Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit e4514cd

Browse files
authored
Update create_resources_and_upload_app_local.py
1 parent 133a038 commit e4514cd

File tree

1 file changed

+88
-84
lines changed

1 file changed

+88
-84
lines changed

scripts/tests/create_resources_and_upload_app_local.py

Lines changed: 88 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from requests import HTTPError
77

88
##########################
9-
# CONNECTOR API SETTINGS #
9+
# APPSTORE API SETTINGS #
1010
##########################
1111
apiUser = "admin"
1212
apiPassword = "password"
@@ -18,9 +18,9 @@
1818
else:
1919
combined_host = f"{protocol}://{host}"
2020

21-
##############################
22-
# APPSTORE REGISTRY SETTINGS #
23-
##############################
21+
########################################
22+
# APPSTORE REGISTRY SETTINGS (HARBOR) #
23+
########################################
2424
registry_address = "app.registry.example.org"
2525
registry_repo_name = "library"
2626
registry_user = "admin"
@@ -32,88 +32,13 @@
3232
client = docker.from_env()
3333

3434
resource_id_tag_version = "latest"
35-
image_name = "ahemid:idsapp"
35+
image_name = "ahemid/idsapp"
3636

3737
resource_version = 1
3838

39-
####################
40-
# REQUEST SETTINGS #
41-
####################
42-
requests.packages.urllib3.disable_warnings()
43-
session_creds = requests.Session()
44-
session_creds.auth = (apiUser, apiPassword)
45-
session_creds.verify = False
46-
47-
session = requests.session()
48-
session.verify = False
49-
50-
51-
############################
52-
# HTTP POST HELPER METHODS #
53-
############################
54-
def get_request_check_response(url, creds=True):
55-
try:
56-
if creds is True:
57-
response_tmp = session_creds.get(url)
58-
time.sleep(5)
59-
response_tmp.raise_for_status()
60-
else:
61-
response_tmp = session.get(url)
62-
time.sleep(5)
63-
response_tmp.raise_for_status()
64-
return response_tmp
65-
except HTTPError as http_error:
66-
pprint(f"HTTP ERROR OCCURED: {http_error}")
67-
except Exception as err:
68-
pprint(f"Something went wrong sending the request: {err}")
69-
70-
71-
def post_request_check_response(url, json, creds=True, ret_location=True):
72-
if json is None:
73-
raise Exception(f"Problem with request json!, json= {json}")
74-
try:
75-
if creds is True:
76-
response_tmp = session_creds.post(url, json=json)
77-
response_tmp.raise_for_status()
78-
else:
79-
response_tmp = session.post(url, data=json)
80-
response_tmp.raise_for_status()
81-
82-
if ret_location is True:
83-
loc = response_tmp.headers["Location"]
84-
if loc is None:
85-
raise Exception(f"Problem with response location!, requestUrl={url}")
86-
pprint.pprint(loc)
87-
return loc
88-
else:
89-
return response_tmp
90-
91-
except HTTPError as http_error:
92-
pprint(f"HTTP ERROR OCCURED: {http_error}")
93-
except Exception as err:
94-
pprint(f"Something went wrong sending the request: {err}")
95-
96-
97-
def post_description_request(recipient, element_id):
98-
params = {}
99-
if recipient is not None:
100-
params["recipient"] = recipient
101-
if element_id is not None:
102-
params["elementId"] = element_id
103-
try:
104-
response_tmp = session_creds.post(f"{combined_host}/api/ids/description", params=params)
105-
response_tmp.raise_for_status()
106-
return response_tmp
107-
except HTTPError as http_error:
108-
pprint(f"HTTP ERROR OCCURED: {http_error}")
109-
except Exception as err:
110-
pprint(f"Something WENT WRONG SENDING THE REQUEST: {err}")
111-
else:
112-
pprint(f"REQUEST SUCCESSFULL!")
113-
11439

11540
############################
116-
# CREATE RESOURCES METHODS #
41+
# APP METADATA METHODS #
11742
############################
11843

11944
def create_catalog():
@@ -158,8 +83,8 @@ def create_dataApp():
15883
"title": "DataApp Information",
15984
"description": "This is the dataApp information for the DataProcessingApp.",
16085
"docs": "App-related human-readable documentation.",
161-
"environmentVariables": "Env1=environmentvariable;Env2=environmentvariable2",
162-
"storageConfig": "/data/temp:/temp",
86+
"environmentVariables": "dbUser=sa;dbPasswd=passwd",
87+
"storageConfig": "-v /data",
16388
"supportedUsagePolicies": [
16489
"PROVIDE_ACCESS"
16590
]
@@ -244,6 +169,10 @@ def create_rule_allow_access():
244169
loc = post_request_check_response(f"{combined_host}/api/rules", json)
245170
return loc
246171

172+
##########################################################################
173+
# USUALLY, IT SHOULD NOT BE NECESSARY TO CHANGE ANYTHING BELOW THIS LINE #
174+
##########################################################################
175+
247176

248177
#############################
249178
# LINKING RESOURCES METHODS #
@@ -287,7 +216,82 @@ def add_contract_to_resource(resource, contract):
287216
def add_rule_to_contract(contract, rule):
288217
link_two_resources(contract, rule)
289218

219+
####################
220+
# REQUEST SETTINGS #
221+
####################
222+
requests.packages.urllib3.disable_warnings()
223+
session_creds = requests.Session()
224+
session_creds.auth = (apiUser, apiPassword)
225+
session_creds.verify = False
226+
227+
session = requests.session()
228+
session.verify = False
229+
230+
231+
############################
232+
# HTTP POST HELPER METHODS #
233+
############################
234+
def get_request_check_response(url, creds=True):
235+
try:
236+
if creds is True:
237+
response_tmp = session_creds.get(url)
238+
time.sleep(5)
239+
response_tmp.raise_for_status()
240+
else:
241+
response_tmp = session.get(url)
242+
time.sleep(5)
243+
response_tmp.raise_for_status()
244+
return response_tmp
245+
except HTTPError as http_error:
246+
pprint(f"HTTP ERROR OCCURED: {http_error}")
247+
except Exception as err:
248+
pprint(f"Something went wrong sending the request: {err}")
249+
250+
251+
def post_request_check_response(url, json, creds=True, ret_location=True):
252+
if json is None:
253+
raise Exception(f"Problem with request json!, json= {json}")
254+
try:
255+
if creds is True:
256+
response_tmp = session_creds.post(url, json=json)
257+
response_tmp.raise_for_status()
258+
else:
259+
response_tmp = session.post(url, data=json)
260+
response_tmp.raise_for_status()
261+
262+
if ret_location is True:
263+
loc = response_tmp.headers["Location"]
264+
if loc is None:
265+
raise Exception(f"Problem with response location!, requestUrl={url}")
266+
pprint.pprint(loc)
267+
return loc
268+
else:
269+
return response_tmp
270+
271+
except HTTPError as http_error:
272+
pprint(f"HTTP ERROR OCCURED: {http_error}")
273+
except Exception as err:
274+
pprint(f"Something went wrong sending the request: {err}")
275+
276+
277+
def post_description_request(recipient, element_id):
278+
params = {}
279+
if recipient is not None:
280+
params["recipient"] = recipient
281+
if element_id is not None:
282+
params["elementId"] = element_id
283+
try:
284+
response_tmp = session_creds.post(f"{combined_host}/api/ids/description", params=params)
285+
response_tmp.raise_for_status()
286+
return response_tmp
287+
except HTTPError as http_error:
288+
pprint(f"HTTP ERROR OCCURED: {http_error}")
289+
except Exception as err:
290+
pprint(f"Something WENT WRONG SENDING THE REQUEST: {err}")
291+
else:
292+
pprint(f"REQUEST SUCCESSFULL!")
290293

294+
291295
#################
292296
# DOCKER METHOD #
293297
#################
@@ -382,7 +386,7 @@ def tag_image_for_registry(image_tmp, resource_id_tmp, resource_version_tmp, reg
382386
# Tag image
383387
tagged = image_tmp.tag(complete_tag)
384388
if tagged is True:
385-
pprint.pprint(f"Successfully taged image. image={image_tmp}, tag={complete_tag}")
389+
pprint.pprint(f"Successfully tagged image. image={image_tmp}, tag={complete_tag}")
386390
return complete_tag
387391
else:
388392
raise Exception("Failed to tag image.")

0 commit comments

Comments
 (0)