libretificacaotjcore 0.1.9__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.

Potentially problematic release.


This version of libretificacaotjcore might be problematic. Click here for more details.

@@ -0,0 +1,39 @@
1
+ from pymongo.errors import BulkWriteError
2
+
3
+ class CertificadoRepository:
4
+ def __init__(self, db):
5
+ self.__db = db
6
+
7
+ async def inserir_certificado(self, certificado: dict) -> bool:
8
+ try:
9
+ certificado_no_db = await self.__db.certificado.find_one(
10
+ {"cnpj": certificado["cnpj"]}
11
+ )
12
+
13
+ if certificado_no_db is None:
14
+ await self.__db.certificado.insert_one(certificado)
15
+ return True
16
+
17
+ await self.__db.certificado.delete_one(
18
+ {"cnpj": certificado["cnpj"]}
19
+ )
20
+ await self.__db.certificado.insert_one(certificado)
21
+ return True
22
+ except Exception as e:
23
+ print(f"❌ Erro ao inserir o arquivo: {e}")
24
+ return False
25
+
26
+ async def remover_certificado(self, cnpj: str) -> bool:
27
+ try:
28
+ await self.__db.certificado.delete_many({"cnpj": cnpj})
29
+ return True
30
+ except Exception as e:
31
+ print(f"❌ Erro ao remover o certificado: {e}")
32
+ return False
33
+
34
+ async def buscar_certificado_por_cnpj(self, cnpj: str) -> list[dict]:
35
+ try:
36
+ return await self.__db.certificado.find({"cnpj": cnpj}).to_list(length=None)
37
+ except Exception as e:
38
+ print(f"❌ Erro ao buscar certificado: {e}")
39
+ return []
@@ -1,3 +1,4 @@
1
+ from enum import unique
1
2
  import motor.motor_asyncio
2
3
  from bson import ObjectId
3
4
  from datetime import datetime
@@ -29,6 +30,13 @@ class ConfigDb:
29
30
  await self.__db.arquivos.create_index([("SolicitacaoId", 1), ("cpf", 1)], unique=True)
30
31
  self.db_initialized = True
31
32
 
33
+ if "certificados" not in (await self.__db.list_collection_names()):
34
+ await self.__db.create_collection("certificados")
35
+
36
+ await self.__db.certificados.create_index([("cnpj", 1)], unique=True)
37
+ await self.__db.arquivos.create_index([("id", 1)], unique=True)
38
+ self.db_initialized = True
39
+
32
40
  async def get_db(self):
33
41
  await self.criar_schema()
34
42
  return self.__db
@@ -1,11 +1,18 @@
1
1
  from cryptography.fernet import Fernet
2
2
 
3
-
4
3
  class CryptoPassService:
5
- def hasherPass(self, password:str , key_id_aws: str, region_name: str):
6
- key = Fernet.generate_key()
7
- cipher = Fernet(key)
8
-
9
- pass_config = password.encode()
10
-
11
-
4
+ def __init__(self, key: bytes | None = None):
5
+ # Se a chave não for passada, gera uma nova
6
+ self.key = key or Fernet.generate_key()
7
+ self.cipher = Fernet(self.key)
8
+
9
+ def encrypt_password(self, password: str) -> bytes:
10
+ # Recebe a senha em texto e retorna a senha criptografada em bytes
11
+ password_bytes = password.encode()
12
+ encrypted = self.cipher.encrypt(password_bytes)
13
+ return encrypted
14
+
15
+ def decrypt_password(self, token: bytes) -> str:
16
+ # Recebe o token criptografado e retorna a senha em texto
17
+ decrypted_bytes = self.cipher.decrypt(token)
18
+ return decrypted_bytes.decode()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: libretificacaotjcore
3
- Version: 0.1.9
3
+ Version: 0.1.11
4
4
  Summary: Biblioteca para centralizar conexao com filas no rabbit e banco de dados no mongodb para os servicos de retificacao da TJ
5
5
  Author-email: Jhonatan Azevedo <dev.azevedo@outlook.com>
6
6
  Project-URL: Homepage, https://github.com/seu-usuario/libretificacaotjcore
@@ -1,14 +1,15 @@
1
1
  libretificacaotjcore/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  libretificacaotjcore/database/__init__.py,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
3
3
  libretificacaotjcore/database/arquivo_repository.py,sha256=yKyYXzTyp1xiQsI1Cjh9wrnJACrm7xrgn6hlWgBHe48,2154
4
- libretificacaotjcore/database/config_db.py,sha256=ydY83Xn16DcAO-apH1nIJ1hKL_38hEHeUKg5R8v8ZJI,1292
4
+ libretificacaotjcore/database/certificado_repository.py,sha256=LF3rV1rQmRGZVB4wPh_vmDj81Gf_env_5hqtTbxXNFM,1396
5
+ libretificacaotjcore/database/config_db.py,sha256=9xLOw9gwlsB91_aCukcQx4PfhzsjnVl2BO0NWrWS-aY,1693
5
6
  libretificacaotjcore/dtos/solicitacao_dto.py,sha256=A0QU6MwuyK6Z2vYy4FknSAOfebpY4txB-YmgpFhAVCY,2460
6
7
  libretificacaotjcore/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- libretificacaotjcore/services/crypto_pass_service.py,sha256=HdZ7IqrPOf55CpxJgn6EaZfxiOC6TycNAnBhehYn8U8,283
8
+ libretificacaotjcore/services/crypto_pass_service.py,sha256=9D0vyjan6f_8AfNxGkLpGdvyMpojsJq_AAySpv_zKMc,740
8
9
  libretificacaotjcore/services/file_service.py,sha256=14CJokBbrsryQGmL0_unH2QKZpnteEAfxf5CPFdv6cE,2075
9
10
  libretificacaotjcore/services/rabbitmq_consumer.py,sha256=a25mRHjbkgO3lkdCJ5NpJfWAGHhVkQDCRDR2t8hMNAI,1710
10
11
  libretificacaotjcore/services/s3_service.py,sha256=HKR_jt2H3XdV1PCzo5R5bnhmoQ3I46Yn5IqAvVPhsjs,2946
11
- libretificacaotjcore-0.1.9.dist-info/METADATA,sha256=66_5zUhwpVf6rQqR6O7k1g_5Z9V5bMz1j-LmO4Uy1tU,1467
12
- libretificacaotjcore-0.1.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
- libretificacaotjcore-0.1.9.dist-info/top_level.txt,sha256=J9vnz_X9OUnxC-eXHiAzlc9xIrWBwZ5bgnIDQIIFY4c,21
14
- libretificacaotjcore-0.1.9.dist-info/RECORD,,
12
+ libretificacaotjcore-0.1.11.dist-info/METADATA,sha256=pWP6dPD6pm3gANy1Mx117YsNAsrwGqMiUtzdqqyjMuE,1468
13
+ libretificacaotjcore-0.1.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ libretificacaotjcore-0.1.11.dist-info/top_level.txt,sha256=J9vnz_X9OUnxC-eXHiAzlc9xIrWBwZ5bgnIDQIIFY4c,21
15
+ libretificacaotjcore-0.1.11.dist-info/RECORD,,