use quote_plus for signing CloudStack API requests
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
1fc432bb0f
commit
6fae2e4115
|
@ -2,7 +2,7 @@ from base64 import b64encode
|
|||
import hashlib
|
||||
import hmac
|
||||
from typing import Dict
|
||||
from urllib.parse import quote
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
import requests
|
||||
from zope import component
|
||||
|
@ -26,21 +26,20 @@ class CloudStackService:
|
|||
self._cached_domain_id = None
|
||||
|
||||
def _create_url(self, params: Dict[str, str]) -> str:
|
||||
# See https://docs.cloudstack.apache.org/en/latest/developersguide/dev.html#the-cloudstack-api
|
||||
if 'apiKey' not in params and 'apikey' not in params:
|
||||
params['apiKey'] = self.api_key
|
||||
# See https://docs.cloudstack.apache.org/en/4.16.0.0/developersguide/dev.html#the-cloudstack-api
|
||||
params['apiKey'] = self.api_key
|
||||
params['response'] = 'json'
|
||||
request_str = '&'.join(
|
||||
key + '=' + quote(val)
|
||||
key + '=' + quote_plus(val)
|
||||
for key, val in params.items()
|
||||
)
|
||||
sig_str = '&'.join(
|
||||
key.lower() + '=' + quote(val).lower()
|
||||
key.lower() + '=' + quote_plus(val).lower().replace('+', '%20')
|
||||
for key, val in sorted(params.items())
|
||||
)
|
||||
sig = hmac.new(self.secret_key.encode(), sig_str.encode(), hashlib.sha1).digest()
|
||||
encoded_sig = b64encode(sig).decode()
|
||||
url = self.base_url + '?' + request_str + '&signature=' + quote(encoded_sig)
|
||||
url = self.base_url + '?' + request_str + '&signature=' + quote_plus(encoded_sig)
|
||||
return url
|
||||
|
||||
def _get_domain_id(self) -> str:
|
||||
|
|
Loading…
Reference in New Issue