Add OT support emails secret for OT creation (#4287)

* Implement retry logic for OT creation

* remove sorting of contact list

* Separate CreateTrial and SetupTrial requests

* Add OT support emails secret for OT creation
This commit is contained in:
Daniel Smith 2024-09-12 11:44:07 -04:00 коммит произвёл GitHub
Родитель fc488c9104
Коммит 419c9363f6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 27 добавлений и 2 удалений

Просмотреть файл

@ -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).
@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -86,6 +86,8 @@ MAX_LOG_LINE = 200 * 1000
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 = 'user1@gmail.com,user2@gmail.com'
if UNIT_TEST_MODE:
APP_TITLE = 'Local testing'