-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetBuildInfo.py
More file actions
94 lines (76 loc) · 2.63 KB
/
GetBuildInfo.py
File metadata and controls
94 lines (76 loc) · 2.63 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
import json
import boto3
import requests
import os
from botocore.auth import SigV4Auth
from botocore.awsrequest import AWSRequest
# Start Session
boto_session = boto3.Session()
# Target, Data & ContentType are all defined from the AWS models. See the below URL:
# https://github.com/boto/botocore/blob/develop/botocore/data/codeconnections/2023-12-01/service-2.json
def make_codefactory_request(
boto_credentials,
target,
data,
content_type='application/x-amz-json-1.0',
region="eu-west-2",
host=None,
path=None
):
service = "dipper"
target_prefix = "CoFaTokenService_Agent."
method = "POST"
if host == None:
host = f"codebuild-builds.{region}.amazonaws.com"
if path == None:
path = "/"
url=f'https://{host}{path}'
request = AWSRequest(
method,
url,
headers={
"X-Amz-Target": target_prefix + target,
'Content-Type': content_type
},
data=json.dumps(data)
)
SigV4Auth(boto_credentials, service, region).add_auth(request)
user_agent = "aws-sdk-go/1.55.8 (go1.25.0; linux; amd64) exec-env/AWS_ECS_EC2"
headers = dict(request.headers) #| {"User-Agent": user_agent},
response = requests.request(
method,
url,
headers=headers,
data=json.dumps(data)
)
return {
"request": {
"headers": headers,
"data": data,
},
"response": response
}
def print_codeconnection_request(reqres):
target = reqres["request"]["headers"]["X-Amz-Target"]
data = reqres["request"]["data"]
response = reqres["response"]
print(f'==== Request - {target.split(".")[-1]} ==== ')
print(f"X-Amz-Target: {target}")
print(f"Body: {json.dumps(data)}")
print("==== Response ====")
print(f"Status: {response.status_code}")
print(response.text)
# Confirm users identity to ensure we are using the correct IAM role during tests
main_boto_session = boto3.Session()
caller_identity = main_boto_session.client('sts').get_caller_identity()
boto_credentials = main_boto_session.get_credentials()
print(f'ARN of Role: {caller_identity["Arn"]}')
CODEBUILD_BUILD_ARN = os.getenv('CODEBUILD_BUILD_ARN', "")
AWS_REGION = os.getenv('AWS_REGION', "eu-west-2")
reqres = make_codefactory_request(
boto_credentials,
"GetBuildInfo",
{"buildArn": CODEBUILD_BUILD_ARN},
region=AWS_REGION,
)
print_codeconnection_request(reqres)