Skip to content

Commit

Permalink
Add OT support emails secret for OT creation (#4287)
Browse files Browse the repository at this point in the history
* Implement retry logic for OT creation

* remove sorting of contact list

* Separate CreateTrial and SetupTrial requests

* Add OT support emails secret for OT creation
  • Loading branch information
DanielRyanSmith authored Sep 12, 2024
1 parent fc488c9 commit 419c936
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
10 changes: 8 additions & 2 deletions framework/origin_trials_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ def create_origin_trial(ot_stage: Stage) -> tuple[str|None, str|None]:
key = secrets.get_ot_api_key()
if key is None:
return None, 'No API key found for origin trials API'
ot_support_emails = secrets.get_ot_support_emails()
if ot_support_emails is None:
return None, 'OT support emails not found'

# Get a list of all OT @google.com contacts (ot_owner_email must be a google
# contact).
Expand All @@ -263,8 +266,11 @@ def create_origin_trial(ot_stage: Stage) -> tuple[str|None, str|None]:
return None, error_text

error_text = _send_set_up_trial_request(
# TODO(DanielRyanSmith): Add owners contacts in subsequent PR.
origin_trial_id, [], unique_contacts, key, access_token)
origin_trial_id,
ot_support_emails.split(','),
unique_contacts,
key,
access_token)

return str(origin_trial_id), error_text

Expand Down
17 changes: 17 additions & 0 deletions framework/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,20 @@ def get_ot_api_key() -> str|None:
settings.OT_API_KEY = response.payload.data.decode("UTF-8")
return settings.OT_API_KEY
return None


def get_ot_support_emails() -> str|None:
"""Obtain a comma-separated list of the OT support members."""
if settings.DEV_MODE or settings.UNIT_TEST_MODE:
# In dev or unit test mode, return a dummy value.
return settings.DEV_MODE_OT_SUPPORT_EMAILS

# If in staging or prod, pull the value from the project secrets.
from google.cloud.secretmanager import SecretManagerServiceClient
client = SecretManagerServiceClient()
name = (f'{client.secret_path(settings.APP_ID, "OT_SUPPORT_EMAILS")}'
'/versions/latest')
response = client.access_secret_version(request={'name': name})
if response:
return response.payload.data.decode("UTF-8")
return None
2 changes: 2 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def get_flask_template_path() -> str:
OT_URL = 'https://origintrials-staging.corp.google.com/origintrials/'
OT_API_URL = 'https://staging-chromeorigintrials-pa.sandbox.googleapis.com'
OT_API_KEY: str|None = None # Value is set later when request is needed.
# Dummy data for local OT support emails.
DEV_MODE_OT_SUPPORT_EMAILS = '[email protected],[email protected]'

if UNIT_TEST_MODE:
APP_TITLE = 'Local testing'
Expand Down

0 comments on commit 419c936

Please sign in to comment.