This repository has been archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthv2.py
executable file
·49 lines (42 loc) · 1.54 KB
/
Authv2.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
import os
import requests
import json
class Authv2:
auth_token_subservice = None
def __init__(self) -> None:
pass
def get_auth_token_subservice(self, service, subservice):
# Get env variables
protocol = os.environ.get("AUTH_PROTOCOL")
endpoint_keystone = os.environ.get("ENDPOINT_KEYSTONE")
username = os.environ.get("AUTH_USER")
password = os.environ.get("AUTH_PASSWORD")
url = "{PROTOCOL}://{ENDPOINT_KEYSTONE}/v3/auth/tokens".format(
PROTOCOL=protocol, ENDPOINT_KEYSTONE=endpoint_keystone
)
payload = json.dumps(
{
"auth": {
"scope": {
"project": {"domain": {"name": service}, "name": subservice}
},
"identity": {
"password": {
"user": {
"domain": {"name": service},
"password": password,
"name": username,
}
},
"methods": ["password"],
},
}
}
)
headers = {"Content-Type": "application/json", "Accept": "application/json"}
# Perform request
response = requests.request(
"POST", url, headers=headers, data=payload, verify=False
)
auth_token_subservice = response.headers["X-Subject-Token"]
return auth_token_subservice