From cb60f12b6b137a10d051e626f31ccc0f4aaaed0d Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Thu, 13 Jun 2019 10:02:00 -0700 Subject: [PATCH] adding additional environment variables for gcp_compute + gcp modules --- awx/main/models/credential/injectors.py | 14 ++++++++++++++ awx/main/tests/data/inventory/plugins/gce/env.json | 8 ++++++-- .../plugins/gce/files/GCP_SERVICE_ACCOUNT_FILE | 7 +++++++ awx/main/tests/data/inventory/scripts/gce/env.json | 6 +++++- .../scripts/gce/files/GCP_SERVICE_ACCOUNT_FILE | 7 +++++++ 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 awx/main/tests/data/inventory/plugins/gce/files/GCP_SERVICE_ACCOUNT_FILE create mode 100644 awx/main/tests/data/inventory/scripts/gce/files/GCP_SERVICE_ACCOUNT_FILE diff --git a/awx/main/models/credential/injectors.py b/awx/main/models/credential/injectors.py index ac2ac71192..b8bc5bd20c 100644 --- a/awx/main/models/credential/injectors.py +++ b/awx/main/models/credential/injectors.py @@ -39,6 +39,20 @@ def gce(cred, env, private_data_dir): f.close() os.chmod(path, stat.S_IRUSR | stat.S_IWUSR) env['GCE_CREDENTIALS_FILE_PATH'] = path + + handle, path = tempfile.mkstemp(dir=private_data_dir) + f = os.fdopen(handle, 'w') + json.dump(json_cred, f, indent=2) + f.close() + os.chmod(path, stat.S_IRUSR | stat.S_IWUSR) + env['GCP_SERVICE_ACCOUNT_FILE'] = path + + # Handle env variables for new module types. + # This includes gcp_compute inventory plugin and + # all new gcp_* modules. + env['GCP_AUTH_KIND'] = 'serviceaccount' + env['GCP_PROJECT'] = project + env['GCP_ENV_TYPE'] = 'tower' return path diff --git a/awx/main/tests/data/inventory/plugins/gce/env.json b/awx/main/tests/data/inventory/plugins/gce/env.json index 91d08e70ee..c36b22fc45 100644 --- a/awx/main/tests/data/inventory/plugins/gce/env.json +++ b/awx/main/tests/data/inventory/plugins/gce/env.json @@ -1,4 +1,8 @@ { "ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS": "never", - "GCE_CREDENTIALS_FILE_PATH": "{{ file_reference }}" -} \ No newline at end of file + "GCE_CREDENTIALS_FILE_PATH": "{{ file_reference }}", + "GCP_AUTH_KIND": "serviceaccount", + "GCP_PROJECT": "fooo", + "GCP_ENV_TYPE": "tower", + "GCP_SERVICE_ACCOUNT_FILE": "{{ file_reference }}" +} diff --git a/awx/main/tests/data/inventory/plugins/gce/files/GCP_SERVICE_ACCOUNT_FILE b/awx/main/tests/data/inventory/plugins/gce/files/GCP_SERVICE_ACCOUNT_FILE new file mode 100644 index 0000000000..ed4c40def1 --- /dev/null +++ b/awx/main/tests/data/inventory/plugins/gce/files/GCP_SERVICE_ACCOUNT_FILE @@ -0,0 +1,7 @@ +{ + "type": "service_account", + "private_key": "{{private_key}}", + "client_email": "fooo", + "project_id": "fooo", + "token_uri": "https://oauth2.googleapis.com/token" +} \ No newline at end of file diff --git a/awx/main/tests/data/inventory/scripts/gce/env.json b/awx/main/tests/data/inventory/scripts/gce/env.json index 5d7cc259b2..def06ac46c 100644 --- a/awx/main/tests/data/inventory/scripts/gce/env.json +++ b/awx/main/tests/data/inventory/scripts/gce/env.json @@ -1,8 +1,12 @@ { "GCE_EMAIL": "fooo", "GCE_PROJECT": "fooo", + "GCP_PROJECT": "fooo", + "GCP_ENV_TYPE": "tower", + "GCP_AUTH_KIND": "serviceaccount", "GCE_CREDENTIALS_FILE_PATH": "{{ file_reference }}", + "GCP_SERVICE_ACCOUNT_FILE": "{{ file_reference }}", "GCE_ZONE": "us-east4-a,us-west1-b", "GCE_INI_PATH": "{{ file_reference }}", "ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS": "never" -} \ No newline at end of file +} diff --git a/awx/main/tests/data/inventory/scripts/gce/files/GCP_SERVICE_ACCOUNT_FILE b/awx/main/tests/data/inventory/scripts/gce/files/GCP_SERVICE_ACCOUNT_FILE new file mode 100644 index 0000000000..ed4c40def1 --- /dev/null +++ b/awx/main/tests/data/inventory/scripts/gce/files/GCP_SERVICE_ACCOUNT_FILE @@ -0,0 +1,7 @@ +{ + "type": "service_account", + "private_key": "{{private_key}}", + "client_email": "fooo", + "project_id": "fooo", + "token_uri": "https://oauth2.googleapis.com/token" +} \ No newline at end of file