mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-04-09 04:10:27 -07:00
updated plugsins based on feedback, fixed linting and documentation errors.
This commit is contained in:
parent
375b317692
commit
3ce29db3ee
1 changed files with 17 additions and 26 deletions
|
@ -116,11 +116,9 @@ RETURN = '''
|
||||||
# Imports
|
# Imports
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
|
|
||||||
from ansible.plugins.lookup import LookupBase
|
from ansible.plugins.lookup import LookupBase
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.utils.display import Display
|
from ansible.utils.display import Display
|
||||||
|
@ -139,12 +137,11 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_GOOGLE_CLOUD_COLLECTION = False
|
HAS_GOOGLE_CLOUD_COLLECTION = False
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
|
||||||
from ansible.utils.display import Display
|
|
||||||
|
|
||||||
class GcpLookupException(Exception):
|
class GcpLookupException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class GcpMockModule(object):
|
class GcpMockModule(object):
|
||||||
def __init__(self, params):
|
def __init__(self, params):
|
||||||
self.params = params
|
self.params = params
|
||||||
|
@ -158,12 +155,15 @@ class GcpMockModule(object):
|
||||||
except getattr(requests.exceptions, "RequestException"):
|
except getattr(requests.exceptions, "RequestException"):
|
||||||
self.fail_json(msg="GCP returned error: %s" % response.json())
|
self.fail_json(msg="GCP returned error: %s" % response.json())
|
||||||
|
|
||||||
|
|
||||||
class LookupModule(LookupBase):
|
class LookupModule(LookupBase):
|
||||||
def run(self, terms=None, variables=None, **kwargs):
|
def run(self, terms=None, variables=None, **kwargs):
|
||||||
self._display = Display()
|
self._display = Display()
|
||||||
if not HAS_GOOGLE_CLOUD_COLLECTION:
|
if not HAS_GOOGLE_CLOUD_COLLECTION:
|
||||||
raise AnsibleError(
|
raise AnsibleError(
|
||||||
"gcp_secret lookup needs a supported version of the google.cloud collection installed. Use `ansible-galaxy collection install google.cloud` to install it"
|
"""gcp_secret lookup needs a supported version of the google.cloud
|
||||||
|
collection installed. Use `ansible-galaxy collection install google.cloud`
|
||||||
|
to install it"""
|
||||||
)
|
)
|
||||||
self.set_options(var_options=variables, direct=kwargs)
|
self.set_options(var_options=variables, direct=kwargs)
|
||||||
params = {
|
params = {
|
||||||
|
@ -194,7 +194,6 @@ class LookupModule(LookupBase):
|
||||||
self.set_option(arg, os.environ[env_name])
|
self.set_option(arg, os.environ[env_name])
|
||||||
return self.get_option(arg)
|
return self.get_option(arg)
|
||||||
|
|
||||||
|
|
||||||
# set version to the latest version because
|
# set version to the latest version because
|
||||||
# we can't be sure that "latest" is always going
|
# we can't be sure that "latest" is always going
|
||||||
# to be set if secret versions get disabled
|
# to be set if secret versions get disabled
|
||||||
|
@ -213,7 +212,6 @@ class LookupModule(LookupBase):
|
||||||
else:
|
else:
|
||||||
self.raise_error(module, f"Unable to list secret versions via {response.request.url}: {response.json()}")
|
self.raise_error(module, f"Unable to list secret versions via {response.request.url}: {response.json()}")
|
||||||
|
|
||||||
|
|
||||||
def raise_error(self, module, msg):
|
def raise_error(self, module, msg):
|
||||||
if module.params['on_error'] == 'strict':
|
if module.params['on_error'] == 'strict':
|
||||||
raise GcpLookupException(msg)
|
raise GcpLookupException(msg)
|
||||||
|
@ -243,10 +241,3 @@ class LookupModule(LookupBase):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
return response.json()['payload']['data']
|
return response.json()['payload']['data']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue