Compare commits
5 Commits
feature/CU
...
master
| Author | SHA1 | Date |
|---|---|---|
|
|
f6ca720917 | |
|
|
f0f0f6412f | |
|
|
8271bb14ea | |
|
|
4eb73838d8 | |
|
|
de74e80811 |
|
|
@ -4,6 +4,7 @@
|
||||||
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
|
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "Python: Aktuelle Datei",
|
"name": "Python: Aktuelle Datei",
|
||||||
"type": "python",
|
"type": "python",
|
||||||
|
|
@ -11,6 +12,14 @@
|
||||||
"program": "${file}",
|
"program": "${file}",
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
"args": ["text"]
|
"args": ["text"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "createToken with arguments",
|
||||||
|
"type": "python",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "createToken.py",
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"args": ["PAAS","DynatraceInstaller","OPMAAS_123","Max_Mustermann@bmw.com","FG-8"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -5,11 +5,11 @@ import json
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
proxies=dict(http='socks5://localhost:3020', https='socks5://localhost:3020')
|
#proxies=dict(http='socks5://localhost:3020', https='socks5://localhost:3020')
|
||||||
|
|
||||||
def get_request(url, headers, proxies):
|
def get_request(url, headers):
|
||||||
try:
|
try:
|
||||||
response = requests.get(url, headers=headers, proxies=proxies)
|
response = requests.get(url, headers=headers)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except requests.exceptions.HTTPError as errh:
|
except requests.exceptions.HTTPError as errh:
|
||||||
return "An Http Error occurred:" + repr(errh)
|
return "An Http Error occurred:" + repr(errh)
|
||||||
|
|
@ -19,12 +19,11 @@ def get_request(url, headers, proxies):
|
||||||
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 post_request(url, headers,body, proxies):
|
def post_request(url, headers,body):
|
||||||
try:
|
try:
|
||||||
response = requests.post(url, body, headers=headers,verify=False, proxies=proxies)
|
response = requests.post(url, body, headers=headers,verify=False)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except requests.exceptions.HTTPError as errh:
|
except requests.exceptions.HTTPError as errh:
|
||||||
return "An Http Error occurred:" + repr(errh)
|
return "An Http Error occurred:" + repr(errh)
|
||||||
|
|
@ -34,12 +33,11 @@ def post_request(url, headers,body, proxies):
|
||||||
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, proxies):
|
def put_request(url, headers,body):
|
||||||
try:
|
try:
|
||||||
response = requests.put(url, body, headers=headers,verify=False, proxies=proxies)
|
response = requests.put(url, body, headers=headers,verify=False)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except requests.exceptions.HTTPError as errh:
|
except requests.exceptions.HTTPError as errh:
|
||||||
return "An Http Error occurred:" + repr(errh)
|
return "An Http Error occurred:" + repr(errh)
|
||||||
|
|
@ -49,37 +47,83 @@ def put_request(url, headers,body, proxies):
|
||||||
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 CreateToken(DTAPIToken, DTENV,nwzone, dtEnvInfo, tokenname):
|
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 = [
|
||||||
|
"InstallerDownload",
|
||||||
|
"SupportAlert"
|
||||||
|
]
|
||||||
|
DevOps_Read = [
|
||||||
|
"DataExport", # Access problem and event feed, metrics, and topology.
|
||||||
|
"DTAQLAccess", # User sessions.
|
||||||
|
"ReadSyntheticData", # Read synthetic monitors, locations, and nodes.
|
||||||
|
"metrics.read", # Read metrics.
|
||||||
|
"entities.read", # Read entities.
|
||||||
|
"problems.read", # Read problems.
|
||||||
|
"syntheticLocations.read", # Read synthetic locations.
|
||||||
|
"slo.read", # Read SLO.
|
||||||
|
"releases.read", # Read releases.
|
||||||
|
"activeGates.read"
|
||||||
|
]
|
||||||
|
ReadAll = [
|
||||||
|
"DataExport", # Access problem and event feed, metrics, and topology.
|
||||||
|
"ReadConfig", # Read configuration.
|
||||||
|
"DTAQLAccess", # User sessions.
|
||||||
|
"ReadSyntheticData", # Read synthetic monitors, locations, and nodes.
|
||||||
|
"auditLogs.read", # Read audit logs.
|
||||||
|
"metrics.read", # Read metrics.
|
||||||
|
"entities.read", # Read entities.
|
||||||
|
"problems.read", # Read problems.
|
||||||
|
"networkZones.read", # Read network zones.
|
||||||
|
"activeGates.read", # Read ActiveGates.
|
||||||
|
"credentialVault.read", # Read credential vault entries.
|
||||||
|
"extensions.read", # Read extensions.
|
||||||
|
"extensionConfigurations.read", # Read extension monitoring configurations.
|
||||||
|
"extensionEnvironment.read", # Read extension environment configurations.
|
||||||
|
"securityProblems.read", # Read security problems.
|
||||||
|
"syntheticLocations.read", # Read synthetic locations.
|
||||||
|
"slo.read", # Read SLO.
|
||||||
|
"releases.read", # Read releases.
|
||||||
|
"apiTokens.read" # Read API tokens.
|
||||||
|
]
|
||||||
|
|
||||||
|
temp=[]
|
||||||
|
if "DynatraceInstaller" in scope:
|
||||||
|
temp.extend(DynatraceInstaller)
|
||||||
|
if "DevOps_Read" in scope:
|
||||||
|
temp.extend(DevOps_Read)
|
||||||
|
if "ReadAll" in scope:
|
||||||
|
temp.extend(ReadAll)
|
||||||
|
|
||||||
data = '{"name":"' + tokenname + '","scopes":["InstallerDownload","ReadConfig","WriteConfig","DataExport"]}'
|
if not temp:
|
||||||
#data = '{"name":"' + tokenname + '","scopes":["ReadConfig","DataExport","entities.read"]}'
|
print("scope not supported")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
r = post_request(DTAPIURL,headers,data, proxies)
|
data = '{"name":"' + tokenname + '","scopes":["' + "\",\"".join(temp) + '"]}' #[""] InstallerDownload",""
|
||||||
|
#data = '{"name":"' + tokenname + '","scopes":' + str(temp) + '}' #[""]
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
#################
|
#################
|
||||||
##main
|
##main
|
||||||
#################
|
#################
|
||||||
|
print(sys.argv)
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 6:
|
||||||
print('createToken.py <filename>')
|
print("createToken.py <TYPE> <SCOPE> <TICKET_NR> <email-address of requestor> <PURPOSE>\n")
|
||||||
|
print("TYPE: API, PAAS, APIPAAS")
|
||||||
|
print("SCOPE: DynatraceInstaller, DevOps_Read, ReadAll")
|
||||||
|
print("further details: https://atc.bmwgroup.net/confluence/display/OPMAAS/Token+Management")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
with open('./environment.yaml') as file:
|
with open('./environment.yaml') as file:
|
||||||
|
|
@ -87,7 +131,12 @@ with open('./environment.yaml') as file:
|
||||||
|
|
||||||
df = pd.DataFrame()
|
df = pd.DataFrame()
|
||||||
#tokenname="runtime_AKS"
|
#tokenname="runtime_AKS"
|
||||||
tokenname=sys.argv[1]
|
type=sys.argv[1]
|
||||||
|
scope=sys.argv[2]
|
||||||
|
ticketnr=sys.argv[3]
|
||||||
|
email=sys.argv[4].replace("_","-")
|
||||||
|
purpose=sys.argv[5]
|
||||||
|
tokenname=type+"_"+ticketnr+"_"+email+"_"+purpose
|
||||||
|
|
||||||
for item, doc in doc.items():
|
for item, doc in doc.items():
|
||||||
token = dict(doc[2])
|
token = dict(doc[2])
|
||||||
|
|
@ -100,10 +149,8 @@ for item, doc in doc.items():
|
||||||
print("Gather data, hold on a minute")
|
print("Gather data, hold on a minute")
|
||||||
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)
|
|
||||||
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)
|
||||||
|
|
|
||||||
9
env
9
env
|
|
@ -1,9 +0,0 @@
|
||||||
NAPROD_TOKEN_VAR="<yourtoken>"
|
|
||||||
EUPREPROD_TOKEN_VAR="<yourtoken>"
|
|
||||||
NAPREPROD_TOKEN_VAR="<yourtoken>"
|
|
||||||
CNPROD_TOKEN_VAR="<yourtoken>"
|
|
||||||
CNPREPROD_TOKEN_VAR="<yourtoken>"
|
|
||||||
GLOBAL_TOKEN_VAR="<yourtoken>"
|
|
||||||
TERRA_TOKEN_VAR="<yourtoken>"
|
|
||||||
|
|
||||||
REPORTING_FOLDER="./Reporting_CSV/"
|
|
||||||
|
|
@ -22,15 +22,15 @@ naprod:
|
||||||
- env-token-name: "NAPROD_TOKEN_VAR"
|
- env-token-name: "NAPROD_TOKEN_VAR"
|
||||||
- network-zone: "coco.na.aws.prod"
|
- network-zone: "coco.na.aws.prod"
|
||||||
- env-info: "E2E/PROD"
|
- env-info: "E2E/PROD"
|
||||||
#cnprod:
|
cnprod:
|
||||||
- name: "cnprod"
|
- name: "cnprod"
|
||||||
- env-url: "https://dynatracemgd-cn.bmwgroup.net/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b"
|
- env-url: "https://dyna-synth-cn.bmwgroup.com.cn/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b"
|
||||||
- env-token-name: "CNPROD_TOKEN_VAR"
|
- env-token-name: "CNPROD_TOKEN_VAR"
|
||||||
- network-zone: "coco.cn.aws-tsp.prod"
|
- network-zone: "coco.cn.aws-tsp.prod"
|
||||||
- env-info: "E2E/PROD"
|
- env-info: "E2E/PROD"
|
||||||
#cnpreprod:
|
cnpreprod:
|
||||||
- name: "cnpreprod"
|
- name: "cnpreprod"
|
||||||
- env-url: "https://dynatracemgd-cn.bmwgroup.net/e/b921f1b9-c00e-4031-b9d1-f5a0d530757b"
|
- env-url: "https://dyna-synth-cn.bmwgroup.com.cn/e/ab88c03b-b7fc-45f0-9115-9e9ecc0ced35"
|
||||||
- env-token-name: "CNPREPROD_TOKEN_VAR"
|
- env-token-name: "CNPREPROD_TOKEN_VAR"
|
||||||
- network-zone: "coco.cn.aws-tsp.preprod"
|
- network-zone: "coco.cn.aws-tsp.preprod"
|
||||||
- env-info: "DEV/INT"
|
- env-info: "DEV/INT"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue