This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.py
executable file
·80 lines (66 loc) · 2.21 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
"""
Client for interacting with the release monitor's API gateway trigger
"""
# pylint: disable=line-too-long
import os
from typing import Dict
from argparse import ArgumentParser
from urllib.parse import urlencode
import requests
from aws_requests_auth.boto_utils import BotoAWSRequestsAuth
def main():
"""Do the thing"""
config = get_args_config()
account = config["account"]
commit = config["commit"]
repository = config["repository"]
method = config["method"]
rest_api_id = config["rest_api_id"]
uri = "/default/release_monitor"
querystring = {
"account": account, # pylint: disable=undefined-variable
"commit": commit, # pylint: disable=undefined-variable
"repository": repository, # pylint: disable=undefined-variable
}
querystring_encoded = urlencode(sorted(querystring.items()))
region = "us-east-1"
host = rest_api_id + ".execute-api." + region + ".amazonaws.com"
url = "https://" + host + uri + "?" + querystring_encoded
service = "execute-api"
# Uses boto logic for auth
auth = BotoAWSRequestsAuth(
aws_host=rest_api_id + ".execute-api." + region + ".amazonaws.com",
aws_region=region,
aws_service=service,
)
response = getattr(requests, method.lower())(url, auth=auth)
print(f"{response.content}")
def get_args_config() -> Dict:
"""
Get the configs passed as arguments
"""
parser = create_arg_parser()
config = vars(parser.parse_args())
return config
def create_arg_parser() -> ArgumentParser:
"""Parse the arguments"""
parser = ArgumentParser()
parser.add_argument(
"--account", type=str, required=True, help="github account",
)
parser.add_argument(
"--repository", type=str, required=True, help="github repository",
)
parser.add_argument(
"--commit", type=str, required=True, help="commitish to monitor for",
)
parser.add_argument(
"--rest-api-id", type=str, required=True, help="The AWS API Gateway REST API ID"
)
parser.add_argument(
"--method", type=str.upper, default="GET", help="HTTP method to use",
)
return parser
if __name__ == "__main__":
main()