diff --git a/README.MD b/README.MD index c24f98d..022557e 100644 --- a/README.MD +++ b/README.MD @@ -4,10 +4,9 @@ This script allows to programmatically fetch all credential-attributes from Cont # USAGE (powershell) ``` -.\main.py --cr_url="https://aa1-app2019.iacc.epam.com" --username="andoni_aguirre_aranguren_creator" --password="notmypasswordyoudumb" +.\main.py --cr_url="https://aa1-app2019.iacc.epam.com" --username="andoni_aguirre_aranguren_creator" --api_key="123fsda" ``` # FUTURE POSSIBLE ENHANCEMENTS -* API Key usage instead of password pending (this may be done in next release) * Multi-threading for the http requests diff --git a/functions.py b/functions.py index 81c6449..0d0da84 100644 --- a/functions.py +++ b/functions.py @@ -18,6 +18,23 @@ def get_token_password(cr_url, username, password): return r.json()['token'] +def get_token_apikey(cr_url, username, api_key): + endpoint = "/v1/authentication" + url = cr_url + endpoint + headers = { + "Content-Type": "application/json" + } + + payload = { + "username": username, + "apiKey": api_key + } + + r = requests.post(url=url, headers=headers, json=payload, verify=False) + r.raise_for_status() + return r.json()['token'] + + def get_credential_list(cr_url, token): endpoint = "/v2/credentialvault/credentials/list" url = cr_url + endpoint diff --git a/main.py b/main.py index e15c3a5..7a8e5c7 100644 --- a/main.py +++ b/main.py @@ -10,13 +10,15 @@ "setup or they are fetched from external key vault") parser.add_argument("--cr_url", help="url of the control room (without the / at the end!) ") parser.add_argument("--username", help="full username with domain if AD") - parser.add_argument("--password", help="password") + # parser.add_argument("--password", help="password") + parser.add_argument("--api_key", help="api key of user") args = parser.parse_args() cr_url = str(args.cr_url) user = str(args.username) - password = str(args.password) + # password = str(args.password) + api_key = str(args.api_key) # Get token - token = f.get_token_password(cr_url, user, password) + token = f.get_token_apikey(cr_url, user, api_key) # Credential list credential_list_json = f.get_credential_list(cr_url, token) # Prepare dataframe