Compare commits
No commits in common. "master" and "modified_script" have entirely different histories.
master
...
modified_s
|
|
@ -32,7 +32,7 @@ def post_request(url, headers,body):
|
||||||
except requests.exceptions.Timeout as errt:
|
except requests.exceptions.Timeout as errt:
|
||||||
return "A Timeout Error occurred:" + repr(errt)
|
return "A Timeout Error occurred:" + repr(errt)
|
||||||
except requests.exceptions.RequestException as err:
|
except requests.exceptions.RequestException as err:
|
||||||
return "An Unknown Error occurred" + repr(err)
|
return "An Unknown Error occurred" + repr(err)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def put_request(url, headers,body):
|
def put_request(url, headers,body):
|
||||||
|
|
@ -50,17 +50,21 @@ def put_request(url, headers,body):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def CreateToken(DTAPIToken, DTENV,nwzone, dtEnvInfo, tokenname,scope):
|
def CreateToken(DTAPIToken, DTENV,nwzone, dtEnvInfo, tokenname,scope):
|
||||||
|
|
||||||
env = DTENV
|
env = DTENV
|
||||||
DTAPIToken = DTAPIToken
|
DTAPIToken = DTAPIToken
|
||||||
DTAPIURL = env + "/api/v2/apiTokens"
|
DTAPIURL = env + "/api/v2/apiTokens"
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': 'Api-Token ' + DTAPIToken
|
'Authorization': 'Api-Token ' + DTAPIToken
|
||||||
}
|
}
|
||||||
|
|
||||||
DynatraceInstaller = [
|
DynatraceInstaller = [
|
||||||
"InstallerDownload",
|
"InstallerDownload",
|
||||||
"SupportAlert"
|
"SupportAlert"
|
||||||
]
|
]
|
||||||
|
|
||||||
DevOps_Read = [
|
DevOps_Read = [
|
||||||
"DataExport", # Access problem and event feed, metrics, and topology.
|
"DataExport", # Access problem and event feed, metrics, and topology.
|
||||||
"DTAQLAccess", # User sessions.
|
"DTAQLAccess", # User sessions.
|
||||||
|
|
@ -72,7 +76,8 @@ def CreateToken(DTAPIToken, DTENV,nwzone, dtEnvInfo, tokenname,scope):
|
||||||
"slo.read", # Read SLO.
|
"slo.read", # Read SLO.
|
||||||
"releases.read", # Read releases.
|
"releases.read", # Read releases.
|
||||||
"activeGates.read"
|
"activeGates.read"
|
||||||
]
|
]
|
||||||
|
|
||||||
ReadAll = [
|
ReadAll = [
|
||||||
"DataExport", # Access problem and event feed, metrics, and topology.
|
"DataExport", # Access problem and event feed, metrics, and topology.
|
||||||
"ReadConfig", # Read configuration.
|
"ReadConfig", # Read configuration.
|
||||||
|
|
@ -93,8 +98,8 @@ def CreateToken(DTAPIToken, DTENV,nwzone, dtEnvInfo, tokenname,scope):
|
||||||
"slo.read", # Read SLO.
|
"slo.read", # Read SLO.
|
||||||
"releases.read", # Read releases.
|
"releases.read", # Read releases.
|
||||||
"apiTokens.read" # Read API tokens.
|
"apiTokens.read" # Read API tokens.
|
||||||
]
|
]
|
||||||
|
|
||||||
temp=[]
|
temp=[]
|
||||||
if "DynatraceInstaller" in scope:
|
if "DynatraceInstaller" in scope:
|
||||||
temp.extend(DynatraceInstaller)
|
temp.extend(DynatraceInstaller)
|
||||||
|
|
@ -102,7 +107,7 @@ def CreateToken(DTAPIToken, DTENV,nwzone, dtEnvInfo, tokenname,scope):
|
||||||
temp.extend(DevOps_Read)
|
temp.extend(DevOps_Read)
|
||||||
if "ReadAll" in scope:
|
if "ReadAll" in scope:
|
||||||
temp.extend(ReadAll)
|
temp.extend(ReadAll)
|
||||||
|
|
||||||
if not temp:
|
if not temp:
|
||||||
print("scope not supported")
|
print("scope not supported")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
@ -113,6 +118,7 @@ def CreateToken(DTAPIToken, DTENV,nwzone, dtEnvInfo, tokenname,scope):
|
||||||
r = post_request(DTAPIURL,headers,data)
|
r = post_request(DTAPIURL,headers,data)
|
||||||
print(r)
|
print(r)
|
||||||
row = {'Environment':dtEnvInfo,'DT_API_URL':env +"/api", 'DT_[API|PAAS]_TOKEN':r.json()['token'],'DT_NETWORK_ZONE':nwzone}
|
row = {'Environment':dtEnvInfo,'DT_API_URL':env +"/api", 'DT_[API|PAAS]_TOKEN':r.json()['token'],'DT_NETWORK_ZONE':nwzone}
|
||||||
|
|
||||||
return row
|
return row
|
||||||
|
|
||||||
#################
|
#################
|
||||||
|
|
@ -150,8 +156,8 @@ for item, doc in doc.items():
|
||||||
DTTOKEN = config(token.get('env-token-name'))
|
DTTOKEN = config(token.get('env-token-name'))
|
||||||
DTURL = url.get('env-url')
|
DTURL = url.get('env-url')
|
||||||
row = CreateToken(DTTOKEN,DTURL,nwzone.get('network-zone'),dtEnvInfo.get('env-info'),tokenname,scope)
|
row = CreateToken(DTTOKEN,DTURL,nwzone.get('network-zone'),dtEnvInfo.get('env-info'),tokenname,scope)
|
||||||
df = df.append(row,ignore_index=True)
|
df = df.append(row,ignore_index=True)
|
||||||
else:
|
else:
|
||||||
print("token not found, skipping " + item)
|
print("token not found, skipping " + item)
|
||||||
print(df)
|
print(df)
|
||||||
df.to_excel(tokenname+".xlsx")
|
df.to_excel(tokenname+".xlsx")
|
||||||
Loading…
Reference in New Issue