Add documentation to methods and fixed access link to DCImanager 6
This commit is contained in:
parent
e57c3209ed
commit
cf1cb49a82
46
main.py
46
main.py
@ -25,6 +25,15 @@ class Access(object):
|
|||||||
self.platform = platform
|
self.platform = platform
|
||||||
|
|
||||||
def get_admin(self):
|
def get_admin(self):
|
||||||
|
"""
|
||||||
|
The method gets the first 10 active database users
|
||||||
|
and finds the admin among them. I couldn't create
|
||||||
|
a request filtering by the roles field because
|
||||||
|
peewee doesn't understand json and can't make a selection
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
_dict_: admin data
|
||||||
|
"""
|
||||||
query_admin = (self.user_table.select(
|
query_admin = (self.user_table.select(
|
||||||
self.user_table.id,
|
self.user_table.id,
|
||||||
self.user_table.email,
|
self.user_table.email,
|
||||||
@ -34,6 +43,7 @@ class Access(object):
|
|||||||
(self.user_table.state == "active")
|
(self.user_table.state == "active")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
# !peewee doesn't work well with JSONfield MySQL
|
||||||
for field in query_admin:
|
for field in query_admin:
|
||||||
if field.roles[0] == '@admin':
|
if field.roles[0] == '@admin':
|
||||||
admin = dict(
|
admin = dict(
|
||||||
@ -46,13 +56,24 @@ class Access(object):
|
|||||||
return admin
|
return admin
|
||||||
|
|
||||||
def get_key(self, admin):
|
def get_key(self, admin):
|
||||||
|
"""
|
||||||
|
Makes a post request to the endpoint
|
||||||
|
passing the admin data and
|
||||||
|
returns the generated access key
|
||||||
|
|
||||||
|
Args:
|
||||||
|
admin (_dict_): _admin data_
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
_dict_: _access key_
|
||||||
|
"""
|
||||||
host = self.input_container
|
host = self.input_container
|
||||||
if self.platform == "vm":
|
if self.platform == "vm":
|
||||||
url = 'http://{}:1500/auth/v4/user/{}/key'.format(
|
url = 'http://{}:1500/auth/v4/user/{}/key'.format(
|
||||||
host, admin['id']
|
host, admin['id']
|
||||||
)
|
)
|
||||||
if self.platform == "dci":
|
if self.platform == "dci":
|
||||||
url = 'http://{}:1500/auth/v3/user/{}/key'.format(
|
url = 'http://{}:1500/auth/v4/user/{}/key'.format(
|
||||||
host, admin['email']
|
host, admin['email']
|
||||||
)
|
)
|
||||||
headers = {"Internal-Auth": "on", "Accept": "application/json"}
|
headers = {"Internal-Auth": "on", "Accept": "application/json"}
|
||||||
@ -60,6 +81,27 @@ class Access(object):
|
|||||||
result = req.json()
|
result = req.json()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def make_access_link(self, key):
|
||||||
|
"""
|
||||||
|
Generates a clickable link which will be received in stdout
|
||||||
|
|
||||||
|
Args:
|
||||||
|
key (_dict_): _access key data_
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
_str_: link to access the platform
|
||||||
|
"""
|
||||||
|
key_type = 'key' # why for dcimgr key-4 ???
|
||||||
|
|
||||||
|
access_link = 'https://{}/auth/{}/{}'.format(
|
||||||
|
CLIENT_HOST, key_type, key['key']
|
||||||
|
)
|
||||||
|
if self.platform == 'dci':
|
||||||
|
access_link = 'https://{}/auth/{}/{}'.format(
|
||||||
|
CLIENT_HOST, key_type, key['key']
|
||||||
|
)
|
||||||
|
return access_link
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""
|
"""
|
||||||
@ -80,7 +122,7 @@ def main():
|
|||||||
print("Key will be used:")
|
print("Key will be used:")
|
||||||
print(key, "\n")
|
print(key, "\n")
|
||||||
|
|
||||||
access_link = 'https://{}/auth/key/{}'.format(CLIENT_HOST, key['key'])
|
access_link = access.make_access_link(key)
|
||||||
|
|
||||||
print("Your access link: \n")
|
print("Your access link: \n")
|
||||||
print(access_link, "\n")
|
print(access_link, "\n")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user