ClickHouse/tests/ci/get_robot_token.py

21 lines
792 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:
2021-10-20 11:52:03 +00:00
client = boto3.client('ssm', region_name='us-east-1')
2021-10-20 11:48:27 +00:00
return client.get_parameter(Name=name, WithDecryption=decrypt)['Parameter']['Value']
def get_best_robot_token(token_prefix_env_name="github_robot_token_", total_tokens=4):
2021-10-20 11:52:03 +00:00
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)
rest, _ = gh.rate_limiting
tokens[token] = rest
return max(tokens.items(), key=lambda x: x[1])[0]