get-hc-secrets 1.5.3__tar.gz → 1.5.5__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.
- {get_hc_secrets-1.5.3 → get_hc_secrets-1.5.5}/PKG-INFO +1 -3
- {get_hc_secrets-1.5.3 → get_hc_secrets-1.5.5}/pyproject.toml +1 -1
- get_hc_secrets-1.5.5/src/__init__.py +0 -0
- get_hc_secrets-1.5.5/src/get_hc_secrets/__init__.py +0 -0
- get_hc_secrets-1.5.5/src/get_hc_secrets/get_secrets.py +136 -0
- {get_hc_secrets-1.5.3 → get_hc_secrets-1.5.5/src}/get_hc_secrets.egg-info/PKG-INFO +1 -3
- get_hc_secrets-1.5.5/src/get_hc_secrets.egg-info/SOURCES.txt +11 -0
- get_hc_secrets-1.5.5/src/get_hc_secrets.egg-info/top_level.txt +2 -0
- get_hc_secrets-1.5.3/get_hc_secrets.egg-info/SOURCES.txt +0 -9
- get_hc_secrets-1.5.3/get_hc_secrets.egg-info/top_level.txt +0 -1
- get_hc_secrets-1.5.3/setup.py +0 -12
- {get_hc_secrets-1.5.3 → get_hc_secrets-1.5.5}/LICENSE +0 -0
- {get_hc_secrets-1.5.3 → get_hc_secrets-1.5.5}/README.md +0 -0
- {get_hc_secrets-1.5.3 → get_hc_secrets-1.5.5}/setup.cfg +0 -0
- {get_hc_secrets-1.5.3 → get_hc_secrets-1.5.5/src}/get_hc_secrets.egg-info/dependency_links.txt +0 -0
- {get_hc_secrets-1.5.3 → get_hc_secrets-1.5.5/src}/get_hc_secrets.egg-info/requires.txt +0 -0
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: get_hc_secrets
|
|
3
|
-
Version: 1.5.
|
|
3
|
+
Version: 1.5.5
|
|
4
4
|
Summary: A package to read secrets from Hashicorp vault
|
|
5
|
-
Home-page: https://github.com/xmayeur/getSecrets
|
|
6
|
-
Author: Xavier Mayeur
|
|
7
5
|
Author-email: Xavier Mayeur <xavier@mayeur.be>
|
|
8
6
|
Project-URL: Homepage, https://github.com/xmayeur/getSecrets
|
|
9
7
|
Project-URL: Bug Tracker, https://github.com/xmayeur/getSecrets/issues
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from os import getenv
|
|
3
|
+
from os.path import join
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
import yaml
|
|
7
|
+
|
|
8
|
+
_config_file = "~/.config/.vault/vault.yml"
|
|
9
|
+
_home = getenv("HOME")
|
|
10
|
+
_config = yaml.safe_load(open(join(_home, _config_file.replace("~/", ''))))
|
|
11
|
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s',
|
|
12
|
+
datefmt='%m/%d/%Y %I:%M:%S %p')
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def get_secret(id: str, repo: str = 'secret') -> dict:
|
|
16
|
+
"""
|
|
17
|
+
:param id: The ID of the secret to retrieve
|
|
18
|
+
:param repo: The name of the secrets repository to retrieve the secret from - defaults to 'secret'
|
|
19
|
+
:return: a json object with key/value pairs
|
|
20
|
+
or an empty object if the secret retrieval fails
|
|
21
|
+
|
|
22
|
+
This method retrieves a secret from a Vault server using the provided ID.
|
|
23
|
+
If the request is successful (status code 200), the method extracts the key-value pairs JSON object.
|
|
24
|
+
If the request fails, the method logs an HTTP error message and returns a n empty json {}.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
base_url = _config['vault']['vault_addr']
|
|
28
|
+
certs = join(_home, _config['vault']['certs'].replace("~/", ''))
|
|
29
|
+
token = _config['vault']['token']
|
|
30
|
+
|
|
31
|
+
headers = {"X-Vault-Token": token}
|
|
32
|
+
uri = f"/v1/{repo}/data/"
|
|
33
|
+
url = f"{base_url}{uri}{id}"
|
|
34
|
+
resp = requests.get(url, headers=headers, verify=certs)
|
|
35
|
+
if resp.status_code == 200:
|
|
36
|
+
secret = resp.json()["data"]["data"]
|
|
37
|
+
return secret
|
|
38
|
+
|
|
39
|
+
else:
|
|
40
|
+
print(f"http error {resp.status_code}")
|
|
41
|
+
logging.error(f"Vault api error {resp}")
|
|
42
|
+
return {}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def get_user_pwd(id: str, repo: str = 'secret') -> tuple:
|
|
46
|
+
"""
|
|
47
|
+
:param id: The ID of the secret to retrieve
|
|
48
|
+
:param repo: The name of the secret repository to retrieve the seret from - defaults to 'secret'
|
|
49
|
+
:return: a tuple username, password values if the secrets has such keys, else None, None
|
|
50
|
+
|
|
51
|
+
This method retrieves a secret from a Vault server using the provided ID.
|
|
52
|
+
If the request is successful (status code 200), the method extracts the username and password key value
|
|
53
|
+
if such keys exist.
|
|
54
|
+
If the request fails, the method prints an HTTP error message and returns (None, None).
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
base_url = _config['vault']['vault_addr']
|
|
58
|
+
certs = join(_home, _config['vault']['certs'].replace("~/", ''))
|
|
59
|
+
token = _config['vault']['token']
|
|
60
|
+
|
|
61
|
+
headers = {"X-Vault-Token": token}
|
|
62
|
+
uri = f"/v1/{repo}/data/"
|
|
63
|
+
url = f"{base_url}{uri}{id}"
|
|
64
|
+
resp = requests.get(url, headers=headers, verify=certs)
|
|
65
|
+
if resp.status_code == 200:
|
|
66
|
+
secret = resp.json()["data"]["data"]
|
|
67
|
+
if 'username' in secret and 'password' in secret:
|
|
68
|
+
return secret['username'], secret['password']
|
|
69
|
+
else:
|
|
70
|
+
return None, None
|
|
71
|
+
|
|
72
|
+
else:
|
|
73
|
+
print(f"http error {resp.status_code}")
|
|
74
|
+
logging.error(f"Vault api error {resp}")
|
|
75
|
+
return None, None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def list_secret(repo: str = 'secret'):
|
|
79
|
+
"""
|
|
80
|
+
:param repo: The name of a secret repository to retrieve the secret from - defaults to 'secret'
|
|
81
|
+
:return: A list containing all items keys from the repository
|
|
82
|
+
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
base_url = _config['vault']['vault_addr']
|
|
86
|
+
certs = join(_home, _config['vault']['certs'].replace("~/", ''))
|
|
87
|
+
token = _config['vault']['token']
|
|
88
|
+
|
|
89
|
+
headers = {"X-Vault-Token": token}
|
|
90
|
+
uri = f"/v1/{repo}/metadata"
|
|
91
|
+
url = f"{base_url}{uri}"
|
|
92
|
+
resp = requests.request('LIST', url, headers=headers, verify=certs)
|
|
93
|
+
if resp.status_code == 200:
|
|
94
|
+
return resp.json()["data"]["keys"]
|
|
95
|
+
|
|
96
|
+
else:
|
|
97
|
+
print(f"http error {resp.status_code}")
|
|
98
|
+
logging.error(f"Vault api error {resp}")
|
|
99
|
+
return None, None
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def upd_secret(id: str, data, repo: str = 'secret'):
|
|
103
|
+
"""
|
|
104
|
+
:param id: The ID of the secret to retrieve
|
|
105
|
+
:param data: The data to be uploaded in place of the exitisting one
|
|
106
|
+
:param repo: The name of the repository to retrieve the secret from - defaults to 'secret'
|
|
107
|
+
:return: the response status code from the vault - 200 if successful.
|
|
108
|
+
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
base_url = _config['vault']['vault_addr']
|
|
112
|
+
certs = join(_home, _config['vault']['certs'].replace("~/", ''))
|
|
113
|
+
token = _config['vault']['token']
|
|
114
|
+
|
|
115
|
+
headers = {"X-Vault-Token": token}
|
|
116
|
+
uri = f"/v1/{repo}/data/"
|
|
117
|
+
url = f"{base_url}{uri}{id}"
|
|
118
|
+
resp = requests.request('GET', url, headers=headers, verify=certs)
|
|
119
|
+
if resp.status_code == 200:
|
|
120
|
+
version = resp.json()["data"]['metadata']['version']
|
|
121
|
+
obj = {
|
|
122
|
+
"options": {
|
|
123
|
+
"cas": version
|
|
124
|
+
},
|
|
125
|
+
"data": data
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
resp2 = requests.request('POST', url, headers=headers, json=obj, verify=certs)
|
|
129
|
+
if resp2.status_code != 200:
|
|
130
|
+
logging.warning(f"Vault update error for {id} with new {data}")
|
|
131
|
+
return resp2.status_code
|
|
132
|
+
|
|
133
|
+
else:
|
|
134
|
+
print(f"http error {resp.status_code}")
|
|
135
|
+
logging.error(f"Vault api error {resp}")
|
|
136
|
+
return None, None
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: get_hc_secrets
|
|
3
|
-
Version: 1.5.
|
|
3
|
+
Version: 1.5.5
|
|
4
4
|
Summary: A package to read secrets from Hashicorp vault
|
|
5
|
-
Home-page: https://github.com/xmayeur/getSecrets
|
|
6
|
-
Author: Xavier Mayeur
|
|
7
5
|
Author-email: Xavier Mayeur <xavier@mayeur.be>
|
|
8
6
|
Project-URL: Homepage, https://github.com/xmayeur/getSecrets
|
|
9
7
|
Project-URL: Bug Tracker, https://github.com/xmayeur/getSecrets/issues
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/__init__.py
|
|
5
|
+
src/get_hc_secrets/__init__.py
|
|
6
|
+
src/get_hc_secrets/get_secrets.py
|
|
7
|
+
src/get_hc_secrets.egg-info/PKG-INFO
|
|
8
|
+
src/get_hc_secrets.egg-info/SOURCES.txt
|
|
9
|
+
src/get_hc_secrets.egg-info/dependency_links.txt
|
|
10
|
+
src/get_hc_secrets.egg-info/requires.txt
|
|
11
|
+
src/get_hc_secrets.egg-info/top_level.txt
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
get_hc_secrets-1.5.3/setup.py
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
from setuptools import setup
|
|
2
|
-
|
|
3
|
-
setup(
|
|
4
|
-
name='get_hc_secrets',
|
|
5
|
-
version='1.5.3',
|
|
6
|
-
packages=[],
|
|
7
|
-
url='https://github.com/xmayeur/getSecrets',
|
|
8
|
-
license='',
|
|
9
|
-
author='Xavier Mayeur',
|
|
10
|
-
author_email='xavier@mayeur.be',
|
|
11
|
-
description='A package to read secrets from Hashicorp vault'
|
|
12
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{get_hc_secrets-1.5.3 → get_hc_secrets-1.5.5/src}/get_hc_secrets.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|