-
Notifications
You must be signed in to change notification settings - Fork 98
PYTHON-3367 Add support for GCP attached service accounts when using GCP KMS #467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| {'aws': {'secretAccessKey': 'foo'}}]: | ||
| with self.assertRaisesRegex( | ||
| ValueError, "kms_providers\['aws'\] must contain " | ||
| ValueError, r"kms_providers\['aws'\] must contain " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes address warnings seen while running the tests:
test/test_mongocrypt.py:139
/Users/steve.silvester/workspace/libmongocrypt/bindings/python/test/test_mongocrypt.py:139: DeprecationWarning: invalid escape sequence '\('
"instance of bytes or str \(unicode in Python 2\)"):There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted.
| """Get on-demand GCP credentials""" | ||
| metadata_host = "metadata.google.internal" | ||
| if os.getenv("GCE_METADATA_HOST"): | ||
| metadata_host = os.environ["GCE_METADATA_HOST"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest:
metadata_host = os.getenv("GCE_METADATA_HOST") or "metadata.google.internal"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| url = "http://%s/computeMetadata/v1/instance/service-accounts/default/token" % metadata_host | ||
|
|
||
| headers = {"Metadata-Flavor": "Google"} | ||
| response = requests.get(url, headers=headers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need exception handling here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| raise ValueError(msg) | ||
| try: | ||
| data = response.json() | ||
| except Exception : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exception : -> Exception:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
| response = requests.get(url, headers=headers) | ||
| if response.status_code != 200: | ||
| msg = "Unable to retrieve GCP credentials: expected StatusCode 200, got StatusCode: %s. Response body:\n%s" % (response.status_code, response.content) | ||
| raise ValueError(msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ValueError is usually used to indicate an invalid argument was passed whereas here the problem is elsewhere. Perhaps MongoCryptError would be more appropriate here and below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| {'aws': {'secretAccessKey': 'foo'}}]: | ||
| with self.assertRaisesRegex( | ||
| ValueError, "kms_providers\['aws'\] must contain " | ||
| ValueError, r"kms_providers\['aws'\] must contain " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted.
|
|
||
| # The libmongocrypt git revision release to embed in our wheels. | ||
| REVISION=$(git rev-list -n 1 1.5.2) | ||
| REVISION=$(git rev-list -n 1 1.6.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.6.1 is out now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see 1.6.1 had no code changes so 1.6.0 is fine.
Integration tests are in mongodb/mongo-python-driver#1064