ClickHouse/tests/ci/get_robot_token.py

23 lines
808 B
Python
Raw Normal View History

#!/usr/bin/env python3
import boto3 # type: ignore
from github import Github # type: ignore
2021-10-20 11:48:27 +00:00
def get_parameter_from_ssm(name, decrypt=True, client=None):
if not client:
client = boto3.client("ssm", region_name="us-east-1")
return client.get_parameter(Name=name, WithDecryption=decrypt)["Parameter"]["Value"]
2021-10-20 11:48:27 +00:00
def get_best_robot_token(token_prefix_env_name="github_robot_token_", total_tokens=4):
client = boto3.client("ssm", region_name="us-east-1")
tokens = {}
2021-10-20 11:48:27 +00:00
for i in range(1, total_tokens + 1):
token_name = token_prefix_env_name + str(i)
2021-10-20 11:48:27 +00:00
token = get_parameter_from_ssm(token_name, True, client)
gh = Github(token, per_page=100)
rest, _ = gh.rate_limiting
tokens[token] = rest
return max(tokens.items(), key=lambda x: x[1])[0]