lbxtoolkit 2.2.7__py3-none-any.whl → 2.2.8__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.
lbxtoolkit/api_rest.py
CHANGED
|
@@ -166,6 +166,56 @@ Para uso em APIs com autenticação JWT (JSON Web Token), OAuth, Bearer Token Au
|
|
|
166
166
|
return Err
|
|
167
167
|
#
|
|
168
168
|
#
|
|
169
|
+
def auth_token(self): # Autentica e abre sessão na API
|
|
170
|
+
if self.Credenciais['token']:
|
|
171
|
+
Token = self.Credenciais['token']
|
|
172
|
+
self.Headers.update({"UserAuthorization": f"token {Token}"})
|
|
173
|
+
else:
|
|
174
|
+
self.logger.critico(f'Falha de requisição api_rest.auth_token: Token não fornecido no dicionário de credenciais! Necessário informar chave da API em dicionário com chave "token" no instanciamento da classe', exit=1)
|
|
175
|
+
|
|
176
|
+
try:
|
|
177
|
+
self.Sessao = requests.Session()
|
|
178
|
+
Auth = self.Sessao.post(self.Url, headers=self.Headers, verify=self.Verify)
|
|
179
|
+
|
|
180
|
+
if 200 <= Auth.status_code <= 299:
|
|
181
|
+
self.Sessao.status_code = Auth.status_code
|
|
182
|
+
return self.Sessao
|
|
183
|
+
else:
|
|
184
|
+
self.logger.critico(f"Erro ao autenticar API: {self.Sessao.status_code} - {self.Sessao.text}")
|
|
185
|
+
raise Exception
|
|
186
|
+
except Exception as Err:
|
|
187
|
+
self.logger.critico(f"Falha ao autenticar API: {Err}. URL: {self.Url}")
|
|
188
|
+
return Err
|
|
189
|
+
#
|
|
190
|
+
#
|
|
191
|
+
def url_request(self, metodo, payload=None): # Efetua chamada diretamente à URL e não a EndPoint específico
|
|
192
|
+
self.ult_tempo_req = time()
|
|
193
|
+
self.Metodo = metodo.lower()
|
|
194
|
+
self.EndPoint = self.Url
|
|
195
|
+
self.Payload = payload
|
|
196
|
+
MetodosAceitos = ['post', 'get', 'patch', 'put']
|
|
197
|
+
if not any(element in self.Metodo for element in MetodosAceitos):
|
|
198
|
+
self.logger.critico(f'Método {self.Metodo} não previsto. Abortando chamada!', exit=1)
|
|
199
|
+
else:
|
|
200
|
+
ChamadaApi = f'self.Sessao.{self.Metodo}(self.Url, timeout=self.Timeout, headers=self.Headers, verify=self.Verify)' if self.Payload is None else f'self.Sessao.{self.Metodo}(self.Url, timeout=self.Timeout, headers=self.Headers, verify=self.Verify, data=self.Payload)'
|
|
201
|
+
self.controla_cadencia()
|
|
202
|
+
self.TempoUltReq = time()
|
|
203
|
+
try:
|
|
204
|
+
self.RetEndPoint = eval(ChamadaApi)
|
|
205
|
+
if self.RetEndPoint.status_code >= 500:
|
|
206
|
+
self.logger.critico(f'Erro [{self.RetEndPoint.status_code}] no lado servidor na resposta à requisição')
|
|
207
|
+
raise Exception
|
|
208
|
+
self.RetEndPoint.Espera = self.Espera ## adiona o tempo de espera ao retorno da API
|
|
209
|
+
self.RetEndPoint.Intervalo = self.Intervalo ## adiciona o intervalo entre chamada ao retorno da API
|
|
210
|
+
return self.RetEndPoint
|
|
211
|
+
except requests.exceptions.ReadTimeout as Err:
|
|
212
|
+
self.logger.critico(f'Excedido tempo limite {self.Timeout} para retorno do endpoint: {Err}\nEndpoint: {self.EndPoint}')
|
|
213
|
+
return Err
|
|
214
|
+
except Exception as Err:
|
|
215
|
+
self.logger.critico(f'Falha na chamada do endpoint: {Err}\nEndpoint: {self.EndPoint}\nCodigo retorno: {self.RetEndPoint.status_code}\nResposta:{self.RetEndPoint.text}')
|
|
216
|
+
return self.RetEndPoint
|
|
217
|
+
#
|
|
218
|
+
#
|
|
169
219
|
def endpoint_json(self, endpoint, metodo, payload=None): # Interage com End Point
|
|
170
220
|
self.ult_tempo_req = time()
|
|
171
221
|
self.Metodo = metodo.lower()
|
|
@@ -182,7 +232,7 @@ Para uso em APIs com autenticação JWT (JSON Web Token), OAuth, Bearer Token Au
|
|
|
182
232
|
try:
|
|
183
233
|
self.RetEndPoint = eval(ChamadaApi)
|
|
184
234
|
if self.RetEndPoint.status_code >= 500:
|
|
185
|
-
self.logger.critico(f'Erro {self.RetEndPoint.status_code}
|
|
235
|
+
self.logger.critico(f'Erro [{self.RetEndPoint.status_code}] no lado servidor na resposta à requisição')
|
|
186
236
|
raise Exception
|
|
187
237
|
self.RetEndPoint.Espera = self.Espera ## adiona o tempo de espera ao retorno da API
|
|
188
238
|
self.RetEndPoint.Intervalo = self.Intervalo ## adiciona o intervalo entre chamada ao retorno da API
|
|
@@ -192,7 +242,7 @@ Para uso em APIs com autenticação JWT (JSON Web Token), OAuth, Bearer Token Au
|
|
|
192
242
|
return Err
|
|
193
243
|
except Exception as Err:
|
|
194
244
|
self.logger.critico(f'Falha na chamada do endpoint: {Err}\nEndpoint: {self.EndPoint}\nCodigo retorno: {self.RetEndPoint.status_code}\nResposta:{self.RetEndPoint.text}')
|
|
195
|
-
return
|
|
245
|
+
return self.RetEndPoint
|
|
196
246
|
#
|
|
197
247
|
#
|
|
198
248
|
def trata_erro_sienge(CodRet, Retorno):
|
lbxtoolkit/postgresql.py
CHANGED
|
@@ -208,10 +208,10 @@ conexao.close()
|
|
|
208
208
|
#
|
|
209
209
|
def db_update(self, Query): # Retorna um cursor à partir de um select
|
|
210
210
|
UpdRows = 0
|
|
211
|
-
BlackList = ['INSERT ', '
|
|
211
|
+
BlackList = ['INSERT ', 'SELECT ', 'CREATE ', 'DROP ', 'MERGE ', 'REPLACE ', 'CALL ', 'EXECUTE ']
|
|
212
212
|
if any(element in Query.upper() for element in BlackList):
|
|
213
213
|
BlackListed = [element for element in BlackList if element in Query.upper()]
|
|
214
|
-
self.logger.erro(f'{__name__}: Este método permite apenas updates. A query informada possui as seguintes palavras reservadas não aceitas: {BlackListed} e não foi executada!')
|
|
214
|
+
self.logger.erro(f'{__name__}: Este método permite apenas updates e deletes. A query informada possui as seguintes palavras reservadas não aceitas: {BlackListed} e não foi executada!')
|
|
215
215
|
return None
|
|
216
216
|
else:
|
|
217
217
|
try:
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
lbxtoolkit/__init__.py,sha256=DbLn2XbgrDKcPhk0MR5hmFYVIRTOjyF_HSmKw1JtSOQ,5923
|
|
2
|
-
lbxtoolkit/api_rest.py,sha256=
|
|
2
|
+
lbxtoolkit/api_rest.py,sha256=8OpmCAwCLWIHU2C_caIb8qvu52kav7dKpJP0Ak1zUww,14736
|
|
3
3
|
lbxtoolkit/auth_entra_id.py,sha256=2iE7KpRhdh4u7Y4lem63IUkEPl_GpSLRSw45_Byn1s0,21922
|
|
4
4
|
lbxtoolkit/config_manager.py,sha256=n3pVsxKykiYsgRuJNcNrq-bdEAjDHLmeCySl33DsoNE,1629
|
|
5
5
|
lbxtoolkit/lbx_logger.py,sha256=iInkOlKdUzm-FSJOvcj-8D-uGJlAcNfjqrb0Q0TJ48Y,23433
|
|
6
6
|
lbxtoolkit/misc.py,sha256=RCIsIi1z_QSZW_jMEHYR9QSO0hdppKwV_QnKH7AVg8A,5282
|
|
7
|
-
lbxtoolkit/postgresql.py,sha256
|
|
7
|
+
lbxtoolkit/postgresql.py,sha256=OC0Iw9sbEthagcESqotodUGFUD6iIycg16ENnsDS6p4,11155
|
|
8
8
|
lbxtoolkit/service.py,sha256=KnkoybzKuO1t4tWkK8xGBylMnq-MMtwhGndf451M57A,19091
|
|
9
9
|
lbxtoolkit/service_windows.py,sha256=LTqITqOEWVSvp5slHG7NpRZV0-NYqI9tAgMXRvkSibM,15226
|
|
10
|
-
lbxtoolkit-2.2.
|
|
11
|
-
lbxtoolkit-2.2.
|
|
12
|
-
lbxtoolkit-2.2.
|
|
10
|
+
lbxtoolkit-2.2.8.dist-info/METADATA,sha256=a_f305BcReKYM3N1-wpHcDi2ZQ6wJDkI_m561kqwldE,46792
|
|
11
|
+
lbxtoolkit-2.2.8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
12
|
+
lbxtoolkit-2.2.8.dist-info/RECORD,,
|
|
File without changes
|