airflow.providers.google.common.hooks.discovery_api

This module allows you to connect to the Google Discovery API Service and query it.

Module Contents

class airflow.providers.google.common.hooks.discovery_api.GoogleDiscoveryApiHook(api_service_name: str, api_version: str, gcp_conn_id: str = 'google_cloud_default', delegate_to: Optional[str] = None, impersonation_chain: Optional[Union[str, Sequence[str]]] = None)[source]

Bases: airflow.providers.google.common.hooks.base_google.GoogleBaseHook

A hook to use the Google API Discovery Service.

Parameters
  • api_service_name (str) – The name of the api service that is needed to get the data for example ‘youtube’.

  • api_version (str) – The version of the api that will be requested for example ‘v3’.

  • gcp_conn_id (str) – The connection ID to use when fetching connection info.

  • delegate_to (str) – The account to impersonate using domain-wide delegation of authority, if any. For this to work, the service account making the request must have domain-wide delegation enabled.

  • impersonation_chain (Union[str, Sequence[str]]) – Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account.

_conn :Optional[Resource][source]
get_conn(self)[source]

Creates an authenticated api client for the given api service name and credentials.

Returns

the authenticated api service.

Return type

Resource

query(self, endpoint: str, data: dict, paginate: bool = False, num_retries: int = 0)[source]

Creates a dynamic API call to any Google API registered in Google’s API Client Library and queries it.

Parameters
  • endpoint (str) –

    The client libraries path to the api call’s executing method. For example: ‘analyticsreporting.reports.batchGet’

    See also

    https://developers.google.com/apis-explorer for more information on what methods are available.

  • data (dict) – The data (endpoint params) needed for the specific request to given endpoint.

  • paginate (bool) – If set to True, it will collect all pages of data.

  • num_retries (int) – Define the number of retries for the requests being made if it fails.

Returns

the API response from the passed endpoint.

Return type

dict

_call_api_request(self, google_api_conn_client, endpoint, data, paginate, num_retries)[source]
_build_api_request(self, google_api_conn_client, api_sub_functions, api_endpoint_params)[source]
_paginate_api(self, google_api_endpoint_instance, google_api_conn_client, api_endpoint_parts, num_retries)[source]
_build_next_api_request(self, google_api_conn_client, api_sub_functions, api_endpoint_instance, api_response)[source]

Was this entry helpful?