airflow.providers.google.cloud.hooks.kms

This module contains a Google Cloud KMS hook

Module Contents

Classes

CloudKMSHook

Hook for Google Cloud Key Management service.

class airflow.providers.google.cloud.hooks.kms.CloudKMSHook(gcp_conn_id='google_cloud_default', delegate_to=None, impersonation_chain=None)[source]

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

Hook for Google Cloud Key Management service.

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

  • delegate_to (Optional[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 (Optional[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.

get_conn(self)[source]

Retrieves connection to Cloud Key Management service.

Returns

Cloud Key Management service object

Return type

google.cloud.kms_v1.KeyManagementServiceClient

encrypt(self, key_name, plaintext, authenticated_data=None, retry=DEFAULT, timeout=None, metadata=())[source]

Encrypts a plaintext message using Google Cloud KMS.

Parameters
  • key_name (str) -- The Resource Name for the key (or key version) to be used for encryption. Of the form projects/*/locations/*/keyRings/*/cryptoKeys/**

  • plaintext (bytes) -- The message to be encrypted.

  • authenticated_data (Optional[bytes]) -- Optional additional authenticated data that must also be provided to decrypt the message.

  • retry (Union[google.api_core.retry.Retry, google.api_core.gapic_v1.method._MethodDefault]) -- A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (Optional[float]) -- The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Sequence[Tuple[str, str]]) -- Additional metadata that is provided to the method.

Returns

The base 64 encoded ciphertext of the original message.

Return type

str

decrypt(self, key_name, ciphertext, authenticated_data=None, retry=DEFAULT, timeout=None, metadata=())[source]

Decrypts a ciphertext message using Google Cloud KMS.

Parameters
  • key_name (str) -- The Resource Name for the key to be used for decryption. Of the form projects/*/locations/*/keyRings/*/cryptoKeys/**

  • ciphertext (str) -- The message to be decrypted.

  • authenticated_data (Optional[bytes]) -- Any additional authenticated data that was provided when encrypting the message.

  • retry (Union[google.api_core.retry.Retry, google.api_core.gapic_v1.method._MethodDefault]) -- A retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (Optional[float]) -- The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (Sequence[Tuple[str, str]]) -- Additional metadata that is provided to the method.

Returns

The original message.

Return type

bytes

Was this entry helpful?