From 2c693cd02b3c6784197f201c53ad6e1b07b792e4 Mon Sep 17 00:00:00 2001 From: Luca Carrogu Date: Mon, 25 Mar 2024 10:01:09 +0100 Subject: [PATCH] Fix URL encoding for pcluster API client example Fix URL encoding for pcluster API client example, that was causing an error when using additional parameters like next_token. The next_token may contain special chars like "/" that needs to be encoded before passing the request to the API gateway. The new client was generated by running the command `./gradlew generatePythonClient`. Signed-off-by: Luca Carrogu --- api/client/resources/sigv4_auth.py | 3 ++- api/client/src/pcluster_client/sigv4_auth.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/api/client/resources/sigv4_auth.py b/api/client/resources/sigv4_auth.py index b24370610d..7f68614be5 100644 --- a/api/client/resources/sigv4_auth.py +++ b/api/client/resources/sigv4_auth.py @@ -15,6 +15,7 @@ import boto3 import botocore import json +import urllib.parse def sigv4_auth(method, host, path, queries, body, headers): @@ -22,7 +23,7 @@ def sigv4_auth(method, host, path, queries, body, headers): endpoint = host.replace('https://', '').replace('http://', '') _api_id, _service, region, _domain = endpoint.split('.', maxsplit=3) - request_parameters = '&'.join([f"{k}={v}" for k, v in queries]) + request_parameters = urllib.parse.urlencode(queries) url = f"{host}{path}?{request_parameters}" session = botocore.session.Session() diff --git a/api/client/src/pcluster_client/sigv4_auth.py b/api/client/src/pcluster_client/sigv4_auth.py index b24370610d..7f68614be5 100644 --- a/api/client/src/pcluster_client/sigv4_auth.py +++ b/api/client/src/pcluster_client/sigv4_auth.py @@ -15,6 +15,7 @@ import boto3 import botocore import json +import urllib.parse def sigv4_auth(method, host, path, queries, body, headers): @@ -22,7 +23,7 @@ def sigv4_auth(method, host, path, queries, body, headers): endpoint = host.replace('https://', '').replace('http://', '') _api_id, _service, region, _domain = endpoint.split('.', maxsplit=3) - request_parameters = '&'.join([f"{k}={v}" for k, v in queries]) + request_parameters = urllib.parse.urlencode(queries) url = f"{host}{path}?{request_parameters}" session = botocore.session.Session()