Skip to content

Commit

Permalink
Metamist ETL integration example. (#694)
Browse files Browse the repository at this point in the history
* Metamist ETL integration example.

* Added audience_list to metamist ETL driver.

* Updating etl_caller_example.py.

* Added metamist-etl-custom-audience-list to read from config.

* Change as per PR review.
  • Loading branch information
milo-hyben authored Mar 4, 2024
1 parent bd3447a commit de9b19e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
20 changes: 19 additions & 1 deletion metamist_infrastructure/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,10 @@ def _setup_etl_pubsub(self):
@cached_property
def etl_extract_function(self):
"""etl_extract_function"""
return self._etl_function('extract', self.etl_extract_service_account)
return self._etl_function(
'extract',
self.etl_extract_service_account,
)

@cached_property
def etl_load_function(self):
Expand Down Expand Up @@ -646,6 +649,16 @@ def _etl_function(
opts=pulumi.ResourceOptions(replace_on_changes=['*']),
)

# prepare custom audience_list
custom_audience_list = None
if (
self.config.metamist.etl.custom_audience_list
and self.config.metamist.etl.custom_audience_list.get(f_name)
):
custom_audience_list = json.dumps(
self.config.metamist.etl.custom_audience_list.get(f_name)
)

fxn = gcp.cloudfunctionsv2.Function(
f'metamist-etl-{f_name}',
name=f'metamist-etl-{f_name}',
Expand Down Expand Up @@ -694,6 +707,11 @@ def _etl_function(
'SM_ENVIRONMENT': self.config.metamist.etl.environment,
'CONFIGURATION_SECRET': self.etl_configuration_secret_version.id,
}, # type: ignore
annotations=(
{'run.googleapis.com/custom-audiences': custom_audience_list}
if custom_audience_list
else None
),
ingress_settings='ALLOW_ALL',
all_traffic_on_latest_revision=True,
service_account_email=sa.email,
Expand Down
9 changes: 8 additions & 1 deletion scripts/etl_caller_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
pip install requests google-auth requests urllib3
"""

import os

import google.auth.transport.requests
Expand All @@ -14,7 +15,7 @@
from requests.adapters import HTTPAdapter
from urllib3 import Retry

URL = 'https://metamist-etl-mnrpw3mdza-ts.a.run.app'
URL = 'https://metamist-extract.popgen.rocks'
TYPE = 'NAME_OF_EXTERNAL_PARTY/v1'


Expand Down Expand Up @@ -60,4 +61,10 @@ def make_request(body: dict | list):


if __name__ == '__main__':
# simple payload which would be sent to the server
print(make_request({'test-value': 'test'}))

# This will raise a 400 with an error message 'Potentially detected PII, the following keys were found in the body'
# it won't update anything in the database
payload = {'first_name': 'This is a test to demonstrate PII detection'}
make_request(payload)

0 comments on commit de9b19e

Please sign in to comment.