-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
57 lines (44 loc) · 2.09 KB
/
main.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
from aktest_se import Se, SDKConfiguration
from edgegrid import EdgeRc, EdgeGridAuth
import argparse
from pathlib import Path
import httpx
import logging
logger = logging.getLogger(__name__)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--edgerc", metavar='', type=str, help="location of .edgerc file", default="~/.edgerc")
parser.add_argument("--section", metavar='', type=str, help="section of token inside .edgerc file", default='default')
parser.add_argument("-c", "--contract", metavar='', type=str, help="contractId without ctr_ prefix")
parser.add_argument("-a", "--accountkey", metavar='', type=str, help="account switch key")
parser.add_argument("--id", metavar='', type=str, help="enrollment id")
args = parser.parse_args()
if args.edgerc is None:
edgerc = EdgeRc(f'{str(Path.home())}/.edgerc')
else:
edgerc = EdgeRc(f'{str(Path(args.edgerc))}')
section = args.section if args.section else 'default'
auth = EdgeGridAuth.from_edgerc(edgerc, section)
host = edgerc.get(section, 'host')
server_url=f"https://{host}/cps/v2"
sdk_config = SDKConfiguration(server_url, async_client=None, debug_logger=logger)
s = Se(sdk_config, server_url, client=httpx.Client(auth=auth))
res = s.enrollments.get_enrollments(contract_id=args.contract, account_switch_key=args.accountkey, server_url=server_url)
for r in res.enrollments:
try:
print(r.csr.sans)
except AttributeError as e:
print(e)
res = s.enrollments.get_enrollment(enrollment_id=args.id, account_switch_key=args.accountkey)
print()
print(res.csr)
'''
client = httpx.Client(auth=auth)
resp = client.get("https://akab-y2lbugj6ikgeep6u-o4o6mtx2qbo4wror.luna.akamaiapis.net/cps/v2/enrollments",
headers={'accept': "application/vnd.akamai.cps.enrollments.v11+json"},
params={"contractId": "W-QZ88G8",
"accountSwitchKey": "F-AC-5015077"
})
print()
print(resp.status_code)
'''