MCPcopy Create free account
hub / github.com/apache/cloudstack / __sign

Method __sign

tools/marvin/marvin/cloudstackConnection.py:132–154  ·  view source on GitHub ↗

@Name : __sign @Desc:signs a given request URL when the apiKey and secretKey are known @Input: payload: dictionary of params be signed @Output: the signature of the payload

(self, payload)

Source from the content-addressed store, hash-verified

130 return self.__lastError
131
132 def __sign(self, payload):
133 """
134 @Name : __sign
135 @Desc:signs a given request URL when the apiKey and
136 secretKey are known
137 @Input: payload: dictionary of params be signed
138 @Output: the signature of the payload
139 """
140 params = list(zip(list(payload.keys()), list(payload.values())))
141 params.sort(key=lambda k: str.lower(k[0]))
142 hash_str = "&".join(
143 ["=".join(
144 [str.lower(r[0]),
145 str.lower(
146 urllib.parse.quote_plus(str(r[1]), safe="*")
147 ).replace("+", "%20")]
148 ) for r in params]
149 )
150 signature = base64.encodebytes(
151 hmac.new(self.securityKey.encode('utf-8'),
152 hash_str.encode('utf-8'),
153 hashlib.sha1).digest()).strip()
154 return signature
155
156 def __sendPostReqToCS(self, url, payload):
157 '''

Callers 1

__sendCmdToCSMethod · 0.95

Calls 7

keysMethod · 0.80
replaceMethod · 0.80
sortMethod · 0.65
encodeMethod · 0.65
valuesMethod · 0.45
joinMethod · 0.45
digestMethod · 0.45

Tested by

no test coverage detected