Сode refactoring, removing block with input_container because in both platforms you can make a request to the same endpoint

This commit is contained in:
Stepan Zhukovsky 2022-09-25 16:46:35 +09:00
parent 33a775dbbd
commit 009535ba8d

39
main.py
View File

@ -17,12 +17,11 @@ class Access(object):
""" """
def __init__(self, platform): def __init__(self, platform):
if platform == 'vm': if platform == 'vm':
self.input_container = 'vm_box'
self.user_table = VmAccount self.user_table = VmAccount
if platform == 'dci': if platform == 'dci':
self.input_container = 'input'
self.user_table = AuthUser self.user_table = AuthUser
self.platform = platform self.platform = platform
self.input_container = 'input'
def get_admin(self): def get_admin(self):
""" """
@ -57,8 +56,8 @@ class Access(object):
def get_key(self, admin): def get_key(self, admin):
""" """
Makes a post request to the endpoint Makes a post request to the endpoint
passing the admin data and passing the admin data and
returns the generated access key returns the generated access key
Args: Args:
@ -67,33 +66,13 @@ class Access(object):
Returns: Returns:
_dict_: _access key_ _dict_: _access key_
""" """
host = self.input_container url = 'http://{}:1500/api/auth/v4/user/{}/key'.format(
url = 'http://{}:1500/auth/v4/user/{}/key'.format(host, admin['id']) self.input_container, admin['id']
)
headers = {"Internal-Auth": "on", "Accept": "application/json"} headers = {"Internal-Auth": "on", "Accept": "application/json"}
req = requests.post(url, headers=headers, data={}) req = requests.post(url, headers=headers, data={})
result = req.json() key = req.json()
return result return key
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():
@ -115,7 +94,7 @@ def main():
print("Key will be used:") print("Key will be used:")
print(key, "\n") print(key, "\n")
access_link = access.make_access_link(key) access_link = 'https://{}/auth/key-v4/{}'.format(CLIENT_HOST, key['key'])
print("Your access link: \n") print("Your access link: \n")
print(access_link, "\n") print(access_link, "\n")