Metadata-Version: 2.4
Name: infra-core-sdk
Version: 0.1.0
Summary: Secure and extensible credential management SDK for Python applications.
Author: Rafael Cavalcante
Project-URL: Homepage, https://github.com/rmcavalcante7/
Project-URL: Repository, https://github.com/rmcavalcante7/infra-core-sdk
Requires-Python: <3.15,>=3.14
Description-Content-Type: text/markdown
Requires-Dist: cryptography>=46.0.6
Provides-Extra: dev
Requires-Dist: pytest>=8.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: black>=24.0.0; extra == "dev"
Requires-Dist: mypy>=1.0.0; extra == "dev"

# 🔐 infra_core

**infra_core** é um SDK Python para gerenciamento seguro de credenciais com suporte a criptografia automática, múltiplos ambientes e arquitetura extensível.

---

## 🚀 Features

* 🔐 Criptografia automática (Fernet)
* 📦 Suporte a múltiplas credenciais (`name`)
* ⚙️ Setup e Load desacoplados
* 📁 Gerenciamento automático de paths
* 🧩 Arquitetura modular e extensível
* 🔄 Compatível com `pip install -e` (desenvolvimento)

---

## 📦 Instalação

### 🔹 Desenvolvimento (recomendado)

Dentro do projeto que irá **usar o SDK**:

```bash
pip install -e caminho/para/infra_core
```

Exemplo:

```bash
pip install -e C:\Users\rafael.m.cavalcante\PycharmProjects\infra_core
```

---

### 🔹 Produção

```bash
pip install infra-core
```

---

## 🧱 Estrutura esperada

Após o uso:

```
seu_projeto/
├── main.py
├── secret/
│   ├── secret.key
│   ├── aws.json
│   ├── pipefy.json
```

---

## 🧠 Conceitos principais

### 🔑 Secret Key

* Gerada automaticamente no primeiro uso
* Armazenada em `secret/secret.key`
* Nunca deve ser criada manualmente

---

### 📄 Credenciais

* Cada credencial é armazenada em um arquivo separado
* Nome controlado pelo parâmetro `name`

```python
name="aws" → secret/aws.json
```

---

## 🧩 Criando um modelo de credenciais

```python
from dataclasses import dataclass
from infra_core import BaseCredentials

@dataclass(frozen=True)
class MyCreds(BaseCredentials):
    api_token: str
```

---

## 💾 Salvando credenciais (Setup)

```python
from infra_core import FernetEncryption
from infra_core.credentials.setup.credentials_setup_service import CredentialsSetupService

setup = CredentialsSetupService(FernetEncryption)

setup.setup(
    MyCreds(api_token="123"),
    name="pipefy"
)
```

---

## 🔓 Carregando credenciais (Load)

```python
from infra_core import CredentialsLoader, FernetEncryption

creds = CredentialsLoader.load(
    MyCreds,
    FernetEncryption,
    name="pipefy"
)

print(creds.api_token)
```

---

## 🔄 Multi-credenciais

```python
setup.setup(..., name="aws")
setup.setup(..., name="pipefy")
setup.setup(..., name="stripe")
```

---

## 🔐 Encryption

### Default

```python
from infra_core import FernetEncryption
```

---

### Custom (avançado)

```python
class CustomEncryption:
    def encrypt(self, value: str) -> str:
        ...

    def decrypt(self, value: str) -> str:
        ...
```

---

## ⚠️ Regras importantes

### ❌ Não faça

```python
Fernet.generate_key()
FernetEncryption(key)
```

---

### ✅ Faça

```python
CredentialsSetupService(FernetEncryption)
```

---

## 🧪 Testes

```bash
pytest tests
```

---

## 🧠 Arquitetura

```
infra_core/
├── core/            # Path management
├── credentials/
│   ├── models/      # BaseCredentials
│   ├── services/    # Load / Save
│   ├── setup/       # Setup flow
│   └── exceptions/
├── security/        # Encryption
```

---

## ⚠️ Problemas comuns

### ModuleNotFoundError

```bash
pip install -e caminho/infra_core
```

---

### Dependência não encontrada

```bash
pip install cryptography
```

---

### PyCharm não reconhece imports

```
File → Invalidate Caches → Restart
```

---

## 🎯 Fluxo completo

```
SETUP:
    → gera key
    → criptografa
    → salva arquivo

LOAD:
    → lê key
    → descriptografa
    → retorna objeto tipado
```

---

## 🚀 Roadmap

* [ ] CLI (`infra-core setup`)
* [ ] Registry de credenciais
* [ ] Multi-env (dev/prod)
* [ ] Publish no PyPI

---

## 📄 Licença

MIT

---

## 👨‍💻 Autor

Rafael Cavalcante
