oc-cdtapi 3.18.3__py3-none-any.whl → 3.19.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
oc_cdtapi/PgAPI.py ADDED
@@ -0,0 +1,404 @@
1
+ import logging
2
+ import os
3
+
4
+ from oc_cdtapi import API
5
+ from oc_cdtapi.API import HttpAPIError
6
+
7
+
8
+ class PostgresAPI(API.HttpAPI):
9
+ _env_prefix = 'PSQL'
10
+ _env_token = 'TOKEN'
11
+ def __init__(self, *args, **kwargs):
12
+ super().__init__(*args, **kwargs)
13
+
14
+ def get_citypedms_by_citype_id(self, citype):
15
+ """
16
+ Retrieve citypedms information for a given CI type ID.
17
+
18
+ This method fetches a list of citypedms entries containing id, ci_type_id,
19
+ dms_id, and gav_template for the specified CI type ID.
20
+
21
+ Args:
22
+ citype (str): The CI type ID to query.
23
+
24
+ Returns:
25
+ dict: A dictionary containing citypedms information with the following keys:
26
+ - id: The citypedms entry ID
27
+ - ci_type_id: The CI type ID
28
+ - dms_id: The DMS ID
29
+ - gav_template: The GAV (Group:Artifact:Version) template
30
+
31
+ Example:
32
+ >>> citypedms = api.get_citypedms_by_citype_id("CI123")
33
+ >>> print(citypedms['id'])
34
+ 'CP456'
35
+ """
36
+ req = f"rest/api/1/citypedms/{citype}"
37
+ res = self.get(req).json()
38
+ logging.debug(f'Using get_citypedms_by_citype_id to get information about {citype}')
39
+
40
+ return res
41
+
42
+ def get_citypedms_by_dms_id(self, dms_id):
43
+ """
44
+ Retrieve citypedms information for a given DMS ID.
45
+
46
+ This method fetches a list of citypedms entries containing id, ci_type_id,
47
+ dms_id, and gav_template for the specified DMS ID (component ID).
48
+
49
+ Args:
50
+ dms_id (str): The DMS ID (component ID) to query.
51
+
52
+ Returns:
53
+ dict: A dictionary containing citypedms information with the following keys:
54
+ - id: The citypedms entry ID
55
+ - ci_type_id: The CI type ID
56
+ - dms_id: The DMS ID
57
+ - gav_template: The GAV (Group:Artifact:Version) template
58
+
59
+ Example:
60
+ >>> citypedms = api.get_citypedms_by_dms_id("DMS789")
61
+ >>> print(citypedms['gav_template'])
62
+ 'com.example:{artifact}:{version}'
63
+ """
64
+ req = f"rest/api/1/citypedms/{dms_id}?bycomponent=True"
65
+ res = self.get(req)
66
+ logging.debug(f'Using get_citypedms_by_dms_id to get information about {dms_id}')
67
+
68
+ return res.json()
69
+
70
+ def get_ci_type_by_code(self, request):
71
+ """
72
+ Retrieve a list of ci type based on the provided ci type code.
73
+
74
+ This function queries the ci database and returns a ci type
75
+ that match the specified code in the request.
76
+
77
+ Args:
78
+ code (string): A code containing search parameters. For example:
79
+ NSDC
80
+
81
+ Returns:
82
+ dict: A dict of citype object matching the search criteria.
83
+
84
+ Example:
85
+ >>> request = 'NSDC'
86
+ >>> citype = get_ci_type_by_code(request)
87
+ >>> print(citype)
88
+ {
89
+ "code": "NSDC",
90
+ "doc_artifactid": null,
91
+ "is_deliverable": false,
92
+ "is_standard": "N",
93
+ "name": "NetServer distribution component",
94
+ "rn_artifactid": null
95
+ }
96
+ """
97
+ req = f"rest/api/1/citype/{request}"
98
+ res = self.get(req)
99
+ logging.debug(f'Using get_ci_type_by_code to get information about citype with code {request}')
100
+
101
+ return res.json()
102
+
103
+ def get_deliveries(self, request):
104
+ """
105
+ Retrieve a list of deliveries based on the provided search criteria.
106
+
107
+ This function queries the delivery database and returns a list of deliveries
108
+ that match the specified parameters in the request.
109
+
110
+ Args:
111
+ request (dict): A dictionary containing search parameters. For example:
112
+ {
113
+ 'gav': 'somegav',
114
+ 'flag_approved': True
115
+ }
116
+
117
+ Returns:
118
+ list: A list of delivery objects matching the search criteria.
119
+
120
+ Example:
121
+ >>> request = {'gav': 'group:artifact:version', 'flag_approved': True}
122
+ >>> deliveries = get_delivery(request)
123
+ >>> print(deliveries)
124
+ [Delivery1, Delivery2, ...]
125
+ """
126
+ req = f"rest/api/1/deliveries"
127
+ res = self.get(req, params=request)
128
+ logging.debug(f'Using get_delivery_by_gav to get information about delivery with {request}')
129
+
130
+ return res.json()
131
+
132
+ def get_historicaldelivery(self, request):
133
+ """
134
+ Retrieve a list of historicaldelivery based on the provided search criteria.
135
+
136
+ This function queries the delivery database and returns a list of deliveries
137
+ that match the specified parameters in the request.
138
+
139
+ Args:
140
+ request (dict): A dictionary containing search parameters. For example:
141
+ {
142
+ 'gav': 'somegav',
143
+ 'flag_approved': True
144
+ }
145
+
146
+ Returns:
147
+ list: A list of delivery objects matching the search criteria.
148
+
149
+ Example:
150
+ >>> request = {'gav': 'group:artifact:version', 'flag_approved': True}
151
+ >>> historicaldeliveries = get_historicaldelivery(request)
152
+ >>> print(historicaldeliveries)
153
+ [HistoricalDelivery1, HistoricalDelivery1, ...]
154
+ """
155
+ req = f"rest/api/1/historicaldeliveries"
156
+ res = self.get(req, params=request)
157
+ logging.debug(f'Using get_historicaldelivery to get information about {request}')
158
+
159
+ return res.json()
160
+
161
+ def update_delivery_by_gav(self, gav, json):
162
+ """
163
+ Update delivery information for a specific GAV (Group:Artifact:Version).
164
+
165
+ This method sends a PUT request to update the delivery information
166
+ associated with the provided GAV.
167
+
168
+ Args:
169
+ gav (str): The GAV (Group:Artifact:Version) identifier of the delivery to update.
170
+ json (dict): A dictionary containing the updated delivery information.
171
+
172
+ Returns:
173
+ requests.Response: The response object from the API call.
174
+
175
+ Example:
176
+ >>> gav = "com.example:artifact:1.0.0"
177
+ >>> update_data = {"status": "approved", "version": "1.0.1"}
178
+ >>> response = api.update_delivery_by_gav(gav, update_data)
179
+ >>> print(response.status_code)
180
+ 200
181
+ """
182
+ payload = {"gav": gav}
183
+ req = f"rest/api/1/deliveries"
184
+ res = self.put(req, json=json, params=payload)
185
+ logging.debug(f'Using put_delivery to update information about {gav}')
186
+
187
+ return res
188
+
189
+ def post_historicaldelivery(self, request):
190
+ """
191
+ Create a new historical delivery entry.
192
+
193
+ This method sends a POST request to create a new historical delivery
194
+ record with the provided information.
195
+
196
+ Args:
197
+ request (dict): A dictionary containing the historical delivery information to be created.
198
+
199
+ Returns:
200
+ dict: The JSON response from the API, typically containing the created historical delivery information.
201
+
202
+ Example:
203
+ >>> new_delivery = {
204
+ ... "gav": "com.example:artifact:1.0.0",
205
+ ... "timestamp": "2023-04-01T12:00:00Z",
206
+ ... "status": "delivered"
207
+ ... }
208
+ >>> result = api.post_historicaldelivery(new_delivery)
209
+ >>> print(result['id'])
210
+ 12345
211
+ """
212
+ req = f"rest/api/1/historicaldeliveries"
213
+ res = self.post(req, json=request)
214
+ logging.debug(f'Using post_historicaldelivery to create information')
215
+
216
+ return res
217
+
218
+ def post_tasks(self, request):
219
+ """
220
+ Create a new tasks entry.
221
+
222
+ This method sends a POST request to create a new tasks
223
+ record with the provided information.
224
+
225
+ Args:
226
+ request (dict): A dictionary containing the tasks information to be inserted.
227
+
228
+ Returns:
229
+ requests.Response: The response object from the API call.
230
+
231
+ Example:
232
+ >>> tasks = {
233
+ ... "status": "Completed",
234
+ ... "action_code": "create",
235
+ ... "commentary": "",
236
+ ... "task_content": {
237
+ ... "hardware": {
238
+ ... "memory_mb": 5120
239
+ ... },
240
+ ... "name": "hostname",
241
+ ... "username": "username"
242
+ ... },
243
+ ... "jira_verification_ticket": "ticket_id",
244
+ ... "status_desc": "status"
245
+ }
246
+ >>> result = api.post_tasks(tasks)
247
+ >>> print(result.status_code)
248
+ 201
249
+ """
250
+ req = f"rest/api/1/tasks"
251
+ res = self.post(req, json=request)
252
+
253
+ return res
254
+
255
+ def update_task(self, task_id, request):
256
+ """
257
+ Create a new tasks entry.
258
+
259
+ This method sends a POST request to create a new tasks
260
+ record with the provided information.
261
+
262
+ Args:
263
+ request (dict): A dictionary containing the tasks information to be inserted.
264
+
265
+ Returns:
266
+ requests.Response: The response object from the API call.
267
+
268
+ Example:
269
+ >>> task_id = 2
270
+ >>> tasks = {
271
+ ... "status": "Completed",
272
+ ... "action_code": "create",
273
+ ... "commentary": "",
274
+ ... "task_content": {
275
+ ... "hardware": {
276
+ ... "memory_mb": 5120
277
+ ... },
278
+ ... "name": "hostname",
279
+ ... "username": "username"
280
+ ... },
281
+ ... "jira_verification_ticket": "ticket_id",
282
+ ... "status_desc": "status"
283
+ }
284
+ >>> result = api.update_task(tasks)
285
+ >>> print(result.status_code)
286
+ 200
287
+ """
288
+ req = f"rest/api/1/tasks/{task_id}"
289
+ res = self.put(req, json=request)
290
+
291
+ return res
292
+
293
+ def get_task_by_id(self, task_id):
294
+ """
295
+ Get a task by id.
296
+
297
+ This method sends a GET request to get a task by desired id.
298
+
299
+ Args:
300
+ task_id (int): An integer of the task id.
301
+
302
+ Returns:
303
+ requests.Response: The response object from the API call.
304
+
305
+ Example:
306
+ >>> task_id = 2
307
+ >>> result = api.get_task_by_id(task_id)
308
+ >>> print(result.status_code)
309
+ 200
310
+ """
311
+ try:
312
+ payload = {"id": task_id}
313
+ req = f"rest/api/1/tasks"
314
+ res = self.get(req, params=payload)
315
+ except HttpAPIError as e:
316
+ if e.code == 404:
317
+ return None
318
+ else:
319
+ raise HttpAPIError(e)
320
+
321
+ return res.json()[0]
322
+
323
+ def get_task_by_id_and_username(self, task_id, username):
324
+ """
325
+ Get a task by id and username.
326
+
327
+ This method sends a GET request to get a task by desired id.
328
+
329
+ Args:
330
+ task_id (int): An integer of the task id.
331
+
332
+ Returns:
333
+ requests.Response: The response object from the API call.
334
+
335
+ Example:
336
+ >>> task_id = 2
337
+ >>> result = api.get_task_by_id(task_id)
338
+ >>> print(result.status_code)
339
+ 200
340
+ """
341
+ try:
342
+ payload = {"id": task_id, "username": username}
343
+ req = f"rest/api/1/tasks"
344
+ res = self.get(req, params=payload)
345
+ except HttpAPIError as e:
346
+ if e.code == 404:
347
+ return None
348
+ else:
349
+ raise HttpAPIError(e)
350
+
351
+ return res.json()[0]
352
+
353
+ def get_task_custom_filter(self, **kwargs):
354
+ """
355
+ Get a task by custom filter.
356
+
357
+ This method sends a GET request to get a task by custom filter.
358
+
359
+ Args:
360
+ **kwargs : Keyword arguments for filtering.
361
+
362
+ Returns:
363
+ requests.Response: The response object from the API call.
364
+
365
+ Example:
366
+ >>> task_id = 2
367
+ >>> param = {"id": 1, "hostname": "test.com"}
368
+ >>> result = api.get_task_custom_filter(**param)
369
+ >>> print(result.status_code)
370
+ 200
371
+ """
372
+ try:
373
+ req = f"rest/api/1/tasks"
374
+ res = self.get(req, params=kwargs)
375
+ except HttpAPIError as e:
376
+ if e.code == 404:
377
+ return []
378
+ else:
379
+ raise HttpAPIError(e)
380
+
381
+ return res.json()
382
+
383
+ def get_client_by_code(self, code):
384
+ """
385
+ Get a client by code.
386
+
387
+ This method sends a GET request to get a client including the ftp upload option by code.
388
+
389
+ Args:
390
+ code : Client code.
391
+
392
+ Returns:
393
+ requests.Response: The response object from the API call.
394
+
395
+ Example:
396
+ >>> code = 2
397
+ >>> result = self.get_client_by_code(code)
398
+ >>> print(result.status_code)
399
+ 200
400
+ """
401
+ req = f"rest/api/1/clients/{code}"
402
+ res = self.get(req)
403
+
404
+ return res.json()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oc-cdtapi
3
- Version: 3.18.3
3
+ Version: 3.19.3
4
4
  Summary: Custom Development python API libraries
5
5
  License: Apache2.0
6
6
  Requires-Python: >=3.6
@@ -6,13 +6,14 @@ oc_cdtapi/DmsGetverAPI.py,sha256=ZPU4HlF59fngKu5mSFhtss3rlBuduffDOSm_y3XWrxk,155
6
6
  oc_cdtapi/ForemanAPI.py,sha256=9r1MSOsubiSxM1sdzF2MHD7IcSwX9Y4UDJknHqQK07g,44255
7
7
  oc_cdtapi/JenkinsAPI.py,sha256=lZ8pe3a4eb_6h53JE7QLuzOSlu7Sqatc9PQwWhio9Vg,15748
8
8
  oc_cdtapi/NexusAPI.py,sha256=uU12GtHvKlWorFaPAnFcQ5AGEc94MZ5SdmfM2Pw3F7A,26122
9
+ oc_cdtapi/PgAPI.py,sha256=9VQBDHvXupOQEo06OjBjacVrCQJ5eNE29epabQXgIfU,13256
9
10
  oc_cdtapi/PgQAPI.py,sha256=ofcoS3J5CWN3EtwxW6EcuFUbNQH2BHAJkjrNSfwJ98o,8612
10
11
  oc_cdtapi/RundeckAPI.py,sha256=O3LmcFaHSz8UqeUyIHTTEMJncDD191Utd-iZaeJay2s,24243
11
12
  oc_cdtapi/TestServer.py,sha256=HV97UWg2IK4gOYAp9yaMdwFUWsw9v66MxyZdI3qQctA,2715
12
13
  oc_cdtapi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- oc_cdtapi-3.18.3.data/scripts/nexus.py,sha256=4teqZ_KtCSrwHDJVgA7lkreteod4Xt5XJFZNbwb7E6E,6858
14
- oc_cdtapi-3.18.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
15
- oc_cdtapi-3.18.3.dist-info/METADATA,sha256=3DStNGs__RNS6M5KQBwsWEVfQHPIlPhT8NuyAGd4M48,484
16
- oc_cdtapi-3.18.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
- oc_cdtapi-3.18.3.dist-info/top_level.txt,sha256=d4-5-D-0CSeSXYuLCP7-nIFCpjkfmJr-Y_muzds8iVU,10
18
- oc_cdtapi-3.18.3.dist-info/RECORD,,
14
+ oc_cdtapi-3.19.3.data/scripts/nexus.py,sha256=4teqZ_KtCSrwHDJVgA7lkreteod4Xt5XJFZNbwb7E6E,6858
15
+ oc_cdtapi-3.19.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
16
+ oc_cdtapi-3.19.3.dist-info/METADATA,sha256=-QyiiGPr2WUm536lYuOBSMmJhamOcTBDvT60YRDeMz4,484
17
+ oc_cdtapi-3.19.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
18
+ oc_cdtapi-3.19.3.dist-info/top_level.txt,sha256=d4-5-D-0CSeSXYuLCP7-nIFCpjkfmJr-Y_muzds8iVU,10
19
+ oc_cdtapi-3.19.3.dist-info/RECORD,,