get-hc-secrets 1.5.23__py3-none-any.whl → 1.5.24__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.
getSecrets/__init__.py CHANGED
@@ -2,9 +2,10 @@ import logging
2
2
  import os
3
3
  import socket
4
4
  import sys
5
+ import urllib.parse
5
6
  from os import getenv
6
7
  from os.path import join
7
- import urllib.parse
8
+
8
9
  import requests
9
10
  import urllib3
10
11
  import yaml
@@ -150,8 +151,7 @@ def upd_secret(id: str, data, repo: str = 'secret'):
150
151
  # check if data is available in config file
151
152
  if id in _config:
152
153
  _config[id] = data
153
- with open(join(_home, _config_file), 'w') as fd:
154
- yaml.safe_dump(_config, fd)
154
+ yaml.safe_dump(_config, open(join(_home, _config_file), 'w'))
155
155
  return 200
156
156
 
157
157
  else:
@@ -0,0 +1,228 @@
1
+ Metadata-Version: 2.4
2
+ Name: get_hc_secrets
3
+ Version: 1.5.24
4
+ Summary: A package to read secrets from Hashicorp vault or from a local file
5
+ Author-email: Xavier Mayeur <xavier@mayeur.be>
6
+ Project-URL: Homepage, https://github.com/xmayeur/getSecrets
7
+ Project-URL: Bug Tracker, https://github.com/xmayeur/getSecrets/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.7
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: pyyaml
15
+ Requires-Dist: requests
16
+ Dynamic: license-file
17
+
18
+ # getSecrets
19
+
20
+ [![Documentation Status](https://readthedocs.org/projects/getsecrets/badge/?version=latest)](https://getsecrets.readthedocs.io/en/latest/?badge=latest)
21
+ [![Python Version](https://img.shields.io/badge/python-3.6+-blue.svg)](https://www.python.org/downloads/)
22
+
23
+ A Python package for securely retrieving secrets from HashiCorp Vault or local configuration files.
24
+
25
+ ## Features
26
+
27
+ - **Simple API**: Easy-to-use functions for retrieving secrets
28
+ - **Flexible Storage**: Works with HashiCorp Vault or local YAML configuration files
29
+ - **Multiple Retrieval Methods**: Get complete secrets, username/password pairs, or list available secrets
30
+ - **Update Support**: Update existing secrets in Vault
31
+ - **Secure by Default**: Automatic certificate validation with intelligent fallback
32
+ - **Repository Support**: Work with multiple secret repositories
33
+
34
+ ## Installation
35
+
36
+ Install from PyPI:
37
+
38
+ ```bash
39
+ pip install get-hc-secrets
40
+ ```
41
+
42
+ Or install from source:
43
+
44
+ ```bash
45
+ git clone https://github.com/yourusername/getSecrets.git
46
+ cd getSecrets
47
+ pip install -e .
48
+ ```
49
+
50
+ ## Quick Start
51
+
52
+ ### Configuration
53
+
54
+ Create a configuration file at `~/.config/.vault/vault.yml`:
55
+
56
+ ```yaml
57
+ vault:
58
+ token: "your-vault-token"
59
+ vault_addr: "https://vault.example.com:8200"
60
+ certs: "~/path/to/bundle.pem"
61
+
62
+ # Optional: Local secrets for development
63
+ local-db:
64
+ host: localhost
65
+ port: 5432
66
+ username: dev_user
67
+ password: dev_password
68
+ ```
69
+
70
+ ### Basic Usage
71
+
72
+ ```python
73
+ from getSecrets import get_secret, get_user_pwd, list_secret, upd_secret
74
+
75
+ # Retrieve a complete secret
76
+ database_config = get_secret('my-database-config')
77
+ print(database_config)
78
+ # {'host': 'db.example.com', 'port': 5432, 'database': 'myapp'}
79
+
80
+ # Retrieve username and password
81
+ username, password = get_user_pwd('postgres-credentials')
82
+
83
+ # List all secrets in a repository
84
+ secrets = list_secret('secret')
85
+ print(secrets)
86
+ # ['database-config', 'api-keys', 'admin-credentials']
87
+
88
+ # Update a secret
89
+ new_data = {'host': 'new-db.example.com', 'port': 5432}
90
+ status = upd_secret('my-database-config', new_data)
91
+ ```
92
+
93
+ ### Working with Custom Repositories
94
+
95
+ ```python
96
+ # Retrieve from a custom repository
97
+ api_keys = get_secret('api-credentials', repo='production-secrets')
98
+
99
+ # Update in custom repository
100
+ upd_secret('api-credentials', new_data, repo='production-secrets')
101
+ ```
102
+
103
+ ## API Reference
104
+
105
+ ### `get_secret(id, repo='secret')`
106
+
107
+ Retrieves a complete secret as a dictionary.
108
+
109
+ **Parameters:**
110
+
111
+ - `id` (str): The ID of the secret to retrieve
112
+ - `repo` (str, optional): The repository name (default: 'secret')
113
+
114
+ **Returns:** `dict` - Key-value pairs from the secret, or empty dict on error
115
+
116
+ ### `get_user_pwd(id, repo='secret')`
117
+
118
+ Retrieves username and password from a secret.
119
+
120
+ **Parameters:**
121
+
122
+ - `id` (str): The ID of the secret to retrieve
123
+ - `repo` (str, optional): The repository name (default: 'secret')
124
+
125
+ **Returns:** `tuple` - (username, password) or (None, None) if not found
126
+
127
+ ### `list_secret(repo='secret')`
128
+
129
+ Lists all available secret IDs in a repository.
130
+
131
+ **Parameters:**
132
+
133
+ - `repo` (str, optional): The repository name (default: 'secret')
134
+
135
+ **Returns:** `list` - List of secret IDs
136
+
137
+ ### `upd_secret(id, data, repo='secret')`
138
+
139
+ Updates an existing secret with new data.
140
+
141
+ **Parameters:**
142
+
143
+ - `id` (str): The ID of the secret to update
144
+ - `data` (dict): The new data to store
145
+ - `repo` (str, optional): The repository name (default: 'secret')
146
+
147
+ **Returns:** `int` - HTTP status code (200 on success)
148
+
149
+ ## Certificate Configuration
150
+
151
+ For secure communication with Vault, create a `bundle.pem` file containing (in order):
152
+
153
+ 1. Vault certificate
154
+ 2. Intermediate certificate
155
+ 3. Root certificate
156
+
157
+ **Note:**
158
+
159
+ - For public networks: The package automatically uses system certificates via certifi
160
+ - For internal networks (192.168.x.x): Custom certificates from config are used
161
+ - If no certificates are found: Works in insecure mode (not recommended for production)
162
+
163
+ ## Configuration File Locations
164
+
165
+ The package searches for configuration in the following order:
166
+
167
+ 1. `~/.config/.vault/vault.yml`
168
+ 2. `/etc/vault/vault.yml`
169
+
170
+ ## Documentation
171
+
172
+ Full documentation is available at: [https://getsecrets.readthedocs.io](https://getsecrets.readthedocs.io)
173
+
174
+ ## Examples
175
+
176
+ ### Database Connection
177
+
178
+ ```python
179
+ import psycopg2
180
+ from getSecrets import get_secret
181
+
182
+ db_config = get_secret('postgres-production')
183
+
184
+ connection = psycopg2.connect(
185
+ host=db_config['host'],
186
+ port=db_config.get('port', 5432),
187
+ database=db_config['database'],
188
+ user=db_config['username'],
189
+ password=db_config['password']
190
+ )
191
+ ```
192
+
193
+ ### API Authentication
194
+
195
+ ```python
196
+ import requests
197
+ from getSecrets import get_secret
198
+
199
+ api_config = get_secret('external-api', repo='api-secrets')
200
+
201
+ headers = {
202
+ 'Authorization': f"Bearer {api_config['api_token']}"
203
+ }
204
+
205
+ response = requests.get(api_config['api_url'], headers=headers)
206
+ ```
207
+
208
+ ## Development
209
+
210
+ To build the documentation locally:
211
+
212
+ ```bash
213
+ cd docs
214
+ pip install -r requirements.txt
215
+ make html
216
+ ```
217
+
218
+ ## License
219
+
220
+ [Your License Here]
221
+
222
+ ## Contributing
223
+
224
+ Contributions are welcome! Please feel free to submit a Pull Request.
225
+
226
+ ## Version
227
+
228
+ Current version: 1.5.23
@@ -0,0 +1,6 @@
1
+ getSecrets/__init__.py,sha256=TlrhsRGuz5K06WdGK-7I6vMj3scD6xOufkK8OIoWkU8,6624
2
+ get_hc_secrets-1.5.24.dist-info/licenses/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
3
+ get_hc_secrets-1.5.24.dist-info/METADATA,sha256=erE6g1gt5hdrgcJSwSojNquHBODCZXyJYlh901ia3GQ,5675
4
+ get_hc_secrets-1.5.24.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
5
+ get_hc_secrets-1.5.24.dist-info/top_level.txt,sha256=X_v6_cB4900TWZoDSDtFDhZrxKcH4dJiPCIAcyL5Z7k,11
6
+ get_hc_secrets-1.5.24.dist-info/RECORD,,
@@ -1,58 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: get_hc_secrets
3
- Version: 1.5.23
4
- Summary: A package to read secrets from Hashicorp vault or from a local file
5
- Author-email: Xavier Mayeur <xavier@mayeur.be>
6
- Project-URL: Homepage, https://github.com/xmayeur/getSecrets
7
- Project-URL: Bug Tracker, https://github.com/xmayeur/getSecrets/issues
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.7
12
- Description-Content-Type: text/markdown
13
- License-File: LICENSE
14
- Requires-Dist: pyyaml
15
- Requires-Dist: requests
16
- Dynamic: license-file
17
-
18
- # getSecrets package
19
-
20
- getSecrets is a simple package that reads from the given engine ('secret' by default) of a Hashicorp vault
21
- It can also read data from the local vault.yml file
22
-
23
- usage:
24
-
25
- ```
26
- from getSecrets import *
27
-
28
- data = get_secret(<id>, [repo:<secret>])
29
-
30
- usr, pwd = get_user_pwd(<id> , [repo:<secret>])
31
-
32
- updater = update_secret(<id>, <new_object>, [repo:<secret>])
33
-
34
- list = list_secret([<secret>]
35
-
36
- ```
37
-
38
- Vault parameters are stored in a config file ~/.config/.vault/.vault.yml
39
-
40
- ```
41
- vault:
42
- token: "<access token>"
43
- vault_addr: "https://vault:8200"
44
- certs: "<path>/bundle.pem"
45
-
46
- id:
47
- item1: 1
48
- item2: 2
49
- username: user
50
- password: !@•?
51
- ```
52
-
53
- for reminder:
54
- bundle.pem, for own certificates, is made of, in this order:
55
-
56
- - vault certificate
57
- - intermediate certificate
58
- - root certificate
@@ -1,6 +0,0 @@
1
- getSecrets/__init__.py,sha256=k7x_Z4c9jfKoVEQmoTP3_4dHyX4YTEB1afYGJDKhiDc,6650
2
- get_hc_secrets-1.5.23.dist-info/licenses/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
3
- get_hc_secrets-1.5.23.dist-info/METADATA,sha256=M2mk3xBS-_3fa_pZOXhxbjHY8p3V6yt-zLHMb5W5nnQ,1410
4
- get_hc_secrets-1.5.23.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
5
- get_hc_secrets-1.5.23.dist-info/top_level.txt,sha256=X_v6_cB4900TWZoDSDtFDhZrxKcH4dJiPCIAcyL5Z7k,11
6
- get_hc_secrets-1.5.23.dist-info/RECORD,,