Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
claw89 committed Nov 1, 2024
1 parent e43f6e5 commit cc783fe
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,40 +127,3 @@ More information

See Google Cloud Financial Services API documentation to `delete an instance
<https://cloud.google.com/financial-services/anti-money-laundering/docs/reference/rest/v1/projects.locations.instances/delete>`_.



Sensors
^^^^^^^

.. _howto/sensor:FinancialServicesOperationSensor:

Check operation status
----------------------

Use the :class:`~airflow.providers.google.cloud.sensors.financial_services.FinancialServicesOperationSensor`
sensor to check the status of an operation in the Google Cloud Financial Services API.

Using the sensor
""""""""""""""""""

.. exampleinclude:: /../../providers/tests/system/google/cloud/financial_services/example_financial_services.py
:language: python
:dedent: 4
:start-after: [START howto_sensor_financial_services_operation]
:end-before: [END howto_sensor_financial_services_operation]

Templating
""""""""""

.. literalinclude:: /../../providers/src/airflow/providers/google/cloud/sensors/financial_services.py
:language: python
:dedent: 4
:start-after: [START howto_sensor_financial_services_operation_template_fields]
:end-before: [END howto_sensor_financial_services_operation_template_fields]

More information
""""""""""""""""

See Google Cloud Financial Services API documentation to `get an operation
<https://cloud.google.com/financial-services/anti-money-laundering/docs/reference/rest/v1/projects.locations.operations/get>`_.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class FinancialServicesHook(GoogleBaseHook):
"""
Hook for interacting with the Google Financial Services API.
:param discovery_doc: Discovery document for building the Financial Services API
as described `here <https://cloud.google.com/financial-services/anti-money-laundering/docs/reference/rest#discovery-document>`__
:param gcp_conn_id: Identifier of connection to Google Cloud Platform.
Defaults to "google_cloud_default".
"""
Expand All @@ -54,9 +52,19 @@ def __init__(
)

def _get_developer_key(self) -> str | None:
"""
Get a developer key for accessing the Financial Services discovery API.
:return: A developer key for discovery API access.
"""
return Variable.get("financial_services_api_key", default_var=None)

def _get_discovery_doc(self) -> dict | None:
"""
Get the Financial Services discovery document from local storage.
:return: Financial Services discovery document.
"""
discovery_doc_path = Variable.get("financial_services_discovery_doc_path", default_var=None)
if not discovery_doc_path:
discovery_doc = None
Expand Down Expand Up @@ -89,14 +97,21 @@ def get_conn(self) -> Resource:
else:
raise AirflowException(
"Connecting to financialservices.googleapis.com requires either 'financial_services_api_key' or "
"'financial_services_discovery_doc_path' to be set in Airflow variables. Use 'airflow variables set financial_services_api_key <API KEY VALUE>' "
"to set the variable"
"'financial_services_discovery_doc_path' to be set in Airflow variables. Use 'airflow variables "
"set financial_services_api_key <API KEY VALUE>' to set the variable"
)

return self.connection

def wait_for_operation(self, operation: Operation, timeout: float | None = None):
"""Wait for long-lasting operation to complete."""
"""
Wait for the completion of a long-running operation.
:param operation: The long-running operation to wait for completion.
:param timeout: Timeout in seconds to wait for completion.
:return: The result of the operation after completion.
"""
try:
return operation.result(timeout=timeout)
except Exception:
Expand Down Expand Up @@ -195,7 +210,7 @@ def _parse_operation_proto(self, json_response: dict) -> tuple[str, operations_p
:param json_response: Required. Long-running operation data returned from the Financial Services API in JSON format.
:returns: Tuple containing the operation ID and a parsed operations_pb2.Operation.
:returns: The operation ID and a parsed pb2 operation.
"""
# Can not find message descriptor by type_url: type.googleapis.com/google.cloud.financialservices.v1.OperationMetadata
# replace operation metadata protobuf with Empty
Expand All @@ -218,7 +233,7 @@ def _get_operation(self, project_id: str, region: str, operation_id: str) -> ope
:param region: Required. The ID of the Google Cloud region that the service belongs to.
:param operation_id: Required. The ID of the long-running operation.
:returns: The parsed operations_pb2.Operation.
:returns: The parsed pb2 operation.
"""
conn = self.get_conn()
name = f"projects/{project_id}/locations/{region}/operations/{operation_id}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ class FinancialServicesCreateInstanceOperator(GoogleCloudBaseOperator):
:param kms_key_ring_id: Required. The ID of the Google Cloud KMS key ring containing the key to
use for instance encryption
:param kms_key_id: Required. The ID of the Google Cloud KMS key to use for instance encryption
:param discovery_doc: Discovery document for building the Financial Services API
as described `here <https://cloud.google.com/financial-services/anti-money-laundering/docs/reference/rest#discovery-document>`__
:param gcp_conn_id: Identifier of connection to Google Cloud Platform.
Defaults to "google_cloud_default".
:param timeout: The maximum time to wait for a long-running operation to complete.
"""

# [START howto_operator_financial_services_create_instance_template_fields]
Expand Down Expand Up @@ -104,12 +103,13 @@ class FinancialServicesDeleteInstanceOperator(GoogleCloudBaseOperator):
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:FinancialServicesDeleteInstanceOperator`
:param instance_resource_uri: URI of the instance to delete (format:
'projects/<Project ID>/locations/<Location>/instances/<Instance ID>)
:param discovery_doc: Discovery document for building the Financial Services API
as described `here <https://cloud.google.com/financial-services/anti-money-laundering/docs/reference/rest#discovery-document>`__
:param project_id: Required. The ID of the Google Cloud project that the service belongs to.
:param region: Required. The ID of the Google Cloud region that the service belongs to.
:param instance_id: Required. The ID of the instance, which is the final component of the
instances's name.
:param gcp_conn_id: Identifier of connection to Google Cloud Platform.
Defaults to "google_cloud_default".
:param timeout: The maximum time to wait for a long-running operation to complete.
"""

# [START howto_operator_financial_services_get_instance_template_fields]
Expand Down Expand Up @@ -154,10 +154,10 @@ class FinancialServicesGetInstanceOperator(GoogleCloudBaseOperator):
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:FinancialServicesGetInstanceOperator`
:param instance_resource_uri: URI of the instance to get (format:
'projects/<Project ID>/locations/<Location>/instances/<Instance ID>)
:param discovery_doc: Discovery document for building the Financial Services API
as described `here <https://cloud.google.com/financial-services/anti-money-laundering/docs/reference/rest#discovery-document>`__
:param project_id: Required. The ID of the Google Cloud project that the service belongs to.
:param region: Required. The ID of the Google Cloud region that the service belongs to.
:param instance_id: Required. The ID of the instance, which is the final component of the
instances's name.
:param gcp_conn_id: Identifier of connection to Google Cloud Platform.
Defaults to "google_cloud_default".
"""
Expand Down
3 changes: 0 additions & 3 deletions providers/src/airflow/providers/google/provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,6 @@ sensors:
- integration-name: Google Dataproc Metastore
python-modules:
- airflow.providers.google.cloud.sensors.dataproc_metastore
- integration-name: Google Cloud Financial Services
python-modules:
- airflow.providers.google.cloud.sensors.financial_services
- integration-name: Google Cloud Storage (GCS)
python-modules:
- airflow.providers.google.cloud.sensors.gcs
Expand Down

0 comments on commit cc783fe

Please sign in to comment.