-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsonar.py
36 lines (34 loc) · 1.42 KB
/
sonar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# import pyyaml module
import yaml
from yaml.loader import SafeLoader
import requests
def generate():
# Open the file and load the file
with open('openapi_sonar.yaml') as f:
data = yaml.load(f, Loader=SafeLoader)
urls={}
names={}
for i in data['paths']:
for j in data['paths'][i]:
if 'x-quantumCode' in data['paths'][i][j]:
urls[data['paths'][i][j]['x-quantumCode']]=data['paths'][i][j]['x-quantumProvider']
if 'operationId' in data['paths'][i][j] and 'x-quantumCode' in data['paths'][i][j]:
names[data['paths'][i][j]['x-quantumCode']]=data['paths'][i][j]['operationId']
x=None
for i in urls.keys():
f = open('./sonarQuantumAnalysis/'+names[i]+'.py', "w")
if i.endswith('.py'):
x = requests.get(i).text
f.write(x)
else:
header_value=i
header_value_utf8 = header_value.encode('utf-8')
if urls[i]=='aws':
x = requests.get('http://quantumservicesdeployment.spilab.es:8081/code/aws', headers={"x-url":header_value_utf8}).json()['code']
else:
x = requests.get('http://quantumservicesdeployment.spilab.es:8081/code/ibm', headers={"x-url":header_value_utf8}).json()['code']
for line in x:
f.write(line+'\n')
f.close()
if __name__ == '__main__':
generate()