From 2023c9dc35e9fcb509ba90d4b111a60d6ca56bad Mon Sep 17 00:00:00 2001 From: Emilien GUILMINEAU Date: Fri, 29 Mar 2024 23:47:30 +0100 Subject: [PATCH] :technologist: Use HATEHOAS style --- snappass/main.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/snappass/main.py b/snappass/main.py index beed48c..ab52f0c 100644 --- a/snappass/main.py +++ b/snappass/main.py @@ -248,7 +248,7 @@ def api_handle_password(): else: abort(500) -@app.route('/api/v2/passwords/', methods=['POST']) +@app.route('/api/v2/passwords', methods=['POST']) def api_v2_set_password(): password = request.json.get('password') ttl = int(request.json.get('ttl', DEFAULT_API_TTL)) @@ -272,9 +272,18 @@ def api_v2_set_password(): return as_validation_problem(request, "set-password-validation-error", "The password and/or the TTL are invalid.", invalid_params) token = set_password(password, ttl) + url_token= quote_plus(token) base_url = set_base_url(request) - link = urljoin(base_url, request.path + quote_plus(token)) - return jsonify(link=link, ttl=ttl) + link = urljoin(base_url, request.path + "/" + url_token) + response_content = { + "token": url_token, + "links": [{ + "rel": "self", + "href": link + }], + "ttl": ttl + } + return jsonify(response_content) @app.route('/api/v2/passwords/', methods=['HEAD']) def api_v2_check_password(token):