0

To give you a little bit of background, I am creating a function to automate some tasks for a personal project. I have used a conf file in the YAML format to help structure data and make it more 'user friendly'.

Conf.yaml

---
Version: 0.0.1
CyberArk:
 PVWA:
  URL: https://cyberark.corp.local
 OnboardingAccount:
  AppID: RESTAPI
  Safe: cashrd
  Username: api
Requests:
 Auth: /PasswordVault/API/Auth/CyberArk/Logon
 AAM: /AIMWebService/api/Accounts?AppID={}&Safe={}&Username={}

MainFunctions.py

    def fetch_api_information():
    url = fetch_url()
    for i in configuration['CyberArk']:
        appid = configuration['CyberArk']['OnboardingAccount']['AppID']
        safe = configuration['CyberArk']['OnboardingAccount']['Safe']
        username = configuration['CyberArk']['OnboardingAccount']['Username']
        aam = configuration['CyberArk']['Requests']['AAM']
    url += aam.format(appid, safe, username)
    client = "RESTAPI.crt"
    key = "RESTAPI.key"
    ssl = "PVWA.pem"
    headers = {
        'Content-Type': 'application/json'
    }
    response = requests.request("GET", url, headers=headers, verify=ssl, cert=(client, key))
    apidetail = json.loads(response.text)
    return apidetail

Essentially what the code is make a API request based on the AppID, Safe and Username then returning a load of information about the account (metadata).

Is there a better way of looping through the information or am I on the right tracks?

Please go easy, this is my first post :D

  • Great question: However, this is a duplicate. https://stackoverflow.com/questions/42568084/read-value-from-config-file-python – Paul Tuckett Jan 06 '21 at 16:19
  • 1
    Try loading the config with yaml module, not sure if you're doing that or not because I don't see full code where you define configuration – Ari K Jan 06 '21 at 16:26

0 Answers0