csc-cia-stne 0.1.10__py3-none-any.whl → 0.1.11__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.
- csc_cia_stne/servicenow.py +10 -34
- csc_cia_stne/utilitarios/__init__.py +5 -1
- csc_cia_stne/utilitarios/functions/__init__.py +5 -0
- csc_cia_stne/utilitarios/functions/func_delete.py +96 -0
- csc_cia_stne/utilitarios/functions/func_validate_json.py +49 -0
- {csc_cia_stne-0.1.10.dist-info → csc_cia_stne-0.1.11.dist-info}/METADATA +1 -1
- {csc_cia_stne-0.1.10.dist-info → csc_cia_stne-0.1.11.dist-info}/RECORD +10 -8
- {csc_cia_stne-0.1.10.dist-info → csc_cia_stne-0.1.11.dist-info}/WHEEL +0 -0
- {csc_cia_stne-0.1.10.dist-info → csc_cia_stne-0.1.11.dist-info}/licenses/LICENCE +0 -0
- {csc_cia_stne-0.1.10.dist-info → csc_cia_stne-0.1.11.dist-info}/top_level.txt +0 -0
csc_cia_stne/servicenow.py
CHANGED
@@ -139,7 +139,7 @@ class ServiceNow:
|
|
139
139
|
logging.debug(f"Erro inesperado: {e}")
|
140
140
|
return {"success": False, "result": None, "error": str(e)}
|
141
141
|
|
142
|
-
def __request_download(self, url, params="", timeout=15):
|
142
|
+
def __request_download(self, url: str, params: str="", timeout: int=15):
|
143
143
|
"""
|
144
144
|
Realiza uma requisição GET para a URL especificada.
|
145
145
|
|
@@ -199,7 +199,7 @@ class ServiceNow:
|
|
199
199
|
logging.debug(f"Erro inesperado: {e}")
|
200
200
|
return {"success": False, "error": str(e), "result": None}
|
201
201
|
|
202
|
-
def put(self, url, payload, timeout=15):
|
202
|
+
def put(self, url: str, payload: dict, timeout: int = 15):
|
203
203
|
"""
|
204
204
|
Realiza uma requisição PUT para a URL especificada.
|
205
205
|
|
@@ -251,17 +251,7 @@ class ServiceNow:
|
|
251
251
|
|
252
252
|
# POSSUINDO 'RESULT', TEREMOS O RETORNO DO TICKET ABERTO.
|
253
253
|
result = response.json()
|
254
|
-
if "result" in result:
|
255
|
-
update = result["result"]
|
256
|
-
logging.debug(
|
257
|
-
f"Atualização concluída com sucesso. Registro atualizado: {update['sys_id']} | Alterações: {payload}"
|
258
|
-
)
|
259
|
-
return {"success": True, "result": update}
|
260
|
-
else:
|
261
|
-
logging.debug(
|
262
|
-
f"A Resposta da sua requisição não contém o campo 'Result'. Segue o retorno: \n {result} | Alterações: {payload}"
|
263
|
-
)
|
264
|
-
return {"success": False, "result": result}
|
254
|
+
return {"success": True, "result": result["result"], "error": None} if "result" in result else {"success": False, "result": result, "error": None}
|
265
255
|
|
266
256
|
# TRATAMENTOS DE ERRO
|
267
257
|
except requests.exceptions.HTTPError as http_err:
|
@@ -279,7 +269,7 @@ class ServiceNow:
|
|
279
269
|
return {"success": False, "error": str(e), "result": None}
|
280
270
|
|
281
271
|
def post(
|
282
|
-
self, url: str,
|
272
|
+
self, url: str, payload: dict, header_content_type="", timeout: int = 15
|
283
273
|
):
|
284
274
|
"""
|
285
275
|
Função para criar um novo ticket no servicenow usando o API REST.
|
@@ -293,7 +283,7 @@ class ServiceNow:
|
|
293
283
|
|
294
284
|
"""
|
295
285
|
try:
|
296
|
-
PostValidator(url=url, variables=
|
286
|
+
PostValidator(url=url, variables=payload)
|
297
287
|
except ValidationError as e:
|
298
288
|
raise ValueError(
|
299
289
|
"Erro na validação dos dados de input do método:", e.errors()
|
@@ -303,15 +293,12 @@ class ServiceNow:
|
|
303
293
|
header = header_content_type
|
304
294
|
else:
|
305
295
|
header = self.api_header
|
306
|
-
|
307
|
-
# Ajustar o Payload para a abertura do ticket
|
308
|
-
payload = {"sysparm_quantity": "1", "variables": json.dumps(variables)}
|
309
296
|
try:
|
310
297
|
response = requests.post(
|
311
|
-
|
298
|
+
url,
|
312
299
|
auth=self.__auth(),
|
313
300
|
headers=header,
|
314
|
-
|
301
|
+
json=payload,
|
315
302
|
timeout=timeout,
|
316
303
|
)
|
317
304
|
|
@@ -320,18 +307,8 @@ class ServiceNow:
|
|
320
307
|
|
321
308
|
# POSSUINDO 'RESULT', TEREMOS O RETORNO DO TICKET ABERTO.
|
322
309
|
result = response.json()
|
323
|
-
if "result" in result:
|
324
|
-
|
325
|
-
ticket_sys_id = result["result"].get("sys_id")
|
326
|
-
logging.debug(
|
327
|
-
f"Ticket registrado com sucesso. Número: {ticket_number} | SYS_ID: {ticket_sys_id}"
|
328
|
-
)
|
329
|
-
return {"success": True, "result": result["result"]}
|
330
|
-
else:
|
331
|
-
logging.debug(
|
332
|
-
f"A Resposta da sua requisição não contém o campo 'Result'. Segue o retorno: \n {result}"
|
333
|
-
)
|
334
|
-
return {"success": False, "result": result}
|
310
|
+
return {"success": True, "result": result["result"], "error" : None} if "result" in result else {"success": False, "result": result, "error" : None}
|
311
|
+
|
335
312
|
|
336
313
|
# TRATAMENTOS DE ERRO
|
337
314
|
except requests.exceptions.HTTPError as http_err:
|
@@ -502,7 +479,7 @@ class ServiceNow:
|
|
502
479
|
)
|
503
480
|
|
504
481
|
logging.debug("Arquivo adicionado no ticket")
|
505
|
-
return {"success": True, "result": response}
|
482
|
+
return {"success": True, "result": response.json()}
|
506
483
|
|
507
484
|
except Exception as e:
|
508
485
|
return {"success": False, "result": None, "error": str(e)}
|
@@ -617,7 +594,6 @@ class ServiceNow:
|
|
617
594
|
try:
|
618
595
|
if not os.path.exists(file_path):
|
619
596
|
diretorio = os.path.dirname(file_path)
|
620
|
-
print(diretorio)
|
621
597
|
os.makedirs(diretorio, exist_ok=True)
|
622
598
|
logging.debug(f"Diretorio criado: {diretorio}")
|
623
599
|
with open(file_path, "wb") as f:
|
@@ -1,4 +1,5 @@
|
|
1
|
-
from .functions import titulo, recriar_pasta, b64encode, b64decode, convert_bquery_result_to_json,get_config, get_secret, now_sp
|
1
|
+
from .functions import titulo, recriar_pasta, b64encode, b64decode, convert_bquery_result_to_json,get_config, get_secret, now_sp, validate_json, delete_file, delete_folder
|
2
|
+
|
2
3
|
__all__ = [
|
3
4
|
"titulo",
|
4
5
|
"recriar_pasta",
|
@@ -8,4 +9,7 @@ __all__ = [
|
|
8
9
|
"get_config",
|
9
10
|
"get_secret",
|
10
11
|
"now_sp",
|
12
|
+
"delete_file",
|
13
|
+
"delete_folder",
|
14
|
+
"validate_json"
|
11
15
|
]
|
@@ -5,6 +5,8 @@ from .func_converters import convert_bquery_result_to_json
|
|
5
5
|
from .func_settings import get_config
|
6
6
|
from .func_get_secret import get_secret
|
7
7
|
from .func_datetime import now_sp
|
8
|
+
from .func_delete import delete_file, delete_folder
|
9
|
+
from .func_validate_json import validate_json
|
8
10
|
|
9
11
|
__all__ = [
|
10
12
|
"titulo",
|
@@ -15,4 +17,7 @@ __all__ = [
|
|
15
17
|
"get_config",
|
16
18
|
"get_secret",
|
17
19
|
"now_sp",
|
20
|
+
"delete_file",
|
21
|
+
"delete_folder",
|
22
|
+
"validate_json"
|
18
23
|
]
|
@@ -0,0 +1,96 @@
|
|
1
|
+
import os
|
2
|
+
import shutil
|
3
|
+
|
4
|
+
|
5
|
+
def delete_file(filename:str) -> bool:
|
6
|
+
"""
|
7
|
+
Exclui um arquivo no diretório atual com o nome especificado.
|
8
|
+
Parâmetros:
|
9
|
+
filename (str): O nome do arquivo a ser excluído.
|
10
|
+
Retorna:
|
11
|
+
dict: Um dicionário indicando o sucesso da operação.
|
12
|
+
- Se bem-sucedido: {"success": True}
|
13
|
+
- Se falhar: {"success": False, "error": <mensagem de erro>}
|
14
|
+
Possíveis mensagens de erro incluem:
|
15
|
+
- "Permissão negada."
|
16
|
+
- "Arquivo não encontrado."
|
17
|
+
- Mensagem de exceção genérica.
|
18
|
+
"""
|
19
|
+
|
20
|
+
filepath = os.path.join(os.getcwd(), filename)
|
21
|
+
|
22
|
+
if os.path.exists(filepath):
|
23
|
+
|
24
|
+
try:
|
25
|
+
os.remove(filepath)
|
26
|
+
|
27
|
+
return {
|
28
|
+
"success": True,
|
29
|
+
}
|
30
|
+
|
31
|
+
except PermissionError as e:
|
32
|
+
|
33
|
+
return {
|
34
|
+
"success": False,
|
35
|
+
"error": "Permissão negada.",
|
36
|
+
}
|
37
|
+
|
38
|
+
except Exception as e:
|
39
|
+
|
40
|
+
return {
|
41
|
+
"success": False,
|
42
|
+
"error": str(e),
|
43
|
+
}
|
44
|
+
|
45
|
+
else:
|
46
|
+
|
47
|
+
return {
|
48
|
+
"success": False,
|
49
|
+
"error": "Arquivo não encontrado."
|
50
|
+
}
|
51
|
+
|
52
|
+
def delete_folder(foldername:str):
|
53
|
+
"""
|
54
|
+
Exclui uma pasta especificada pelo nome.
|
55
|
+
Parâmetros:
|
56
|
+
foldername (str): O nome da pasta a ser excluída.
|
57
|
+
Retorna:
|
58
|
+
dict: Um dicionário indicando se a exclusão foi bem-sucedida.
|
59
|
+
- Se bem-sucedido: {"success": True}
|
60
|
+
- Se a pasta não for encontrada: {"success": False, "error": "Pasta não encontrada."}
|
61
|
+
- Se houver permissão negada: {"success": False, "error": "Permissão negada."}
|
62
|
+
- Para outros erros: {"success": False, "error": <mensagem do erro>}
|
63
|
+
"""
|
64
|
+
|
65
|
+
filepath = os.path.join(os.getcwd(), foldername)
|
66
|
+
|
67
|
+
if os.path.exists(filepath):
|
68
|
+
|
69
|
+
try:
|
70
|
+
|
71
|
+
shutil.rmtree(filepath)
|
72
|
+
|
73
|
+
return {
|
74
|
+
"success": True
|
75
|
+
}
|
76
|
+
|
77
|
+
except PermissionError as e:
|
78
|
+
|
79
|
+
return {
|
80
|
+
"success": False,
|
81
|
+
"error": "Permissão negada.",
|
82
|
+
}
|
83
|
+
|
84
|
+
except Exception as e:
|
85
|
+
|
86
|
+
return {
|
87
|
+
"success": False,
|
88
|
+
"error": str(e),
|
89
|
+
}
|
90
|
+
|
91
|
+
else:
|
92
|
+
|
93
|
+
return {
|
94
|
+
"success": False,
|
95
|
+
"error": "Pasta não encontrada."
|
96
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
|
4
|
+
def validate_json(token):
|
5
|
+
"""
|
6
|
+
Valida e converte uma string JSON em um objeto Python (dict ou list).
|
7
|
+
Parâmetros:
|
8
|
+
token (str, dict ou list): O JSON a ser validado, podendo ser uma string ou já um objeto Python.
|
9
|
+
Retorna:
|
10
|
+
dict: Um dicionário contendo:
|
11
|
+
- "success" (bool): Indica se a validação/conversão foi bem-sucedida.
|
12
|
+
- "data" (dict ou list, opcional): O objeto Python resultante, presente se o sucesso for True.
|
13
|
+
- "error" (Exception, opcional): A exceção capturada, presente se o sucesso for False.
|
14
|
+
Exemplo:
|
15
|
+
>>> validate_json('{"chave": "valor"}')
|
16
|
+
{'success': True, 'data': {'chave': 'valor'}}
|
17
|
+
"""
|
18
|
+
|
19
|
+
if not isinstance(token,dict) and not isinstance(token,list):
|
20
|
+
|
21
|
+
try:
|
22
|
+
|
23
|
+
token = json.loads(token)
|
24
|
+
|
25
|
+
return {
|
26
|
+
"success":True,
|
27
|
+
"data":token
|
28
|
+
}
|
29
|
+
|
30
|
+
except json.JSONDecodeError as e:
|
31
|
+
|
32
|
+
return {
|
33
|
+
"success":False,
|
34
|
+
"error":e
|
35
|
+
}
|
36
|
+
|
37
|
+
except Exception as e:
|
38
|
+
|
39
|
+
return {
|
40
|
+
"success":False,
|
41
|
+
"error":e
|
42
|
+
}
|
43
|
+
|
44
|
+
else:
|
45
|
+
|
46
|
+
return {
|
47
|
+
"success":True,
|
48
|
+
"data":token
|
49
|
+
}
|
@@ -10,20 +10,22 @@ csc_cia_stne/karavela.py,sha256=jJCYX43D49gGuzmwwK6bN9XVnv2dXdp9iHnnV5H1LMQ,4794
|
|
10
10
|
csc_cia_stne/logger_json.py,sha256=CXxSCOFGMymDi8XE9SKnPKjW4D0wJLqDLnxqePS26i8,3187
|
11
11
|
csc_cia_stne/logger_rich.py,sha256=fklgkBb4rblKQd7YZ3q-eWfhGg9eflO2k2-z4pGh_yo,5201
|
12
12
|
csc_cia_stne/provio.py,sha256=G-pDnHYLSp97joc7S7dvwjNvl3omnTmvdi3rOPQf5GA,3987
|
13
|
-
csc_cia_stne/servicenow.py,sha256=
|
13
|
+
csc_cia_stne/servicenow.py,sha256=PUGN6bjcQ25hf-bwVuuKsnRKdqYTaYZ1Uh7QHn9OM24,35350
|
14
14
|
csc_cia_stne/slack.py,sha256=sPLeaQh_JewLcrBDjjwUgbjtC7d1Np03OTy06JimMV4,8117
|
15
15
|
csc_cia_stne/stne_admin.py,sha256=4v_BVQAwZeWmxvjDOkwFAl9yIxJ3r54BY7pRgAgSXEM,24220
|
16
16
|
csc_cia_stne/wacess.py,sha256=g-bWZNpm_tU7UsW1G_rqh_2fW2KShvxZHGOerX8DuQw,26768
|
17
17
|
csc_cia_stne/web.py,sha256=TBXUJ5eS36fytU3oFDuJsogi0sgw_qKgK-uphx4Nvxo,2506
|
18
|
-
csc_cia_stne/utilitarios/__init__.py,sha256=
|
19
|
-
csc_cia_stne/utilitarios/functions/__init__.py,sha256=
|
18
|
+
csc_cia_stne/utilitarios/__init__.py,sha256=ul7p-4XduFOQW2ldKSIbTQb3eq7h5O1l8IwSP7b5KgY,410
|
19
|
+
csc_cia_stne/utilitarios/functions/__init__.py,sha256=1jKf5CbiBe5wRKu-npBe9AYqY8KybGbQXfHjZ8JR5wM,629
|
20
20
|
csc_cia_stne/utilitarios/functions/func_b64.py,sha256=XGU34BIQQXWXBS0yM2B4A2wDlcrMl1unIJXjq4lpLnk,1254
|
21
21
|
csc_cia_stne/utilitarios/functions/func_converters.py,sha256=EY1zvlBaRX7G1MceVSiRXwwKDQDZwUO9iECBL0fe5iU,481
|
22
22
|
csc_cia_stne/utilitarios/functions/func_datetime.py,sha256=UA7ch4sQWTiYcz8r6LtGujIdpTU-Sht8qmTYvm9vhh0,257
|
23
|
+
csc_cia_stne/utilitarios/functions/func_delete.py,sha256=o2h4leucTq5Cs0XxJ5aBzbRyuxusKXIoedn2tmxNp1E,2449
|
23
24
|
csc_cia_stne/utilitarios/functions/func_get_secret.py,sha256=XFsAd9GnKnf9WLnARqNG2fFg5h_JEOxbVvt_78VFYh4,2959
|
24
25
|
csc_cia_stne/utilitarios/functions/func_recriar_pastas.py,sha256=4whZpB3aJQaCPJ3osMAQpKrzEhqYtJbljGWlx_OvKIM,826
|
25
26
|
csc_cia_stne/utilitarios/functions/func_settings.py,sha256=XwlfqdcfocXQ8kTsDKZ6GsAtpzr0_u44AOTIMtdem7U,2059
|
26
27
|
csc_cia_stne/utilitarios/functions/func_titulo.py,sha256=bH4tYxovTARF-g2kWUK_GIzzXt8egbVdp6mWD6fc_3I,5345
|
28
|
+
csc_cia_stne/utilitarios/functions/func_validate_json.py,sha256=mAc2J5Eab8ZpNYqsDLJMKkKIeyrSbhytncdJ5G0jztA,1306
|
27
29
|
csc_cia_stne/utilitarios/validations/GcpBigQueryValidator.py,sha256=PfCeeQquheZkrm07HTIjobleh3QQOjljRFGdxbQ1amQ,4630
|
28
30
|
csc_cia_stne/utilitarios/validations/GoogleDriveValidator.py,sha256=Q1oZTae4hDJ2TQ4sUL5Q5TkDNPoJo-DZQt6wIue2jwM,4811
|
29
31
|
csc_cia_stne/utilitarios/validations/ServiceNowValidator.py,sha256=yleKUIo1ZfyloP9fDPNjv3JJXdLcocT81WIgRSYmqEA,14423
|
@@ -36,8 +38,8 @@ csc_cia_stne/utilitarios/web_screen/__init__.py,sha256=5QcOPXKd95SvP2DoZiHS0gaU6
|
|
36
38
|
csc_cia_stne/utilitarios/web_screen/web_screen_abstract.py,sha256=PjL8Vgfj_JdKidia7RFyCkro3avYLQu4RZRos41sh3w,3241
|
37
39
|
csc_cia_stne/utilitarios/web_screen/web_screen_botcity.py,sha256=Xi5YJjl2pcxlX3OimqcBWRNXZEpAE7asyUjDJ4Oho5U,12297
|
38
40
|
csc_cia_stne/utilitarios/web_screen/web_screen_selenium.py,sha256=JLIcPJE9ZX3Pd6zG6oTRMqqUAY063UzLY3ReRlxmiSM,15581
|
39
|
-
csc_cia_stne-0.1.
|
40
|
-
csc_cia_stne-0.1.
|
41
|
-
csc_cia_stne-0.1.
|
42
|
-
csc_cia_stne-0.1.
|
43
|
-
csc_cia_stne-0.1.
|
41
|
+
csc_cia_stne-0.1.11.dist-info/licenses/LICENCE,sha256=LPGMtgKki2C3KEZP7hDhA1HBrlq5JCHkIeStUCLEMx4,1073
|
42
|
+
csc_cia_stne-0.1.11.dist-info/METADATA,sha256=QKmQOPFva5ax0o61P-BH8zX7l9JAeAjgWLKOEb4YFg8,1464
|
43
|
+
csc_cia_stne-0.1.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
44
|
+
csc_cia_stne-0.1.11.dist-info/top_level.txt,sha256=ldo7GVv3tQx5KJvwBzdZzzQmjPys2NDVVn1rv0BOF2Q,13
|
45
|
+
csc_cia_stne-0.1.11.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|