Code changes suggested by AWX repo reviewer team

This commit is contained in:
Asharma-bhavna
2021-01-22 17:12:22 +05:30
committed by Ryan Petrello
parent bbf283d1fd
commit 18752a637f

View File

@@ -46,20 +46,16 @@ def handle_auth(**kwargs):
"grant_type": "client_credentials", "grant_type": "client_credentials",
"scope":"siem" "scope":"siem"
} }
post_header = {
"Authorization": 'Basic ' + base64.b64encode(bytes(kwargs['client_id'] + ":" + kwargs['client_password'], 'ascii')).decode('ascii')
}
response = requests.post( response = requests.post(
kwargs['endpoint'], kwargs['endpoint'],
data = post_data, data = post_data,
headers = post_header, auth = (kwargs['client_id'],kwargs['client_password']),
verify = True, verify = True,
timeout = (5, 30) timeout = (5, 30)
) )
raise_for_status(response) raise_for_status(response)
tokens = json.loads(response.text)
try: try:
return tokens['access_token'] return response.json()['access_token']
except KeyError: except KeyError:
raise RuntimeError('OAuth request to tenant was unsuccessful') raise RuntimeError('OAuth request to tenant was unsuccessful')
@@ -81,12 +77,10 @@ def get_ID(**kwargs):
timeout = (5, 30) timeout = (5, 30)
) )
raise_for_status(response) raise_for_status(response)
tokens = json.loads(response.text)
result_str=tokens["Result"]["Results"]
try: try:
acc_ID=result_str[0]["Row"]["ID"] result_str = response.json()["Result"]["Results"]
return acc_ID return result_str[0]["Row"]["ID"]
except IndexError: except (IndexError, KeyError):
raise RuntimeError("Error Detected!! Check the Inputs") raise RuntimeError("Error Detected!! Check the Inputs")
@@ -105,16 +99,14 @@ def get_passwd(**kwargs):
timeout = (5, 30) timeout = (5, 30)
) )
raise_for_status(response) raise_for_status(response)
tokens=json.loads(response.text)
try: try:
result_str=tokens["Result"]["Password"] return response.json()["Result"]["Password"]
return result_str except KeyError:
except TypeError:
raise RuntimeError("Password Not Found") raise RuntimeError("Password Not Found")
def centrify_backend(**kwargs): def centrify_backend(**kwargs):
url = kwargs.get('url') # url = kwargs.get('url')
acc_name = kwargs.get('account-name') acc_name = kwargs.get('account-name')
system_name = kwargs.get('system-name') system_name = kwargs.get('system-name')
client_id = kwargs.get('client_id') client_id = kwargs.get('client_id')