Skip to content

Commit

Permalink
feat(storage): migrate to Service Account Credentials API (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurov Ilya committed Jun 23, 2020
1 parent 4d76e38 commit e4990d0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions google/cloud/storage/_signing.py
Expand Up @@ -660,14 +660,14 @@ def _sign_message(message, access_token, service_account_email):
message = _helpers._to_bytes(message)

method = "POST"
url = "https://iam.googleapis.com/v1/projects/-/serviceAccounts/{}:signBlob?alt=json".format(
url = "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/{}:signBlob?alt=json".format(
service_account_email
)
headers = {
"Authorization": "Bearer " + access_token,
"Content-type": "application/json",
}
body = json.dumps({"bytesToSign": base64.b64encode(message).decode("utf-8")})
body = json.dumps({"payload": base64.b64encode(message).decode("utf-8")})

request = requests.Request()
response = request(url=url, method=method, body=body, headers=headers)
Expand All @@ -678,7 +678,7 @@ def _sign_message(message, access_token, service_account_email):
)

data = json.loads(response.data.decode("utf-8"))
return data["signature"]
return data["signedBlob"]


def _url_encode(query_params):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test__signing.py
Expand Up @@ -678,7 +678,7 @@ def _call_fut(*args, **kwargs):

def test_sign_bytes(self):
signature = "DEADBEEF"
data = {"signature": signature}
data = {"signedBlob": signature}
request = make_request(200, data)
with mock.patch("google.auth.transport.requests.Request", return_value=request):
returned_signature = self._call_fut(
Expand Down

0 comments on commit e4990d0

Please sign in to comment.