def fetch_resources(query, resource_type, secrets, configuration): query = __create_resource_graph_query(query, resource_type, configuration) client = init_resource_graph_client(secrets) resources = client.resources(query) results = to_dicts(resources.data, client.api_version) return results
def test_init_rg_client_usgov(cmclient, spcred): client = MagicMock() cmclient.return_value = client cred = MagicMock() spcred.return_value = cred init_resource_graph_client(SECRETS_USGOV) spcred.assert_called_with(client_id=SECRETS_USGOV.get("client_id"), secret=SECRETS_USGOV.get('client_secret'), tenant=SECRETS_USGOV.get('tenant_id'), cloud_environment=__get_cloud_env_by_name( SECRETS_USGOV.get('azure_cloud'))) cmclient.assert_called_with( credentials=ANY, base_url=__get_cloud_env_by_name( SECRETS_USGOV.get("azure_cloud")).endpoints.resource_manager)
def fetch_resources(input_query: str, resource_type: str, secrets: Secrets, configuration: Configuration): # prepare query _query = __query_from(resource_type, input_query) _query_request = __query_request_from(_query, configuration) # prepare resource graph client try: client = init_resource_graph_client(secrets) resources = client.resources(_query_request) except HttpResponseError as e: msg = e.error.code if e.error.details: for d in e.error.details: msg += ": " + str(d) raise InterruptExecution(msg) # prepare results results = __to_dicts(resources.data) return results