2022-02-16 17:35:02 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
import boto3
|
|
|
|
from ray_release.logger import logger
|
2022-06-28 18:14:01 +01:00
|
|
|
from ray_release.util import DeferredEnvVar
|
2022-02-16 17:35:02 +00:00
|
|
|
|
2022-06-28 18:14:01 +01:00
|
|
|
RELEASE_AWS_BUCKET = DeferredEnvVar(
|
|
|
|
"RELEASE_AWS_BUCKET", "ray-release-automation-results"
|
|
|
|
)
|
|
|
|
RELEASE_AWS_DB_NAME = DeferredEnvVar("RELEASE_AWS_DB_NAME", "ray_ci")
|
|
|
|
RELEASE_AWS_DB_TABLE = DeferredEnvVar("RELEASE_AWS_DB_TABLE", "release_test_result")
|
2022-02-16 17:35:02 +00:00
|
|
|
|
2022-06-28 18:14:01 +01:00
|
|
|
RELEASE_AWS_DB_SECRET_ARN = DeferredEnvVar(
|
2022-02-16 17:35:02 +00:00
|
|
|
"RELEASE_AWS_DB_SECRET_ARN",
|
|
|
|
"arn:aws:secretsmanager:us-west-2:029272617770:secret:"
|
|
|
|
"rds-db-credentials/cluster-7RB7EYTTBK2EUC3MMTONYRBJLE/ray_ci-MQN2hh",
|
|
|
|
)
|
2022-06-28 18:14:01 +01:00
|
|
|
RELEASE_AWS_DB_RESOURCE_ARN = DeferredEnvVar(
|
2022-02-16 17:35:02 +00:00
|
|
|
"RELEASE_AWS_DB_RESOURCE_ARN",
|
|
|
|
"arn:aws:rds:us-west-2:029272617770:cluster:ci-reporting",
|
|
|
|
)
|
2022-06-28 18:14:01 +01:00
|
|
|
RELEASE_AWS_ANYSCALE_SECRET_ARN = DeferredEnvVar(
|
2022-02-16 17:35:02 +00:00
|
|
|
"RELEASE_AWS_ANYSCALE_SECRET_ARN",
|
|
|
|
"arn:aws:secretsmanager:us-west-2:029272617770:secret:"
|
|
|
|
"release-automation/"
|
|
|
|
"anyscale-token20210505220406333800000001-BcUuKB",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def maybe_fetch_api_token():
|
2022-06-28 18:14:01 +01:00
|
|
|
from anyscale.authenticate import AuthenticationBlock
|
|
|
|
|
2022-02-16 17:35:02 +00:00
|
|
|
if not os.environ.get("ANYSCALE_CLI_TOKEN"):
|
|
|
|
try:
|
|
|
|
token, _ = AuthenticationBlock._load_credentials()
|
|
|
|
logger.info("Loaded anyscale credentials from local storage.")
|
|
|
|
os.environ["ANYSCALE_CLI_TOKEN"] = token
|
|
|
|
return
|
|
|
|
except Exception:
|
|
|
|
pass # Ignore errors
|
|
|
|
|
|
|
|
logger.info("Missing ANYSCALE_CLI_TOKEN, retrieving from AWS secrets store")
|
|
|
|
# NOTE(simon) This should automatically retrieve
|
|
|
|
# release-automation@anyscale.com's anyscale token
|
2022-06-28 18:14:01 +01:00
|
|
|
cli_token = boto3.client(
|
2022-02-16 17:35:02 +00:00
|
|
|
"secretsmanager", region_name="us-west-2"
|
2022-06-28 18:14:01 +01:00
|
|
|
).get_secret_value(SecretId=str(RELEASE_AWS_ANYSCALE_SECRET_ARN))[
|
|
|
|
"SecretString"
|
|
|
|
]
|
|
|
|
os.environ["ANYSCALE_CLI_TOKEN"] = cli_token
|