oc-cdtapi 3.18.3__py3-none-any.whl → 3.19.2__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,348 @@
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_ci_type_by_code(self, request):
15
+ """
16
+ Retrieve a list of ci type based on the provided ci type code.
17
+
18
+ This function queries the ci database and returns a ci type
19
+ that match the specified code in the request.
20
+
21
+ Args:
22
+ code (string): A code containing search parameters. For example:
23
+ NSDC
24
+
25
+ Returns:
26
+ dict: A dict of citype object matching the search criteria.
27
+
28
+ Example:
29
+ >>> request = 'NSDC'
30
+ >>> citype = get_ci_type_by_code(request)
31
+ >>> print(citype)
32
+ {
33
+ "code": "NSDC",
34
+ "doc_artifactid": null,
35
+ "is_deliverable": false,
36
+ "is_standard": "N",
37
+ "name": "NetServer distribution component",
38
+ "rn_artifactid": null
39
+ }
40
+ """
41
+ req = f"rest/api/1/citype/{request}"
42
+ res = self.get(req)
43
+ logging.debug(f'Using get_ci_type_by_code to get information about citype with code {request}')
44
+
45
+ return res.json()
46
+
47
+ def get_deliveries(self, request):
48
+ """
49
+ Retrieve a list of deliveries based on the provided search criteria.
50
+
51
+ This function queries the delivery database and returns a list of deliveries
52
+ that match the specified parameters in the request.
53
+
54
+ Args:
55
+ request (dict): A dictionary containing search parameters. For example:
56
+ {
57
+ 'gav': 'somegav',
58
+ 'flag_approved': True
59
+ }
60
+
61
+ Returns:
62
+ list: A list of delivery objects matching the search criteria.
63
+
64
+ Example:
65
+ >>> request = {'gav': 'group:artifact:version', 'flag_approved': True}
66
+ >>> deliveries = get_delivery(request)
67
+ >>> print(deliveries)
68
+ [Delivery1, Delivery2, ...]
69
+ """
70
+ req = f"rest/api/1/deliveries"
71
+ res = self.get(req, params=request)
72
+ logging.debug(f'Using get_delivery_by_gav to get information about delivery with {request}')
73
+
74
+ return res.json()
75
+
76
+ def get_historicaldelivery(self, request):
77
+ """
78
+ Retrieve a list of historicaldelivery based on the provided search criteria.
79
+
80
+ This function queries the delivery database and returns a list of deliveries
81
+ that match the specified parameters in the request.
82
+
83
+ Args:
84
+ request (dict): A dictionary containing search parameters. For example:
85
+ {
86
+ 'gav': 'somegav',
87
+ 'flag_approved': True
88
+ }
89
+
90
+ Returns:
91
+ list: A list of delivery objects matching the search criteria.
92
+
93
+ Example:
94
+ >>> request = {'gav': 'group:artifact:version', 'flag_approved': True}
95
+ >>> historicaldeliveries = get_historicaldelivery(request)
96
+ >>> print(historicaldeliveries)
97
+ [HistoricalDelivery1, HistoricalDelivery1, ...]
98
+ """
99
+ req = f"rest/api/1/historicaldeliveries"
100
+ res = self.get(req, params=request)
101
+ logging.debug(f'Using get_historicaldelivery to get information about {request}')
102
+
103
+ return res.json()
104
+
105
+ def update_delivery_by_gav(self, gav, json):
106
+ """
107
+ Update delivery information for a specific GAV (Group:Artifact:Version).
108
+
109
+ This method sends a PUT request to update the delivery information
110
+ associated with the provided GAV.
111
+
112
+ Args:
113
+ gav (str): The GAV (Group:Artifact:Version) identifier of the delivery to update.
114
+ json (dict): A dictionary containing the updated delivery information.
115
+
116
+ Returns:
117
+ requests.Response: The response object from the API call.
118
+
119
+ Example:
120
+ >>> gav = "com.example:artifact:1.0.0"
121
+ >>> update_data = {"status": "approved", "version": "1.0.1"}
122
+ >>> response = api.update_delivery_by_gav(gav, update_data)
123
+ >>> print(response.status_code)
124
+ 200
125
+ """
126
+ payload = {"gav": gav}
127
+ req = f"rest/api/1/deliveries"
128
+ res = self.put(req, json=json, params=payload)
129
+ logging.debug(f'Using put_delivery to update information about {gav}')
130
+
131
+ return res
132
+
133
+ def post_historicaldelivery(self, request):
134
+ """
135
+ Create a new historical delivery entry.
136
+
137
+ This method sends a POST request to create a new historical delivery
138
+ record with the provided information.
139
+
140
+ Args:
141
+ request (dict): A dictionary containing the historical delivery information to be created.
142
+
143
+ Returns:
144
+ dict: The JSON response from the API, typically containing the created historical delivery information.
145
+
146
+ Example:
147
+ >>> new_delivery = {
148
+ ... "gav": "com.example:artifact:1.0.0",
149
+ ... "timestamp": "2023-04-01T12:00:00Z",
150
+ ... "status": "delivered"
151
+ ... }
152
+ >>> result = api.post_historicaldelivery(new_delivery)
153
+ >>> print(result['id'])
154
+ 12345
155
+ """
156
+ req = f"rest/api/1/historicaldeliveries"
157
+ res = self.post(req, json=request)
158
+ logging.debug(f'Using post_historicaldelivery to create information')
159
+
160
+ return res
161
+
162
+ def post_tasks(self, request):
163
+ """
164
+ Create a new tasks entry.
165
+
166
+ This method sends a POST request to create a new tasks
167
+ record with the provided information.
168
+
169
+ Args:
170
+ request (dict): A dictionary containing the tasks information to be inserted.
171
+
172
+ Returns:
173
+ requests.Response: The response object from the API call.
174
+
175
+ Example:
176
+ >>> tasks = {
177
+ ... "status": "Completed",
178
+ ... "action_code": "create",
179
+ ... "commentary": "",
180
+ ... "task_content": {
181
+ ... "hardware": {
182
+ ... "memory_mb": 5120
183
+ ... },
184
+ ... "name": "hostname",
185
+ ... "username": "username"
186
+ ... },
187
+ ... "jira_verification_ticket": "ticket_id",
188
+ ... "status_desc": "status"
189
+ }
190
+ >>> result = api.post_tasks(tasks)
191
+ >>> print(result.status_code)
192
+ 201
193
+ """
194
+ req = f"rest/api/1/tasks"
195
+ res = self.post(req, json=request)
196
+
197
+ return res
198
+
199
+ def update_task(self, task_id, request):
200
+ """
201
+ Create a new tasks entry.
202
+
203
+ This method sends a POST request to create a new tasks
204
+ record with the provided information.
205
+
206
+ Args:
207
+ request (dict): A dictionary containing the tasks information to be inserted.
208
+
209
+ Returns:
210
+ requests.Response: The response object from the API call.
211
+
212
+ Example:
213
+ >>> task_id = 2
214
+ >>> tasks = {
215
+ ... "status": "Completed",
216
+ ... "action_code": "create",
217
+ ... "commentary": "",
218
+ ... "task_content": {
219
+ ... "hardware": {
220
+ ... "memory_mb": 5120
221
+ ... },
222
+ ... "name": "hostname",
223
+ ... "username": "username"
224
+ ... },
225
+ ... "jira_verification_ticket": "ticket_id",
226
+ ... "status_desc": "status"
227
+ }
228
+ >>> result = api.update_task(tasks)
229
+ >>> print(result.status_code)
230
+ 200
231
+ """
232
+ req = f"rest/api/1/tasks/{task_id}"
233
+ res = self.put(req, json=request)
234
+
235
+ return res
236
+
237
+ def get_task_by_id(self, task_id):
238
+ """
239
+ Get a task by id.
240
+
241
+ This method sends a GET request to get a task by desired id.
242
+
243
+ Args:
244
+ task_id (int): An integer of the task id.
245
+
246
+ Returns:
247
+ requests.Response: The response object from the API call.
248
+
249
+ Example:
250
+ >>> task_id = 2
251
+ >>> result = api.get_task_by_id(task_id)
252
+ >>> print(result.status_code)
253
+ 200
254
+ """
255
+ try:
256
+ payload = {"id": task_id}
257
+ req = f"rest/api/1/tasks"
258
+ res = self.get(req, params=payload)
259
+ except HttpAPIError as e:
260
+ if e.code == 404:
261
+ return None
262
+ else:
263
+ raise HttpAPIError(e)
264
+
265
+ return res.json()[0]
266
+
267
+ def get_task_by_id_and_username(self, task_id, username):
268
+ """
269
+ Get a task by id and username.
270
+
271
+ This method sends a GET request to get a task by desired id.
272
+
273
+ Args:
274
+ task_id (int): An integer of the task id.
275
+
276
+ Returns:
277
+ requests.Response: The response object from the API call.
278
+
279
+ Example:
280
+ >>> task_id = 2
281
+ >>> result = api.get_task_by_id(task_id)
282
+ >>> print(result.status_code)
283
+ 200
284
+ """
285
+ try:
286
+ payload = {"id": task_id, "username": username}
287
+ req = f"rest/api/1/tasks"
288
+ res = self.get(req, params=payload)
289
+ except HttpAPIError as e:
290
+ if e.code == 404:
291
+ return None
292
+ else:
293
+ raise HttpAPIError(e)
294
+
295
+ return res.json()[0]
296
+
297
+ def get_task_custom_filter(self, **kwargs):
298
+ """
299
+ Get a task by custom filter.
300
+
301
+ This method sends a GET request to get a task by custom filter.
302
+
303
+ Args:
304
+ **kwargs : Keyword arguments for filtering.
305
+
306
+ Returns:
307
+ requests.Response: The response object from the API call.
308
+
309
+ Example:
310
+ >>> task_id = 2
311
+ >>> param = {"id": 1, "hostname": "test.com"}
312
+ >>> result = api.get_task_custom_filter(**param)
313
+ >>> print(result.status_code)
314
+ 200
315
+ """
316
+ try:
317
+ req = f"rest/api/1/tasks"
318
+ res = self.get(req, params=kwargs)
319
+ except HttpAPIError as e:
320
+ if e.code == 404:
321
+ return []
322
+ else:
323
+ raise HttpAPIError(e)
324
+
325
+ return res.json()
326
+
327
+ def get_client_by_code(self, code):
328
+ """
329
+ Get a client by code.
330
+
331
+ This method sends a GET request to get a client including the ftp upload option by code.
332
+
333
+ Args:
334
+ code : Client code.
335
+
336
+ Returns:
337
+ requests.Response: The response object from the API call.
338
+
339
+ Example:
340
+ >>> code = 2
341
+ >>> result = self.get_client_by_code(code)
342
+ >>> print(result.status_code)
343
+ 200
344
+ """
345
+ req = f"rest/api/1/clients/{code}"
346
+ res = self.get(req)
347
+
348
+ 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.2
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=Mm1wXrXGGY2MMnrF9HdFoxpZT7uMMyP3WnF8zyZcYlc,11194
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.2.data/scripts/nexus.py,sha256=4teqZ_KtCSrwHDJVgA7lkreteod4Xt5XJFZNbwb7E6E,6858
15
+ oc_cdtapi-3.19.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
16
+ oc_cdtapi-3.19.2.dist-info/METADATA,sha256=RD2npG_1I_X5lEl2k5nym2um12nl6rnqD-my3GDgLCs,484
17
+ oc_cdtapi-3.19.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
18
+ oc_cdtapi-3.19.2.dist-info/top_level.txt,sha256=d4-5-D-0CSeSXYuLCP7-nIFCpjkfmJr-Y_muzds8iVU,10
19
+ oc_cdtapi-3.19.2.dist-info/RECORD,,