|
8 | 8 | import ast |
9 | 9 | import os |
10 | 10 | import json |
11 | | -import re |
12 | 11 |
|
13 | 12 | try: |
14 | 13 | import requests |
|
25 | 24 | except ImportError: |
26 | 25 | HAS_GOOGLE_LIBRARIES = False |
27 | 26 |
|
28 | | -from ansible.errors import AnsibleError |
29 | 27 | from ansible.module_utils.basic import AnsibleModule, env_fallback |
30 | 28 | from ansible.module_utils.six import string_types |
31 | 29 | from ansible.module_utils._text import to_text, to_native |
@@ -449,57 +447,3 @@ def _convert_value(self, value): |
449 | 447 | new_dict[key] = self._convert_value(value[key]) |
450 | 448 | return new_dict |
451 | 449 | return to_text(value) |
452 | | - |
453 | | - |
454 | | -# Handles all authentication and options for GCP Secrets Manager API calls in Lookup plugins. |
455 | | -class GcpSecretLookup(): |
456 | | - def __init__(self): |
457 | | - if not HAS_GOOGLE_LIBRARIES: |
458 | | - raise AnsibleError("Please install the google-auth library") |
459 | | - |
460 | | - self.plugin_name = '' |
461 | | - self.secret_id = None |
462 | | - self.version_id = None |
463 | | - self.project_id = None |
464 | | - self.service_account_file = None |
465 | | - self.scope = ["https://www.googleapis.com/auth/cloud-platform"] |
466 | | - |
467 | | - def set_plugin_name(self, name): |
468 | | - self.plugin_name = name |
469 | | - |
470 | | - def client(self, secretmanager): |
471 | | - if self.service_account_file is not None: |
472 | | - path = os.path.realpath(os.path.expanduser(self.service_account_file)) |
473 | | - credentials = service_account.Credentials.from_service_account_file(path).with_scopes(self.scope) |
474 | | - return secretmanager.SecretManagerServiceClient(credentials=credentials) |
475 | | - |
476 | | - return secretmanager.SecretManagerServiceClient() |
477 | | - |
478 | | - def process_options(self, terms, variables=None, **kwargs): |
479 | | - self.secret_id = kwargs.get('secret') |
480 | | - self.version_id = kwargs.get('version', 'latest') |
481 | | - self.project_id = kwargs.get('project', os.getenv('GCP_PROJECT')) |
482 | | - self.service_account_file = kwargs.get('service_account_file', os.getenv('GCP_SERVICE_ACCOUNT_FILE')) |
483 | | - |
484 | | - if len(terms) > 1: |
485 | | - raise AnsibleError("{0} lookup plugin can have only one secret name or resource id".format(self.plugin_name)) |
486 | | - |
487 | | - if self.secret_id is None and len(terms) == 1: |
488 | | - self.secret_id = terms[0] |
489 | | - |
490 | | - regex = r'^projects/([^/]+)/secrets/([^/]+)/versions/(.+)$' |
491 | | - match = re.match(regex, self.secret_id) |
492 | | - if match: |
493 | | - self.name = self.secret_id |
494 | | - self.project_id = match.group(1) |
495 | | - self.secret_id = match.group(2) |
496 | | - self.version_id = match.group(3) |
497 | | - return |
498 | | - |
499 | | - if self.project_id is None: |
500 | | - raise AnsibleError("{0} lookup plugin required option: project or resource id".format(self.plugin_name)) |
501 | | - |
502 | | - if self.secret_id is None: |
503 | | - raise AnsibleError("{0} lookup plugin required option: secret or resource id".format(self.plugin_name)) |
504 | | - |
505 | | - self.name = f"projects/{self.project_id}/secrets/{self.secret_id}/versions/{self.version_id}" |
0 commit comments