From 73623c0029328dfadaf094cb1e520853f36d6a38 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 19 Aug 2019 12:52:47 -0700 Subject: [PATCH] Bug fixes for GCP modules (#60723) --- .../cloud/google/gcp_iam_service_account_info.py | 10 ++-------- .../modules/cloud/google/gcp_mlengine_model_info.py | 10 ++-------- .../modules/cloud/google/gcp_mlengine_version_info.py | 10 ++-------- .../cloud/google/gcp_pubsub_subscription_info.py | 10 ++-------- .../modules/cloud/google/gcp_pubsub_topic_info.py | 10 ++-------- .../modules/cloud/google/gcp_redis_instance_info.py | 10 ++-------- .../cloud/google/gcp_resourcemanager_project_info.py | 10 ++-------- .../cloud/google/gcp_sourcerepo_repository_info.py | 10 ++-------- .../modules/cloud/google/gcp_spanner_database_info.py | 10 ++-------- .../modules/cloud/google/gcp_spanner_instance_info.py | 10 ++-------- .../modules/cloud/google/gcp_sql_database_info.py | 10 ++-------- 11 files changed, 22 insertions(+), 88 deletions(-) diff --git a/lib/ansible/modules/cloud/google/gcp_iam_service_account_info.py b/lib/ansible/modules/cloud/google/gcp_iam_service_account_info.py index 2f22bde5449..f3f56495a6c 100644 --- a/lib/ansible/modules/cloud/google/gcp_iam_service_account_info.py +++ b/lib/ansible/modules/cloud/google/gcp_iam_service_account_info.py @@ -111,12 +111,7 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/iam'] - items = fetch_list(module, collection(module)) - if items.get('accounts'): - items = items.get('accounts') - else: - items = [] - return_value = {'resources': items} + return_value = {'resources': fetch_list(module, collection(module))} module.exit_json(**return_value) @@ -126,8 +121,7 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'iam') - response = auth.get(link) - return return_if_object(module, response) + return auth.list(link, return_if_object, array_name='accounts') def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_mlengine_model_info.py b/lib/ansible/modules/cloud/google/gcp_mlengine_model_info.py index 4605c08057f..0dfdcf24865 100644 --- a/lib/ansible/modules/cloud/google/gcp_mlengine_model_info.py +++ b/lib/ansible/modules/cloud/google/gcp_mlengine_model_info.py @@ -120,12 +120,7 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - items = fetch_list(module, collection(module)) - if items.get('models'): - items = items.get('models') - else: - items = [] - return_value = {'resources': items} + return_value = {'resources': fetch_list(module, collection(module))} module.exit_json(**return_value) @@ -135,8 +130,7 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'mlengine') - response = auth.get(link) - return return_if_object(module, response) + return auth.list(link, return_if_object, array_name='models') def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_mlengine_version_info.py b/lib/ansible/modules/cloud/google/gcp_mlengine_version_info.py index de02cb2508d..86eb8780867 100644 --- a/lib/ansible/modules/cloud/google/gcp_mlengine_version_info.py +++ b/lib/ansible/modules/cloud/google/gcp_mlengine_version_info.py @@ -211,12 +211,7 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - items = fetch_list(module, collection(module)) - if items.get('versions'): - items = items.get('versions') - else: - items = [] - return_value = {'resources': items} + return_value = {'resources': fetch_list(module, collection(module))} module.exit_json(**return_value) @@ -227,8 +222,7 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'mlengine') - response = auth.get(link) - return return_if_object(module, response) + return auth.list(link, return_if_object, array_name='versions') def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_pubsub_subscription_info.py b/lib/ansible/modules/cloud/google/gcp_pubsub_subscription_info.py index a0d4c487851..7748f936991 100644 --- a/lib/ansible/modules/cloud/google/gcp_pubsub_subscription_info.py +++ b/lib/ansible/modules/cloud/google/gcp_pubsub_subscription_info.py @@ -190,12 +190,7 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/pubsub'] - items = fetch_list(module, collection(module)) - if items.get('subscriptions'): - items = items.get('subscriptions') - else: - items = [] - return_value = {'resources': items} + return_value = {'resources': fetch_list(module, collection(module))} module.exit_json(**return_value) @@ -205,8 +200,7 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'pubsub') - response = auth.get(link) - return return_if_object(module, response) + return auth.list(link, return_if_object, array_name='subscriptions') def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_pubsub_topic_info.py b/lib/ansible/modules/cloud/google/gcp_pubsub_topic_info.py index 66923471de3..648070db953 100644 --- a/lib/ansible/modules/cloud/google/gcp_pubsub_topic_info.py +++ b/lib/ansible/modules/cloud/google/gcp_pubsub_topic_info.py @@ -117,12 +117,7 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/pubsub'] - items = fetch_list(module, collection(module)) - if items.get('topics'): - items = items.get('topics') - else: - items = [] - return_value = {'resources': items} + return_value = {'resources': fetch_list(module, collection(module))} module.exit_json(**return_value) @@ -132,8 +127,7 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'pubsub') - response = auth.get(link) - return return_if_object(module, response) + return auth.list(link, return_if_object, array_name='topics') def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_redis_instance_info.py b/lib/ansible/modules/cloud/google/gcp_redis_instance_info.py index 213b0c71167..72fdca38f32 100644 --- a/lib/ansible/modules/cloud/google/gcp_redis_instance_info.py +++ b/lib/ansible/modules/cloud/google/gcp_redis_instance_info.py @@ -188,12 +188,7 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - items = fetch_list(module, collection(module)) - if items.get('instances'): - items = items.get('instances') - else: - items = [] - return_value = {'resources': items} + return_value = {'resources': fetch_list(module, collection(module))} module.exit_json(**return_value) @@ -203,8 +198,7 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'redis') - response = auth.get(link) - return return_if_object(module, response) + return auth.list(link, return_if_object, array_name='instances') def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_resourcemanager_project_info.py b/lib/ansible/modules/cloud/google/gcp_resourcemanager_project_info.py index 1f5fd17d751..64cf786b961 100644 --- a/lib/ansible/modules/cloud/google/gcp_resourcemanager_project_info.py +++ b/lib/ansible/modules/cloud/google/gcp_resourcemanager_project_info.py @@ -138,12 +138,7 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - items = fetch_list(module, collection(module)) - if items.get('projects'): - items = items.get('projects') - else: - items = [] - return_value = {'resources': items} + return_value = {'resources': fetch_list(module, collection(module))} module.exit_json(**return_value) @@ -153,8 +148,7 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'resourcemanager') - response = auth.get(link) - return return_if_object(module, response) + return auth.list(link, return_if_object, array_name='projects') def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_sourcerepo_repository_info.py b/lib/ansible/modules/cloud/google/gcp_sourcerepo_repository_info.py index baecdd483f2..2e9cef2531c 100644 --- a/lib/ansible/modules/cloud/google/gcp_sourcerepo_repository_info.py +++ b/lib/ansible/modules/cloud/google/gcp_sourcerepo_repository_info.py @@ -98,12 +98,7 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - items = fetch_list(module, collection(module)) - if items.get('repos'): - items = items.get('repos') - else: - items = [] - return_value = {'resources': items} + return_value = {'resources': fetch_list(module, collection(module))} module.exit_json(**return_value) @@ -113,8 +108,7 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'sourcerepo') - response = auth.get(link) - return return_if_object(module, response) + return auth.list(link, return_if_object, array_name='repos') def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_spanner_database_info.py b/lib/ansible/modules/cloud/google/gcp_spanner_database_info.py index 24c6d322e0a..8f35a88b8f3 100644 --- a/lib/ansible/modules/cloud/google/gcp_spanner_database_info.py +++ b/lib/ansible/modules/cloud/google/gcp_spanner_database_info.py @@ -111,12 +111,7 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/spanner.admin'] - items = fetch_list(module, collection(module)) - if items.get('databases'): - items = items.get('databases') - else: - items = [] - return_value = {'resources': items} + return_value = {'resources': fetch_list(module, collection(module))} module.exit_json(**return_value) @@ -127,8 +122,7 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'spanner') - response = auth.get(link) - return return_if_object(module, response) + return auth.list(link, return_if_object, array_name='databases') def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_spanner_instance_info.py b/lib/ansible/modules/cloud/google/gcp_spanner_instance_info.py index 375ea6d20e0..5f286b85ff5 100644 --- a/lib/ansible/modules/cloud/google/gcp_spanner_instance_info.py +++ b/lib/ansible/modules/cloud/google/gcp_spanner_instance_info.py @@ -114,12 +114,7 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/spanner.admin'] - items = fetch_list(module, collection(module)) - if items.get('instances'): - items = items.get('instances') - else: - items = [] - return_value = {'resources': items} + return_value = {'resources': fetch_list(module, collection(module))} module.exit_json(**return_value) @@ -129,8 +124,7 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'spanner') - response = auth.get(link) - return return_if_object(module, response) + return auth.list(link, return_if_object, array_name='instances') def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_sql_database_info.py b/lib/ansible/modules/cloud/google/gcp_sql_database_info.py index 6d1b34654bb..c60f1e31363 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_database_info.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_database_info.py @@ -108,12 +108,7 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/sqlservice.admin'] - items = fetch_list(module, collection(module)) - if items.get('items'): - items = items.get('items') - else: - items = [] - return_value = {'resources': items} + return_value = {'resources': fetch_list(module, collection(module))} module.exit_json(**return_value) @@ -123,8 +118,7 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'sql') - response = auth.get(link) - return return_if_object(module, response) + return auth.list(link, return_if_object, array_name='items') def return_if_object(module, response):