feat: CCP secret manager lookup(https://github.com/ansible-collections/google.cloud/pull/357)#628
Conversation
…e on the remote host
feat: merge GCP secret management lookup by "levonet" from "levonet:B2B-98"
|
@toumorokoshi can you pls review and approve if OK |
|
Sorry, I no longer am employed by Google and therefore cannot merge this PR. I guess if @SirGitsalot gives me approval I'm happy to merge some PRs - although I think releases will still have to be maintained by Google. |
|
Hello, Guys |
|
Looks good - there's a few linter nits that shouldn't affect functionality that need to be fixed though: |
| - name: GCP_SERVICE_ACCOUNT_FILE | ||
| notes: | ||
| - When I(secret) is the first option in the term string, C(secret=) is not required (see examples). | ||
| - If you’re running your application elsewhere, you should download a service account JSON keyfile and point to it using the secret option or an environment variable C(GOOGLE_APPLICATION_CREDENTIALS="/path/to/keyfile.json"). |
There was a problem hiding this comment.
| - If you’re running your application elsewhere, you should download a service account JSON keyfile and point to it using the secret option or an environment variable C(GOOGLE_APPLICATION_CREDENTIALS="/path/to/keyfile.json"). | |
| - If you're running your application elsewhere, you should download a service account JSON keyfile and | |
| - point to it using the secret option or an environment variable C(GOOGLE_APPLICATION_CREDENTIALS="/path/to/keyfile.json"). |
| - name: GCP_SERVICE_ACCOUNT_FILE | ||
| notes: | ||
| - When I(secret) is the first option in the term string, C(secret=) is not required (see examples). | ||
| - If you’re running your application elsewhere, you should download a service account JSON keyfile and point to it using the secret option or an environment variable C(GOOGLE_APPLICATION_CREDENTIALS="/path/to/keyfile.json"). |
There was a problem hiding this comment.
| - If you’re running your application elsewhere, you should download a service account JSON keyfile and point to it using the secret option or an environment variable C(GOOGLE_APPLICATION_CREDENTIALS="/path/to/keyfile.json"). | |
| - If you're running your application elsewhere, you should download a service account JSON keyfile and | |
| - point to it using the secret option or an environment variable C(GOOGLE_APPLICATION_CREDENTIALS="/path/to/keyfile.json"). |
| - google-cloud-secret-manager >= 1.0.0 | ||
| description: | ||
| - Retrieve secret contents from GCP Secret Manager. | ||
| - Accessing to secret content requires the Secret Manager Secret Accessor role (C(roles/secretmanager.secretAccessor)) on the secret, project, folder, or organization. |
There was a problem hiding this comment.
| - Accessing to secret content requires the Secret Manager Secret Accessor role (C(roles/secretmanager.secretAccessor)) on the secret, project, folder, or organization. | |
| - Accessing to secret content requires: | |
| - the Secret Manager Secret Accessor role (C(roles/secretmanager.secretAccessor)) on the secret, project, folder, or organization. |
|
|
||
| def client(self, secretmanager): | ||
| if self.access_token is not None: | ||
| credentials=google.oauth2.credentials.Credentials(self.access_token, scopes=self.scope) |
There was a problem hiding this comment.
| credentials=google.oauth2.credentials.Credentials(self.access_token, scopes=self.scope) | |
| credentials = google.oauth2.credentials.Credentials(self.access_token, scopes=self.scope) |
| if self.service_account_file is not None: | ||
| path = os.path.realpath(os.path.expanduser(self.service_account_file)) | ||
| if not os.path.exists(path): | ||
| raise AnsibleError("File {} was not found.".format(path)) |
There was a problem hiding this comment.
| raise AnsibleError("File {} was not found.".format(path)) | |
| raise AnsibleError("File {0} was not found.".format(path)) |
| try: | ||
| info = json.load(file_obj) | ||
| except ValueError as e: | ||
| raise AnsibleError("File {} is not a valid json file.".format(path)) |
There was a problem hiding this comment.
| raise AnsibleError("File {} is not a valid json file.".format(path)) | |
| raise AnsibleError("File {0} is not a valid json file.".format(path)) |
| credentials = identity_pool.Credentials.from_info(info, scopes=self.scope) | ||
| else: | ||
| raise AnsibleError( | ||
| "Type is {}, expected one of authorized_user, service_account, external_account.".format(credential_type) |
There was a problem hiding this comment.
| "Type is {}, expected one of authorized_user, service_account, external_account.".format(credential_type) | |
| "Type is {0}, expected one of authorized_user, service_account, external_account.".format(credential_type) |
| if self.secret_id is None: | ||
| raise AnsibleError("{0} lookup plugin required option: secret or resource id".format(self.plugin_name)) | ||
|
|
||
| self.name = "projects/{}/secrets/{}/versions/{}".format(self.project_id, self.secret_id, self.version_id) |
There was a problem hiding this comment.
| self.name = "projects/{}/secrets/{}/versions/{}".format(self.project_id, self.secret_id, self.version_id) | |
| self.name = "projects/{0}/secrets/{1}/versions/{2}".format(self.project_id, self.secret_id, self.version_id) |
@SirGitsalot I made suggestions to fix all the lint errors, can you please have another look and merge? |
|
@gkorolev or maybe you can merge my above suggestions if that's ok? |
|
is this a dup of #578? |
SUMMARY
GCP secret manager lookup by @levonet
Trying to push enhancement done by @levonet and address minor fixes, requested by @toumorokoshi.
ISSUE TYPE
COMPONENT NAME
GCP secret manager lookup plugin