-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy patht-04-cert-03-create-02-status.py
More file actions
executable file
·40 lines (35 loc) · 1.02 KB
/
t-04-cert-03-create-02-status.py
File metadata and controls
executable file
·40 lines (35 loc) · 1.02 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
#!/usr/bin/env vpython3
import json
import base64
import datetime
#import rlogger
import requests
import sys
from ksefconfig import Config
from ksefcert import Certificate, serialization
def main():
cfg = Config(int(sys.argv[1]), sys.argv[2]=='o')
with open(f'{cfg.prefix}-auth.json', 'rt') as fp:
auth = json.loads(fp.read())
with open(f'{cfg.prefix}-cert.json', 'rt') as fp:
csr = json.loads(fp.read())
resp = requests.get(
cfg.url+f'/certificates/enrollments/{csr["referenceNumber"]}',
headers={
"Authorization": "Bearer "+auth['accessToken']['token'],
},
timeout=5
)
print('result:', resp)
if resp.status_code != 200:
print(resp.text)
print(resp.headers)
return
data = resp.json()
if data['status']['code'] != 200:
print('xxx',data)
return
csr['certificateSerialNumber'] = data['certificateSerialNumber']
with open(f'{cfg.prefix}-cert.json', 'wt') as fp:
fp.write(json.dumps(csr))
main()