Skip to content

Commit

Permalink
api key instead of password
Browse files Browse the repository at this point in the history
  • Loading branch information
aagirre92 committed Jan 26, 2023
1 parent d53e616 commit 142c000
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
3 changes: 1 addition & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 142c000

Please sign in to comment.