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
question from:
https://stackoverflow.com/questions/65599200/reading-yaml-file-in-python-is-this-the-best-way 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…