From c946e777833d2011fedf6fa37d60285ea6061f08 Mon Sep 17 00:00:00 2001 From: The Magician Date: Wed, 10 Jul 2019 10:59:51 -0700 Subject: [PATCH] adding more specific metrics (#302) Signed-off-by: Modular Magician --- plugins/doc_fragment/gcp.py | 6 ++++++ plugins/module_utils/gcp_utils.py | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/plugins/doc_fragment/gcp.py b/plugins/doc_fragment/gcp.py index 3704997..43c1c4d 100644 --- a/plugins/doc_fragment/gcp.py +++ b/plugins/doc_fragment/gcp.py @@ -36,6 +36,12 @@ options: description: - Array of scopes to be used. type: list + env_type: + description: + - Specifies which Ansible environment you're running this module within. + - This should not be set unless you know what you're doing. + - This only alters the User Agent string for any API requests. + type: str notes: - for authentication, you can set service_account_file using the c(gcp_service_account_file) env variable. diff --git a/plugins/module_utils/gcp_utils.py b/plugins/module_utils/gcp_utils.py index d2f9b01..e4e24e4 100644 --- a/plugins/module_utils/gcp_utils.py +++ b/plugins/module_utils/gcp_utils.py @@ -165,9 +165,14 @@ class GcpSession(object): self.module.fail_json(msg="Credential type '%s' not implemented" % cred_type) def _headers(self): - return { - 'User-Agent': "Google-Ansible-MM-{0}".format(self.product) - } + if self.module.params.get('env_type'): + return { + 'User-Agent': "Google-Ansible-MM-{0}-{1}".format(self.product, self.module.params.get('env_type')) + } + else: + return { + 'User-Agent': "Google-Ansible-MM-{0}".format(self.product) + } def _merge_dictionaries(self, a, b): new = a.copy() @@ -208,7 +213,11 @@ class GcpModule(AnsibleModule): scopes=dict( required=False, fallback=(env_fallback, ['GCP_SCOPES']), - type='list') + type='list'), + env_type=dict( + required=False, + fallback=(env_fallback, ['GCP_ENV_TYPE']), + type='str') ) )