-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploadService.py
57 lines (46 loc) · 1.38 KB
/
uploadService.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
#!/usr/bin/env python
"""Update a service
Usage:
update_service.py <endpoint> <access_token> <service_id> <filename>
Example:
./update_service.py http://localhost:5000 myToken ~/update.json
"""
from __future__ import print_function
import json
import requests
import getpass
from docopt import docopt
def update(base_url, access_token, filename, service_id):
print(base_url)
print(access_token)
print(filename)
print(service_id)
endpoint = "{}/services/{}".format(base_url, service_id)
with open(filename) as data_file:
json_from_file = json.load(data_file)
data = {
'update_details': {
'updated_by': getpass.getuser()
},
'services': json_from_file
}
print(endpoint)
response = requests.put(
endpoint,
data=json.dumps(data),
headers={
"content-type": "application/json",
"authorization": "Bearer {}".format(access_token),
}
)
print(response.status_code)
print(response.text)
return service_id, response
if __name__ == "__main__":
arguments = docopt(__doc__)
update(
base_url=arguments['<endpoint>'],
access_token=arguments['<access_token>'],
service_id=arguments['<service_id>'],
filename=arguments['<filename>'],
)