X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=solution%2Fsmo%2Fcommon%2Fidentity%2Fconfig.py;fp=solution%2Fsmo%2Fcommon%2Fidentity%2Fconfig.py;h=22ef6413e1185864c1429e4b5df51501082c34bf;hb=cd1788251c44e71d0722b8b1e41f12efd8e3978e;hp=393d9189f26fa40eeb757be2f7ba3797a85704a2;hpb=05630a9d213a894be06f302029731c2fc32b1bb3;p=oam.git diff --git a/solution/smo/common/identity/config.py b/solution/smo/common/identity/config.py index 393d918..22ef641 100644 --- a/solution/smo/common/identity/config.py +++ b/solution/smo/common/identity/config.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -################################################################################ -# Copyright 2021 highstreet technologies GmbH +############################################################################# +# Copyright 2023 highstreet technologies GmbH # # Licensed under the Apache License, Version 2.0 (the 'License'); # you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ warnings.filterwarnings('ignore', message='Unverified HTTPS request') def get_environment_variable(name): configs = Properties() - path = pathlib.Path( os.path.dirname(os.path.abspath(__file__)) ) + path = pathlib.Path(os.path.dirname(os.path.abspath(__file__))) env_file = str(path.parent.absolute()) + '/.env' with open(env_file, "rb") as read_prop: configs.load(read_prop) @@ -62,12 +62,12 @@ def load_arguments(args: List[str]) -> tuple: def isReady(timeoutSeconds=180): - url = getBaseUrl(); + url = getBaseUrl() while timeoutSeconds > 0: try: response = requests.get(url, verify=False, headers={}) except: - pass + response = None if response is not None and response.status_code == 200: return True time.sleep(1) @@ -79,6 +79,8 @@ def getBaseUrl(): return get_environment_variable("IDENTITY_PROVIDER_URL") # Request a token for further communication + + def getToken(): url = base + '/realms/master/protocol/openid-connect/token' headers = { @@ -204,10 +206,10 @@ def createUsers(token, realmConfig, authConfig): "value": password, "temporary": True } - ], - "requiredActions": [ - "UPDATE_PASSWORD" - ] + ], + "requiredActions": [ + "UPDATE_PASSWORD" + ] } createUser(token, realmConfig, systemUser) @@ -218,7 +220,8 @@ def addUserRole(user: dict, role: dict, options: dict): url = options['url'] + '/' + user['id'] + '/role-mappings/realm' try: response = requests.post(url, verify=False, json=[ - {'id': role['id'], 'name':role['name']}], headers=options['headers']) + {'id': role['id'], 'name':role['name']}], + headers=options['headers']) except requests.exceptions.Timeout: sys.exit('HTTP request failed, please check you internet connection.') except requests.exceptions.TooManyRedirects: @@ -235,6 +238,7 @@ def addUserRole(user: dict, role: dict, options: dict): # searches for the role of a given user + def findRole(username: str, authConfig: dict, realmConfig: dict) -> dict: roleName = 'administration' for grant in authConfig['grants']: