С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

35
main.py
View File

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