get-hc-secrets 1.5.23__tar.gz → 1.5.24__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.
@@ -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,211 @@
1
+ # getSecrets
2
+
3
+ [![Documentation Status](https://readthedocs.org/projects/getsecrets/badge/?version=latest)](https://getsecrets.readthedocs.io/en/latest/?badge=latest)
4
+ [![Python Version](https://img.shields.io/badge/python-3.6+-blue.svg)](https://www.python.org/downloads/)
5
+
6
+ A Python package for securely retrieving secrets from HashiCorp Vault or local configuration files.
7
+
8
+ ## Features
9
+
10
+ - **Simple API**: Easy-to-use functions for retrieving secrets
11
+ - **Flexible Storage**: Works with HashiCorp Vault or local YAML configuration files
12
+ - **Multiple Retrieval Methods**: Get complete secrets, username/password pairs, or list available secrets
13
+ - **Update Support**: Update existing secrets in Vault
14
+ - **Secure by Default**: Automatic certificate validation with intelligent fallback
15
+ - **Repository Support**: Work with multiple secret repositories
16
+
17
+ ## Installation
18
+
19
+ Install from PyPI:
20
+
21
+ ```bash
22
+ pip install get-hc-secrets
23
+ ```
24
+
25
+ Or install from source:
26
+
27
+ ```bash
28
+ git clone https://github.com/yourusername/getSecrets.git
29
+ cd getSecrets
30
+ pip install -e .
31
+ ```
32
+
33
+ ## Quick Start
34
+
35
+ ### Configuration
36
+
37
+ Create a configuration file at `~/.config/.vault/vault.yml`:
38
+
39
+ ```yaml
40
+ vault:
41
+ token: "your-vault-token"
42
+ vault_addr: "https://vault.example.com:8200"
43
+ certs: "~/path/to/bundle.pem"
44
+
45
+ # Optional: Local secrets for development
46
+ local-db:
47
+ host: localhost
48
+ port: 5432
49
+ username: dev_user
50
+ password: dev_password
51
+ ```
52
+
53
+ ### Basic Usage
54
+
55
+ ```python
56
+ from getSecrets import get_secret, get_user_pwd, list_secret, upd_secret
57
+
58
+ # Retrieve a complete secret
59
+ database_config = get_secret('my-database-config')
60
+ print(database_config)
61
+ # {'host': 'db.example.com', 'port': 5432, 'database': 'myapp'}
62
+
63
+ # Retrieve username and password
64
+ username, password = get_user_pwd('postgres-credentials')
65
+
66
+ # List all secrets in a repository
67
+ secrets = list_secret('secret')
68
+ print(secrets)
69
+ # ['database-config', 'api-keys', 'admin-credentials']
70
+
71
+ # Update a secret
72
+ new_data = {'host': 'new-db.example.com', 'port': 5432}
73
+ status = upd_secret('my-database-config', new_data)
74
+ ```
75
+
76
+ ### Working with Custom Repositories
77
+
78
+ ```python
79
+ # Retrieve from a custom repository
80
+ api_keys = get_secret('api-credentials', repo='production-secrets')
81
+
82
+ # Update in custom repository
83
+ upd_secret('api-credentials', new_data, repo='production-secrets')
84
+ ```
85
+
86
+ ## API Reference
87
+
88
+ ### `get_secret(id, repo='secret')`
89
+
90
+ Retrieves a complete secret as a dictionary.
91
+
92
+ **Parameters:**
93
+
94
+ - `id` (str): The ID of the secret to retrieve
95
+ - `repo` (str, optional): The repository name (default: 'secret')
96
+
97
+ **Returns:** `dict` - Key-value pairs from the secret, or empty dict on error
98
+
99
+ ### `get_user_pwd(id, repo='secret')`
100
+
101
+ Retrieves username and password from a secret.
102
+
103
+ **Parameters:**
104
+
105
+ - `id` (str): The ID of the secret to retrieve
106
+ - `repo` (str, optional): The repository name (default: 'secret')
107
+
108
+ **Returns:** `tuple` - (username, password) or (None, None) if not found
109
+
110
+ ### `list_secret(repo='secret')`
111
+
112
+ Lists all available secret IDs in a repository.
113
+
114
+ **Parameters:**
115
+
116
+ - `repo` (str, optional): The repository name (default: 'secret')
117
+
118
+ **Returns:** `list` - List of secret IDs
119
+
120
+ ### `upd_secret(id, data, repo='secret')`
121
+
122
+ Updates an existing secret with new data.
123
+
124
+ **Parameters:**
125
+
126
+ - `id` (str): The ID of the secret to update
127
+ - `data` (dict): The new data to store
128
+ - `repo` (str, optional): The repository name (default: 'secret')
129
+
130
+ **Returns:** `int` - HTTP status code (200 on success)
131
+
132
+ ## Certificate Configuration
133
+
134
+ For secure communication with Vault, create a `bundle.pem` file containing (in order):
135
+
136
+ 1. Vault certificate
137
+ 2. Intermediate certificate
138
+ 3. Root certificate
139
+
140
+ **Note:**
141
+
142
+ - For public networks: The package automatically uses system certificates via certifi
143
+ - For internal networks (192.168.x.x): Custom certificates from config are used
144
+ - If no certificates are found: Works in insecure mode (not recommended for production)
145
+
146
+ ## Configuration File Locations
147
+
148
+ The package searches for configuration in the following order:
149
+
150
+ 1. `~/.config/.vault/vault.yml`
151
+ 2. `/etc/vault/vault.yml`
152
+
153
+ ## Documentation
154
+
155
+ Full documentation is available at: [https://getsecrets.readthedocs.io](https://getsecrets.readthedocs.io)
156
+
157
+ ## Examples
158
+
159
+ ### Database Connection
160
+
161
+ ```python
162
+ import psycopg2
163
+ from getSecrets import get_secret
164
+
165
+ db_config = get_secret('postgres-production')
166
+
167
+ connection = psycopg2.connect(
168
+ host=db_config['host'],
169
+ port=db_config.get('port', 5432),
170
+ database=db_config['database'],
171
+ user=db_config['username'],
172
+ password=db_config['password']
173
+ )
174
+ ```
175
+
176
+ ### API Authentication
177
+
178
+ ```python
179
+ import requests
180
+ from getSecrets import get_secret
181
+
182
+ api_config = get_secret('external-api', repo='api-secrets')
183
+
184
+ headers = {
185
+ 'Authorization': f"Bearer {api_config['api_token']}"
186
+ }
187
+
188
+ response = requests.get(api_config['api_url'], headers=headers)
189
+ ```
190
+
191
+ ## Development
192
+
193
+ To build the documentation locally:
194
+
195
+ ```bash
196
+ cd docs
197
+ pip install -r requirements.txt
198
+ make html
199
+ ```
200
+
201
+ ## License
202
+
203
+ [Your License Here]
204
+
205
+ ## Contributing
206
+
207
+ Contributions are welcome! Please feel free to submit a Pull Request.
208
+
209
+ ## Version
210
+
211
+ Current version: 1.5.23
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "get_hc_secrets"
3
- version = '1.5.23'
3
+ version = '1.5.24'
4
4
  authors = [
5
5
  { name = "Xavier Mayeur", email = "xavier@mayeur.be" }
6
6
  ]
@@ -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
@@ -7,4 +7,5 @@ src/get_hc_secrets.egg-info/SOURCES.txt
7
7
  src/get_hc_secrets.egg-info/dependency_links.txt
8
8
  src/get_hc_secrets.egg-info/requires.txt
9
9
  src/get_hc_secrets.egg-info/top_level.txt
10
- tests/test_getsecrets.py
10
+ tests/test_getsecrets.py
11
+ tests/test_getsecrets_comprehensive.py