gcp-secret-lib
Biblioteca Python para facilitar a leitura, criação, atualização e gerenciamento de secrets no Google Cloud Secret Manager.
Esta biblioteca foi criada para simplificar o uso do Secret Manager em serviços, pipelines ou aplicações Python, fornecendo uma interface fácil e padronizada para operações comuns.
📦 Instalação
Você poderá instalar via:
pip install gcp-secret-lib
Ou instalar diretamente pelo repositório local:
pip install .
🔐 Autenticação
Para acessar o Secret Manager, é necessário configurar a variável de ambiente
GOOGLE_APPLICATION_CREDENTIALS apontando para um arquivo JSON de uma
Service Account com permissões adequadas.
Exemplo:
export GOOGLE_APPLICATION_CREDENTIALS="/caminho/para/sua/service-account.json"
A conta precisa das permissões:
- secretmanager.secrets.get
- secretmanager.versions.access
- secretmanager.secrets.create
- secretmanager.versions.add
- secretmanager.secrets.delete (opcional)
🚀 Como usar
1. Importar e inicializar
from gcp_secret_lib import GCPSecretManager
sm = GCPSecretManager()
2. Ler uma secret
secret = sm.get_secret(
project_id="meu-projeto",
secret_name="minha-secret"
)
print(secret)
Se a secret contiver JSON, ela será automaticamente convertida para dict.
3. Criar uma nova secret
secret_path = sm.create_secret(
project_id="meu-projeto",
secret_name="nova-secret"
)
print("Secret criada em:", secret_path)
4. Atualizar uma secret (criar nova versão)
sm.update_secret(
project_id="meu-projeto",
secret_name="nova-secret",
data={"token": "123", "url": "https://example.com"}
)
5. Carregar secrets como variáveis de ambiente
dados = sm.get_secret("meu-projeto", "minha-secret")
sm.set_env_vars(dados)
import os
print(os.getenv("token"))
6. Deletar uma secret
sm.delete_secret(
project_id="meu-projeto",
secret_name="secret-antiga"
)
🔍 Documentação das Funções
get_secret(project_id, secret_name)
Lê a última versão da secret e retorna o conteúdo como dict.
create_secret(project_id, secret_name)
Cria uma nova secret com replicação automática.
update_secret(project_id, secret_name, data)
Adiciona uma nova versão à secret existente.
set_env_vars(secrets_dict)
Carrega os valores da secret como variáveis de ambiente.
delete_secret(project_id, secret_name)
Remove a secret do projeto.
📁 Estrutura do Projeto
gcp-secret-lib/
│
├── gcp_secret_lib/
│ ├── __init__.py
│ └── secret_manager.py
│
├── tests/
│ └── test_secret_manager.py
│
├── README.md
├── setup.py
└── requirements.txt
🧪 Testes Unitários
Rode:
pytest
Ou:
PYTHONPATH=. python tests/test_secret_manager.py
🤝 Contribuições
Pull requests e melhorias são bem-vindos!
Metadata
Release files for gcp-secret-lib 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gcp_secret_lib-1.0.2.tar.gz | 3.8 kB | Without provenance | Details for gcp_secret_lib-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gcp_secret_lib-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for gcp_secret_lib-1.0.2-py3-none-any.whl |
Total release size: 7.7 kB
Release files / gcp_secret_lib-1.0.2.tar.gz
| Download URL | gcp_secret_lib-1.0.2.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a4f7eeb6f7a3b15201ba3c29ad432b3cfa9a7eebaac64f5f7a60d69d8b01e2cc
|
|
BLAKE2b-256 checksum How to use checksums |
9e32e722daa8a306b805cf062ae6e43becc3c3f20b876b4fe740235d091f9c33
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.14
|
Release files / gcp_secret_lib-1.0.2-py3-none-any.whl
| Download URL | gcp_secret_lib-1.0.2-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
273ad9e4cee36cc07d7d8ba121fc3e4e5af91ad45e73842c1219adb9ef4d5b39
|
|
BLAKE2b-256 checksum How to use checksums |
bb9e5f3cd7152bb2d75affffcfc78acb435f18914e010d14256419bcd6e7fc62
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.14
|
Security for gcp-secret-lib 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.