Wukong-Huahua / utils.py
drizzlezyk's picture
update for multi-node delivery
f829abc
import os
import requests
def get_token():
username = os.environ["username"]
domain_name = os.environ["domain_name"]
domain_pwd = os.environ["domain_pwd"]
url = os.environ["token_url"]
requests_json = {
"auth": {
"identity": {
"methods": ["password"],
"password": {
"user": {
"name": username,
"password": domain_pwd,
"domain": {
"name": domain_name
}
}
}
},
"scope": {
"project": {
"name": "cn-central-221"
}
}
}
}
headers = {
"Content-Type": "text/plain"
}
response = requests.post(url, json=requests_json, headers=headers)
assert response.status_code == 201
result = response.headers
print("token success")
return result['X-Subject-Token']
if __name__ == "__main__":
get_token()