Skip to content

Commit

Permalink
Fix URL encoding for pcluster API client example
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
lukeseawalker committed Mar 25, 2024
1 parent 0644632 commit 2c693cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/client/resources/sigv4_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
import boto3
import botocore
import json
import urllib.parse


def sigv4_auth(method, host, path, queries, body, headers):
"Adds authorization headers for sigv4 to headers parameter."
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()
Expand Down
3 changes: 2 additions & 1 deletion api/client/src/pcluster_client/sigv4_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
import boto3
import botocore
import json
import urllib.parse


def sigv4_auth(method, host, path, queries, body, headers):
"Adds authorization headers for sigv4 to headers parameter."
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()
Expand Down

0 comments on commit 2c693cd

Please sign in to comment.