airflow.contrib.hooks.gcp_function_hook

Module Contents

airflow.contrib.hooks.gcp_function_hook.TIME_TO_SLEEP_IN_SECONDS = 1[source]
class airflow.contrib.hooks.gcp_function_hook.GcfHook(api_version, gcp_conn_id='google_cloud_default', delegate_to=None)[source]

Bases: airflow.contrib.hooks.gcp_api_base_hook.GoogleCloudBaseHook

Hook for the Google Cloud Functions APIs.

All the methods in the hook where project_id is used must be called with keyword arguments rather than positional.

_conn[source]
static _full_location(project_id, location)[source]

Retrieve full location of the function in the form of projects/<GCP_PROJECT_ID>/locations/<GCP_LOCATION>

Parameters
  • project_id (str) – The Google Cloud Project project_id where the function belongs.

  • location (str) – The location where the function is created.

Returns

get_conn(self)[source]

Retrieves the connection to Cloud Functions.

Returns

Google Cloud Function services object.

Return type

dict

get_function(self, name)[source]

Returns the Cloud Function with the given name.

Parameters

name (str) – Name of the function.

Returns

A Cloud Functions object representing the function.

Return type

dict

create_new_function(self, location, body, project_id=None)[source]

Creates a new function in Cloud Function in the location specified in the body.

Parameters
  • location (str) – The location of the function.

  • body (dict) – The body required by the Cloud Functions insert API.

  • project_id (str) – Optional, Google Cloud Project project_id where the function belongs. If set to None or missing, the default project_id from the GCP connection is used.

Returns

None

update_function(self, name, body, update_mask)[source]

Updates Cloud Functions according to the specified update mask.

Parameters
  • name (str) – The name of the function.

  • body (dict) – The body required by the cloud function patch API.

  • update_mask ([str]) – The update mask - array of fields that should be patched.

Returns

None

upload_function_zip(self, location, zip_path, project_id=None)[source]

Uploads zip file with sources.

Parameters
  • location (str) – The location where the function is created.

  • zip_path (str) – The path of the valid .zip file to upload.

  • project_id (str) – Optional, Google Cloud Project project_id where the function belongs. If set to None or missing, the default project_id from the GCP connection is used.

Returns

The upload URL that was returned by generateUploadUrl method.

delete_function(self, name)[source]

Deletes the specified Cloud Function.

Parameters

name (str) – The name of the function.

Returns

None

_wait_for_operation_to_complete(self, operation_name)[source]

Waits for the named operation to complete - checks status of the asynchronous call.

Parameters

operation_name (str) – The name of the operation.

Returns

The response returned by the operation.

Return type

dict

Exception

AirflowException in case error is returned.

Was this entry helpful?