-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathecho-auth.py
80 lines (59 loc) · 2.11 KB
/
echo-auth.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
# echo-auth.py
"""Script for adding an authorization rule between echo server and client."""
######################
# Imports & Globals
######################
# Arrowhead
# Requests with .p12 support
import requests_pkcs12
# Error output
import sys
# Argument parsing
import argparse
# Global configuration
exec(open("parameters.py").read())
######################
# Arrowhead Framework
######################
def addAuthorizationRule(consumerID, interfaceID, providerID, serviceID):
"""Add an authorization rule between echo client and echo server.
Return:
True when successful
"""
print ("Adding the authorization rule...")
# Authorize connection between client and server
data = {
"consumerId": consumerID,
"interfaceIds": [
interfaceID,
],
"providerIds": [
providerID,
],
"serviceDefinitionIds": [
serviceID,
],
}
res = requests_pkcs12.post(
CONFIG["url_auth"]
+ "mgmt/intracloud",
json=data, pkcs12_filename=CONFIG["auth_p12_path"], pkcs12_password=CONFIG["auth_p12_pass"])
print (res.status_code, res.text)
return res.status_code < 400
######################
# Main
######################
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="A script used for authorizing echo client and echo server communication.")
parser.add_argument("-c", type=int, required=True, metavar="consumerID",
help="ID of the consumer system")
parser.add_argument("-i", type=int, required=True, metavar="interfaceID",
help="ID of the used interface")
parser.add_argument("-p", type=int, required=True, metavar="providerID",
help="ID of the provider system")
parser.add_argument("-s", type=int, required=True, metavar="serviceID",
help="ID of the service")
args = parser.parse_args()
if not addAuthorizationRule(args.c, args.i, args.p, args.s):
print ("Unable add the intracloud rule.", file=sys.stderr)