|
6 | 6 | from requests import HTTPError |
7 | 7 |
|
8 | 8 | ########################## |
9 | | -# CONNECTOR API SETTINGS # |
| 9 | +# APPSTORE API SETTINGS # |
10 | 10 | ########################## |
11 | 11 | apiUser = "admin" |
12 | 12 | apiPassword = "password" |
|
18 | 18 | else: |
19 | 19 | combined_host = f"{protocol}://{host}" |
20 | 20 |
|
21 | | -############################## |
22 | | -# APPSTORE REGISTRY SETTINGS # |
23 | | -############################## |
| 21 | +######################################## |
| 22 | +# APPSTORE REGISTRY SETTINGS (HARBOR) # |
| 23 | +######################################## |
24 | 24 | registry_address = "app.registry.example.org" |
25 | 25 | registry_repo_name = "library" |
26 | 26 | registry_user = "admin" |
|
32 | 32 | client = docker.from_env() |
33 | 33 |
|
34 | 34 | resource_id_tag_version = "latest" |
35 | | -image_name = "ahemid:idsapp" |
| 35 | +image_name = "ahemid/idsapp" |
36 | 36 |
|
37 | 37 | resource_version = 1 |
38 | 38 |
|
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 | | - |
114 | 39 |
|
115 | 40 | ############################ |
116 | | -# CREATE RESOURCES METHODS # |
| 41 | +# APP METADATA METHODS # |
117 | 42 | ############################ |
118 | 43 |
|
119 | 44 | def create_catalog(): |
@@ -158,8 +83,8 @@ def create_dataApp(): |
158 | 83 | "title": "DataApp Information", |
159 | 84 | "description": "This is the dataApp information for the DataProcessingApp.", |
160 | 85 | "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", |
163 | 88 | "supportedUsagePolicies": [ |
164 | 89 | "PROVIDE_ACCESS" |
165 | 90 | ] |
@@ -244,6 +169,10 @@ def create_rule_allow_access(): |
244 | 169 | loc = post_request_check_response(f"{combined_host}/api/rules", json) |
245 | 170 | return loc |
246 | 171 |
|
| 172 | +########################################################################## |
| 173 | +# USUALLY, IT SHOULD NOT BE NECESSARY TO CHANGE ANYTHING BELOW THIS LINE # |
| 174 | +########################################################################## |
| 175 | + |
247 | 176 |
|
248 | 177 | ############################# |
249 | 178 | # LINKING RESOURCES METHODS # |
@@ -287,7 +216,82 @@ def add_contract_to_resource(resource, contract): |
287 | 216 | def add_rule_to_contract(contract, rule): |
288 | 217 | link_two_resources(contract, rule) |
289 | 218 |
|
| 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!") |
290 | 293 |
|
| 294 | + |
291 | 295 | ################# |
292 | 296 | # DOCKER METHOD # |
293 | 297 | ################# |
@@ -382,7 +386,7 @@ def tag_image_for_registry(image_tmp, resource_id_tmp, resource_version_tmp, reg |
382 | 386 | # Tag image |
383 | 387 | tagged = image_tmp.tag(complete_tag) |
384 | 388 | 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}") |
386 | 390 | return complete_tag |
387 | 391 | else: |
388 | 392 | raise Exception("Failed to tag image.") |
|
0 commit comments