gates-sdk 0.1.4__tar.gz
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.
- gates_sdk-0.1.4/LICENSE +21 -0
- gates_sdk-0.1.4/MANIFEST.in +11 -0
- gates_sdk-0.1.4/PKG-INFO +312 -0
- gates_sdk-0.1.4/README.md +247 -0
- gates_sdk-0.1.4/pyproject.toml +117 -0
- gates_sdk-0.1.4/setup.cfg +4 -0
- gates_sdk-0.1.4/src/gates_sdk/__init__.py +38 -0
- gates_sdk-0.1.4/src/gates_sdk/auth.py +149 -0
- gates_sdk-0.1.4/src/gates_sdk/cache.py +43 -0
- gates_sdk-0.1.4/src/gates_sdk/errors.py +72 -0
- gates_sdk-0.1.4/src/gates_sdk/models.py +41 -0
- gates_sdk-0.1.4/src/gates_sdk/py.typed +1 -0
- gates_sdk-0.1.4/src/gates_sdk/user.py +119 -0
- gates_sdk-0.1.4/src/gates_sdk.egg-info/PKG-INFO +312 -0
- gates_sdk-0.1.4/src/gates_sdk.egg-info/SOURCES.txt +21 -0
- gates_sdk-0.1.4/src/gates_sdk.egg-info/dependency_links.txt +1 -0
- gates_sdk-0.1.4/src/gates_sdk.egg-info/requires.txt +18 -0
- gates_sdk-0.1.4/src/gates_sdk.egg-info/top_level.txt +1 -0
- gates_sdk-0.1.4/tests/__init__.py +1 -0
- gates_sdk-0.1.4/tests/test_auth.py +14 -0
- gates_sdk-0.1.4/tests/test_cache.py +56 -0
- gates_sdk-0.1.4/tests/test_integration.py +18 -0
- gates_sdk-0.1.4/tests/test_user.py +95 -0
gates_sdk-0.1.4/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Intelicity
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
include README.md
|
|
2
|
+
include LICENSE
|
|
3
|
+
include pyproject.toml
|
|
4
|
+
recursive-include src *.py
|
|
5
|
+
recursive-include src *.pyi
|
|
6
|
+
recursive-include tests *.py
|
|
7
|
+
global-exclude __pycache__
|
|
8
|
+
global-exclude *.py[co]
|
|
9
|
+
global-exclude .DS_Store
|
|
10
|
+
global-exclude *.so
|
|
11
|
+
global-exclude .git*
|
gates_sdk-0.1.4/PKG-INFO
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gates-sdk
|
|
3
|
+
Version: 0.1.4
|
|
4
|
+
Summary: SDK em Python para integrar com o Gates para autenticação via Cognito e gestão de usuários
|
|
5
|
+
Author: Intelicity
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Intelicity
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/intelicity/gates-python-sdk
|
|
29
|
+
Project-URL: Repository, https://github.com/intelicity/gates-python-sdk
|
|
30
|
+
Project-URL: Documentation, https://github.com/intelicity/gates-python-sdk#readme
|
|
31
|
+
Project-URL: Bug Reports, https://github.com/intelicity/gates-python-sdk/issues
|
|
32
|
+
Project-URL: Source Code, https://github.com/intelicity/gates-python-sdk
|
|
33
|
+
Keywords: aws,cognito,jwt,authentication,gates,sdk
|
|
34
|
+
Classifier: Development Status :: 4 - Beta
|
|
35
|
+
Classifier: Intended Audience :: Developers
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
42
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
43
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
44
|
+
Classifier: Topic :: System :: Systems Administration :: Authentication/Directory
|
|
45
|
+
Requires-Python: >=3.9
|
|
46
|
+
Description-Content-Type: text/markdown
|
|
47
|
+
License-File: LICENSE
|
|
48
|
+
Requires-Dist: pyjwt[crypto]>=2.8
|
|
49
|
+
Requires-Dist: httpx<1.0,>=0.27
|
|
50
|
+
Provides-Extra: dev
|
|
51
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
52
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
53
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
|
|
54
|
+
Requires-Dist: black>=23.0; extra == "dev"
|
|
55
|
+
Requires-Dist: flake8>=6.0; extra == "dev"
|
|
56
|
+
Requires-Dist: mypy>=1.0; extra == "dev"
|
|
57
|
+
Requires-Dist: isort>=5.0; extra == "dev"
|
|
58
|
+
Requires-Dist: twine>=4.0; extra == "dev"
|
|
59
|
+
Requires-Dist: build>=0.10; extra == "dev"
|
|
60
|
+
Provides-Extra: test
|
|
61
|
+
Requires-Dist: pytest>=7.0; extra == "test"
|
|
62
|
+
Requires-Dist: pytest-cov>=4.0; extra == "test"
|
|
63
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == "test"
|
|
64
|
+
Dynamic: license-file
|
|
65
|
+
|
|
66
|
+
# Gates SDK (Python)
|
|
67
|
+
|
|
68
|
+
[](https://badge.fury.io/py/gates-sdk)
|
|
69
|
+
[](https://pypi.org/project/gates-sdk/)
|
|
70
|
+
[](https://opensource.org/licenses/MIT)
|
|
71
|
+
[](https://github.com/psf/black)
|
|
72
|
+
|
|
73
|
+
SDK em Python para autenticação de usuários com tokens JWT do AWS Cognito e integração com o backend do Gates para gerenciamento de perfis. Estruturado para publicação no PyPI.
|
|
74
|
+
|
|
75
|
+
## Características
|
|
76
|
+
|
|
77
|
+
- ✅ Autenticação com tokens JWT do AWS Cognito
|
|
78
|
+
- ✅ Validação de grupos de usuários
|
|
79
|
+
- ✅ Cache automático de chaves públicas
|
|
80
|
+
- ✅ Cliente HTTP assíncrono para API do Gates
|
|
81
|
+
- ✅ Suporte a profiles de usuário personalizados
|
|
82
|
+
- ✅ Tratamento robusto de erros
|
|
83
|
+
- ✅ Type hints completos
|
|
84
|
+
- ✅ Testes unitários abrangentes
|
|
85
|
+
|
|
86
|
+
## Instalação
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
pip install gates-sdk
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Instalação para desenvolvimento
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# Clone o repositório
|
|
96
|
+
git clone https://github.com/intelicity/gates-python-sdk.git
|
|
97
|
+
cd gates-python-sdk
|
|
98
|
+
|
|
99
|
+
# Crie um ambiente virtual
|
|
100
|
+
python -m venv venv
|
|
101
|
+
|
|
102
|
+
# Ative o ambiente virtual (Windows)
|
|
103
|
+
venv\Scripts\activate
|
|
104
|
+
# ou Linux/Mac:
|
|
105
|
+
# source venv/bin/activate
|
|
106
|
+
|
|
107
|
+
# Instale em modo de desenvolvimento
|
|
108
|
+
pip install -e ".[dev]"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Uso
|
|
112
|
+
|
|
113
|
+
### Autenticação
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from gates_sdk import AuthService
|
|
117
|
+
|
|
118
|
+
auth = AuthService(
|
|
119
|
+
region="sa-east-1",
|
|
120
|
+
user_pool_id="sa-east-1_xxxxxxxxx",
|
|
121
|
+
audience="your-client-id",
|
|
122
|
+
required_group=["admin", "user"], # opcional
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
try:
|
|
126
|
+
user = auth.verify_token(token)
|
|
127
|
+
print("Usuário autenticado", user)
|
|
128
|
+
print("É membro do grupo?", auth.is_member_of(user.groups or []))
|
|
129
|
+
except Exception as exc:
|
|
130
|
+
print("Falha ao autenticar:", exc)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Serviço de usuários
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from gates_sdk import UserService
|
|
137
|
+
|
|
138
|
+
user_service = UserService(
|
|
139
|
+
base_url="https://api.example.com",
|
|
140
|
+
system="your-system-name",
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
users = user_service.get_all_users(id_token)
|
|
144
|
+
print(users.profiles, users.total)
|
|
145
|
+
|
|
146
|
+
profile = user_service.get_profile(id_token)
|
|
147
|
+
print(profile)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Variáveis de ambiente
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
export GATES_REGION=sa-east-1
|
|
154
|
+
export GATES_USER_POOL_ID=sa-east-1_xxxxxxxxx
|
|
155
|
+
export GATES_CLIENT_ID=your-cognito-client-id
|
|
156
|
+
export GATES_BACKEND_URL=https://your-backend-api.com
|
|
157
|
+
export GATES_SYSTEM_NAME=your-system-name
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Também é possível instanciar os serviços lendo essas variáveis com `os.getenv`.
|
|
161
|
+
|
|
162
|
+
## Desenvolvimento
|
|
163
|
+
|
|
164
|
+
### Configuração inicial
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# Instalar dependências de desenvolvimento
|
|
168
|
+
pip install -e ".[dev]"
|
|
169
|
+
|
|
170
|
+
# Configurar pre-commit hooks (opcional)
|
|
171
|
+
pre-commit install
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Comandos úteis
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# Executar testes
|
|
178
|
+
pytest
|
|
179
|
+
|
|
180
|
+
# Testes com cobertura
|
|
181
|
+
pytest --cov=src --cov-report=html
|
|
182
|
+
|
|
183
|
+
# Formatação de código
|
|
184
|
+
black src tests
|
|
185
|
+
isort src tests
|
|
186
|
+
|
|
187
|
+
# Verificar formatação sem modificar
|
|
188
|
+
black --check src tests
|
|
189
|
+
isort --check-only src tests
|
|
190
|
+
|
|
191
|
+
# Lint
|
|
192
|
+
flake8 src tests
|
|
193
|
+
|
|
194
|
+
# Verificação de tipos
|
|
195
|
+
mypy src
|
|
196
|
+
|
|
197
|
+
# Executar todas as verificações
|
|
198
|
+
pytest && black --check src tests && isort --check-only src tests && flake8 src tests && mypy src
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Usando o Makefile (Linux/Mac)
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
make help # Mostra todos os comandos disponíveis
|
|
205
|
+
make install-dev # Instala dependências de desenvolvimento
|
|
206
|
+
make test # Executa testes
|
|
207
|
+
make format # Formata código
|
|
208
|
+
make check # Executa todas as verificações
|
|
209
|
+
make build # Constrói o pacote
|
|
210
|
+
make upload-test # Publica no TestPyPI
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Usando o script PowerShell (Windows)
|
|
214
|
+
|
|
215
|
+
```powershell
|
|
216
|
+
# Publicar no TestPyPI
|
|
217
|
+
.\publish.ps1 -Target test
|
|
218
|
+
|
|
219
|
+
# Publicar no PyPI (produção)
|
|
220
|
+
.\publish.ps1 -Target prod
|
|
221
|
+
|
|
222
|
+
# Pular testes durante publicação
|
|
223
|
+
.\publish.ps1 -SkipTests
|
|
224
|
+
|
|
225
|
+
# Forçar publicação sem confirmação
|
|
226
|
+
.\publish.ps1 -Force
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Estrutura do projeto
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
gates-python-sdk/
|
|
233
|
+
├── src/
|
|
234
|
+
│ ├── __init__.py # Exports principais
|
|
235
|
+
│ ├── auth.py # Serviço de autenticação
|
|
236
|
+
│ ├── cache.py # Sistema de cache
|
|
237
|
+
│ ├── errors.py # Exceções customizadas
|
|
238
|
+
│ ├── models.py # Modelos de dados
|
|
239
|
+
│ ├── user.py # Serviço de usuários
|
|
240
|
+
│ └── py.typed # Marcador de type hints
|
|
241
|
+
├── tests/
|
|
242
|
+
│ ├── test_auth.py # Testes de autenticação
|
|
243
|
+
│ ├── test_cache.py # Testes de cache
|
|
244
|
+
│ └── test_user.py # Testes de usuários
|
|
245
|
+
├── .github/workflows/ # GitHub Actions
|
|
246
|
+
├── pyproject.toml # Configuração do projeto
|
|
247
|
+
├── CHANGELOG.md # Histórico de mudanças
|
|
248
|
+
├── LICENSE # Licença MIT
|
|
249
|
+
├── MANIFEST.in # Arquivos para incluir no pacote
|
|
250
|
+
├── Makefile # Comandos para Unix/Linux
|
|
251
|
+
├── publish.ps1 # Script de publicação para Windows
|
|
252
|
+
├── publish.py # Script de publicação Python
|
|
253
|
+
└── README.md # Este arquivo
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Publicação
|
|
257
|
+
|
|
258
|
+
1. **Atualizar versão** em `pyproject.toml`
|
|
259
|
+
2. **Atualizar** `CHANGELOG.md`
|
|
260
|
+
3. **Executar testes**: `pytest`
|
|
261
|
+
4. **Testar no TestPyPI**: `.\publish.ps1 -Target test`
|
|
262
|
+
5. **Publicar no PyPI**: `.\publish.ps1 -Target prod`
|
|
263
|
+
|
|
264
|
+
### Testes
|
|
265
|
+
|
|
266
|
+
O projeto inclui testes unitários abrangentes:
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
# Executar todos os testes
|
|
270
|
+
pytest
|
|
271
|
+
|
|
272
|
+
# Executar com cobertura
|
|
273
|
+
pytest --cov=src
|
|
274
|
+
|
|
275
|
+
# Executar testes específicos
|
|
276
|
+
pytest tests/test_auth.py
|
|
277
|
+
|
|
278
|
+
# Executar com output verboso
|
|
279
|
+
pytest -v
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Integração Contínua
|
|
283
|
+
|
|
284
|
+
O projeto está configurado com GitHub Actions para:
|
|
285
|
+
|
|
286
|
+
- ✅ Testes automatizados em Python 3.9-3.12
|
|
287
|
+
- ✅ Verificação de formatação e lint
|
|
288
|
+
- ✅ Verificação de tipos com mypy
|
|
289
|
+
- ✅ Build e verificação do pacote
|
|
290
|
+
- ✅ Publicação automática no PyPI via releases
|
|
291
|
+
|
|
292
|
+
## Requisitos
|
|
293
|
+
|
|
294
|
+
- Python ≥ 3.9
|
|
295
|
+
- pyjwt[crypto] ≥ 2.8
|
|
296
|
+
- httpx ≥ 0.27
|
|
297
|
+
|
|
298
|
+
## Licença
|
|
299
|
+
|
|
300
|
+
MIT - veja o arquivo [LICENSE](LICENSE) para detalhes.
|
|
301
|
+
|
|
302
|
+
## Contribuição
|
|
303
|
+
|
|
304
|
+
1. Fork o projeto
|
|
305
|
+
2. Crie uma branch para sua feature (`git checkout -b feature/nova-feature`)
|
|
306
|
+
3. Commit suas mudanças (`git commit -am 'Adiciona nova feature'`)
|
|
307
|
+
4. Push para a branch (`git push origin feature/nova-feature`)
|
|
308
|
+
5. Abra um Pull Request
|
|
309
|
+
|
|
310
|
+
## Suporte
|
|
311
|
+
|
|
312
|
+
Para questões e suporte, abra uma [issue](https://github.com/intelicity/gates-python-sdk/issues) no GitHub.
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Gates SDK (Python)
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/py/gates-sdk)
|
|
4
|
+
[](https://pypi.org/project/gates-sdk/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://github.com/psf/black)
|
|
7
|
+
|
|
8
|
+
SDK em Python para autenticação de usuários com tokens JWT do AWS Cognito e integração com o backend do Gates para gerenciamento de perfis. Estruturado para publicação no PyPI.
|
|
9
|
+
|
|
10
|
+
## Características
|
|
11
|
+
|
|
12
|
+
- ✅ Autenticação com tokens JWT do AWS Cognito
|
|
13
|
+
- ✅ Validação de grupos de usuários
|
|
14
|
+
- ✅ Cache automático de chaves públicas
|
|
15
|
+
- ✅ Cliente HTTP assíncrono para API do Gates
|
|
16
|
+
- ✅ Suporte a profiles de usuário personalizados
|
|
17
|
+
- ✅ Tratamento robusto de erros
|
|
18
|
+
- ✅ Type hints completos
|
|
19
|
+
- ✅ Testes unitários abrangentes
|
|
20
|
+
|
|
21
|
+
## Instalação
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install gates-sdk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Instalação para desenvolvimento
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Clone o repositório
|
|
31
|
+
git clone https://github.com/intelicity/gates-python-sdk.git
|
|
32
|
+
cd gates-python-sdk
|
|
33
|
+
|
|
34
|
+
# Crie um ambiente virtual
|
|
35
|
+
python -m venv venv
|
|
36
|
+
|
|
37
|
+
# Ative o ambiente virtual (Windows)
|
|
38
|
+
venv\Scripts\activate
|
|
39
|
+
# ou Linux/Mac:
|
|
40
|
+
# source venv/bin/activate
|
|
41
|
+
|
|
42
|
+
# Instale em modo de desenvolvimento
|
|
43
|
+
pip install -e ".[dev]"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Uso
|
|
47
|
+
|
|
48
|
+
### Autenticação
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from gates_sdk import AuthService
|
|
52
|
+
|
|
53
|
+
auth = AuthService(
|
|
54
|
+
region="sa-east-1",
|
|
55
|
+
user_pool_id="sa-east-1_xxxxxxxxx",
|
|
56
|
+
audience="your-client-id",
|
|
57
|
+
required_group=["admin", "user"], # opcional
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
try:
|
|
61
|
+
user = auth.verify_token(token)
|
|
62
|
+
print("Usuário autenticado", user)
|
|
63
|
+
print("É membro do grupo?", auth.is_member_of(user.groups or []))
|
|
64
|
+
except Exception as exc:
|
|
65
|
+
print("Falha ao autenticar:", exc)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Serviço de usuários
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from gates_sdk import UserService
|
|
72
|
+
|
|
73
|
+
user_service = UserService(
|
|
74
|
+
base_url="https://api.example.com",
|
|
75
|
+
system="your-system-name",
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
users = user_service.get_all_users(id_token)
|
|
79
|
+
print(users.profiles, users.total)
|
|
80
|
+
|
|
81
|
+
profile = user_service.get_profile(id_token)
|
|
82
|
+
print(profile)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Variáveis de ambiente
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
export GATES_REGION=sa-east-1
|
|
89
|
+
export GATES_USER_POOL_ID=sa-east-1_xxxxxxxxx
|
|
90
|
+
export GATES_CLIENT_ID=your-cognito-client-id
|
|
91
|
+
export GATES_BACKEND_URL=https://your-backend-api.com
|
|
92
|
+
export GATES_SYSTEM_NAME=your-system-name
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Também é possível instanciar os serviços lendo essas variáveis com `os.getenv`.
|
|
96
|
+
|
|
97
|
+
## Desenvolvimento
|
|
98
|
+
|
|
99
|
+
### Configuração inicial
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Instalar dependências de desenvolvimento
|
|
103
|
+
pip install -e ".[dev]"
|
|
104
|
+
|
|
105
|
+
# Configurar pre-commit hooks (opcional)
|
|
106
|
+
pre-commit install
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Comandos úteis
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# Executar testes
|
|
113
|
+
pytest
|
|
114
|
+
|
|
115
|
+
# Testes com cobertura
|
|
116
|
+
pytest --cov=src --cov-report=html
|
|
117
|
+
|
|
118
|
+
# Formatação de código
|
|
119
|
+
black src tests
|
|
120
|
+
isort src tests
|
|
121
|
+
|
|
122
|
+
# Verificar formatação sem modificar
|
|
123
|
+
black --check src tests
|
|
124
|
+
isort --check-only src tests
|
|
125
|
+
|
|
126
|
+
# Lint
|
|
127
|
+
flake8 src tests
|
|
128
|
+
|
|
129
|
+
# Verificação de tipos
|
|
130
|
+
mypy src
|
|
131
|
+
|
|
132
|
+
# Executar todas as verificações
|
|
133
|
+
pytest && black --check src tests && isort --check-only src tests && flake8 src tests && mypy src
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Usando o Makefile (Linux/Mac)
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
make help # Mostra todos os comandos disponíveis
|
|
140
|
+
make install-dev # Instala dependências de desenvolvimento
|
|
141
|
+
make test # Executa testes
|
|
142
|
+
make format # Formata código
|
|
143
|
+
make check # Executa todas as verificações
|
|
144
|
+
make build # Constrói o pacote
|
|
145
|
+
make upload-test # Publica no TestPyPI
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Usando o script PowerShell (Windows)
|
|
149
|
+
|
|
150
|
+
```powershell
|
|
151
|
+
# Publicar no TestPyPI
|
|
152
|
+
.\publish.ps1 -Target test
|
|
153
|
+
|
|
154
|
+
# Publicar no PyPI (produção)
|
|
155
|
+
.\publish.ps1 -Target prod
|
|
156
|
+
|
|
157
|
+
# Pular testes durante publicação
|
|
158
|
+
.\publish.ps1 -SkipTests
|
|
159
|
+
|
|
160
|
+
# Forçar publicação sem confirmação
|
|
161
|
+
.\publish.ps1 -Force
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Estrutura do projeto
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
gates-python-sdk/
|
|
168
|
+
├── src/
|
|
169
|
+
│ ├── __init__.py # Exports principais
|
|
170
|
+
│ ├── auth.py # Serviço de autenticação
|
|
171
|
+
│ ├── cache.py # Sistema de cache
|
|
172
|
+
│ ├── errors.py # Exceções customizadas
|
|
173
|
+
│ ├── models.py # Modelos de dados
|
|
174
|
+
│ ├── user.py # Serviço de usuários
|
|
175
|
+
│ └── py.typed # Marcador de type hints
|
|
176
|
+
├── tests/
|
|
177
|
+
│ ├── test_auth.py # Testes de autenticação
|
|
178
|
+
│ ├── test_cache.py # Testes de cache
|
|
179
|
+
│ └── test_user.py # Testes de usuários
|
|
180
|
+
├── .github/workflows/ # GitHub Actions
|
|
181
|
+
├── pyproject.toml # Configuração do projeto
|
|
182
|
+
├── CHANGELOG.md # Histórico de mudanças
|
|
183
|
+
├── LICENSE # Licença MIT
|
|
184
|
+
├── MANIFEST.in # Arquivos para incluir no pacote
|
|
185
|
+
├── Makefile # Comandos para Unix/Linux
|
|
186
|
+
├── publish.ps1 # Script de publicação para Windows
|
|
187
|
+
├── publish.py # Script de publicação Python
|
|
188
|
+
└── README.md # Este arquivo
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Publicação
|
|
192
|
+
|
|
193
|
+
1. **Atualizar versão** em `pyproject.toml`
|
|
194
|
+
2. **Atualizar** `CHANGELOG.md`
|
|
195
|
+
3. **Executar testes**: `pytest`
|
|
196
|
+
4. **Testar no TestPyPI**: `.\publish.ps1 -Target test`
|
|
197
|
+
5. **Publicar no PyPI**: `.\publish.ps1 -Target prod`
|
|
198
|
+
|
|
199
|
+
### Testes
|
|
200
|
+
|
|
201
|
+
O projeto inclui testes unitários abrangentes:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
# Executar todos os testes
|
|
205
|
+
pytest
|
|
206
|
+
|
|
207
|
+
# Executar com cobertura
|
|
208
|
+
pytest --cov=src
|
|
209
|
+
|
|
210
|
+
# Executar testes específicos
|
|
211
|
+
pytest tests/test_auth.py
|
|
212
|
+
|
|
213
|
+
# Executar com output verboso
|
|
214
|
+
pytest -v
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Integração Contínua
|
|
218
|
+
|
|
219
|
+
O projeto está configurado com GitHub Actions para:
|
|
220
|
+
|
|
221
|
+
- ✅ Testes automatizados em Python 3.9-3.12
|
|
222
|
+
- ✅ Verificação de formatação e lint
|
|
223
|
+
- ✅ Verificação de tipos com mypy
|
|
224
|
+
- ✅ Build e verificação do pacote
|
|
225
|
+
- ✅ Publicação automática no PyPI via releases
|
|
226
|
+
|
|
227
|
+
## Requisitos
|
|
228
|
+
|
|
229
|
+
- Python ≥ 3.9
|
|
230
|
+
- pyjwt[crypto] ≥ 2.8
|
|
231
|
+
- httpx ≥ 0.27
|
|
232
|
+
|
|
233
|
+
## Licença
|
|
234
|
+
|
|
235
|
+
MIT - veja o arquivo [LICENSE](LICENSE) para detalhes.
|
|
236
|
+
|
|
237
|
+
## Contribuição
|
|
238
|
+
|
|
239
|
+
1. Fork o projeto
|
|
240
|
+
2. Crie uma branch para sua feature (`git checkout -b feature/nova-feature`)
|
|
241
|
+
3. Commit suas mudanças (`git commit -am 'Adiciona nova feature'`)
|
|
242
|
+
4. Push para a branch (`git push origin feature/nova-feature`)
|
|
243
|
+
5. Abra um Pull Request
|
|
244
|
+
|
|
245
|
+
## Suporte
|
|
246
|
+
|
|
247
|
+
Para questões e suporte, abra uma [issue](https://github.com/intelicity/gates-python-sdk/issues) no GitHub.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "gates-sdk"
|
|
7
|
+
version = "0.1.4"
|
|
8
|
+
description = "SDK em Python para integrar com o Gates para autenticação via Cognito e gestão de usuários"
|
|
9
|
+
authors = [{name = "Intelicity"}]
|
|
10
|
+
license = {file = "LICENSE"}
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
keywords = ["aws", "cognito", "jwt", "authentication", "gates", "sdk"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
24
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
25
|
+
"Topic :: System :: Systems Administration :: Authentication/Directory",
|
|
26
|
+
]
|
|
27
|
+
dependencies = [
|
|
28
|
+
"pyjwt[crypto]>=2.8",
|
|
29
|
+
"httpx>=0.27,<1.0",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
dev = [
|
|
34
|
+
"pytest>=7.0",
|
|
35
|
+
"pytest-cov>=4.0",
|
|
36
|
+
"pytest-asyncio>=0.21",
|
|
37
|
+
"black>=23.0",
|
|
38
|
+
"flake8>=6.0",
|
|
39
|
+
"mypy>=1.0",
|
|
40
|
+
"isort>=5.0",
|
|
41
|
+
"twine>=4.0",
|
|
42
|
+
"build>=0.10",
|
|
43
|
+
]
|
|
44
|
+
test = [
|
|
45
|
+
"pytest>=7.0",
|
|
46
|
+
"pytest-cov>=4.0",
|
|
47
|
+
"pytest-asyncio>=0.21",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
[project.urls]
|
|
51
|
+
Homepage = "https://github.com/intelicity/gates-python-sdk"
|
|
52
|
+
Repository = "https://github.com/intelicity/gates-python-sdk"
|
|
53
|
+
Documentation = "https://github.com/intelicity/gates-python-sdk#readme"
|
|
54
|
+
"Bug Reports" = "https://github.com/intelicity/gates-python-sdk/issues"
|
|
55
|
+
"Source Code" = "https://github.com/intelicity/gates-python-sdk"
|
|
56
|
+
|
|
57
|
+
[tool.setuptools.packages.find]
|
|
58
|
+
where = ["src"]
|
|
59
|
+
|
|
60
|
+
[tool.setuptools.package-data]
|
|
61
|
+
"*" = ["py.typed"]
|
|
62
|
+
|
|
63
|
+
[tool.black]
|
|
64
|
+
line-length = 88
|
|
65
|
+
target-version = ['py39']
|
|
66
|
+
include = '\.pyi?$'
|
|
67
|
+
extend-exclude = '''
|
|
68
|
+
(
|
|
69
|
+
/(
|
|
70
|
+
\.eggs
|
|
71
|
+
| \.git
|
|
72
|
+
| \.hg
|
|
73
|
+
| \.mypy_cache
|
|
74
|
+
| \.tox
|
|
75
|
+
| \.venv
|
|
76
|
+
| _build
|
|
77
|
+
| buck-out
|
|
78
|
+
| build
|
|
79
|
+
| dist
|
|
80
|
+
)/
|
|
81
|
+
)
|
|
82
|
+
'''
|
|
83
|
+
|
|
84
|
+
[tool.isort]
|
|
85
|
+
profile = "black"
|
|
86
|
+
line_length = 88
|
|
87
|
+
multi_line_output = 3
|
|
88
|
+
include_trailing_comma = true
|
|
89
|
+
force_grid_wrap = 0
|
|
90
|
+
use_parentheses = true
|
|
91
|
+
ensure_newline_before_comments = true
|
|
92
|
+
|
|
93
|
+
[tool.mypy]
|
|
94
|
+
python_version = "3.9"
|
|
95
|
+
warn_return_any = true
|
|
96
|
+
warn_unused_configs = true
|
|
97
|
+
disallow_untyped_defs = true
|
|
98
|
+
disallow_incomplete_defs = true
|
|
99
|
+
check_untyped_defs = true
|
|
100
|
+
disallow_untyped_decorators = true
|
|
101
|
+
no_implicit_optional = true
|
|
102
|
+
warn_redundant_casts = true
|
|
103
|
+
warn_unused_ignores = true
|
|
104
|
+
warn_no_return = true
|
|
105
|
+
warn_unreachable = true
|
|
106
|
+
strict_equality = true
|
|
107
|
+
|
|
108
|
+
[tool.pytest.ini_options]
|
|
109
|
+
testpaths = ["tests"]
|
|
110
|
+
python_files = ["test_*.py"]
|
|
111
|
+
python_classes = ["Test*"]
|
|
112
|
+
python_functions = ["test_*"]
|
|
113
|
+
addopts = "-v --cov=src --cov-report=term-missing --cov-report=html"
|
|
114
|
+
|
|
115
|
+
[tool.coverage.run]
|
|
116
|
+
source = ["src"]
|
|
117
|
+
omit = ["*/tests/*", "*/test_*"]
|