get-hc-secrets 1.5.0__tar.gz → 1.5.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: get_hc_secrets
3
- Version: 1.5.0
3
+ Version: 1.5.2
4
4
  Summary: A package to read secrets from Hashicorp vault
5
5
  Home-page: https://github.com/xmayeur/getSecrets
6
6
  Author: Xavier Mayeur
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: get_hc_secrets
3
- Version: 1.5.0
3
+ Version: 1.5.2
4
4
  Summary: A package to read secrets from Hashicorp vault
5
5
  Home-page: https://github.com/xmayeur/getSecrets
6
6
  Author: Xavier Mayeur
@@ -6,6 +6,4 @@ get_hc_secrets.egg-info/PKG-INFO
6
6
  get_hc_secrets.egg-info/SOURCES.txt
7
7
  get_hc_secrets.egg-info/dependency_links.txt
8
8
  get_hc_secrets.egg-info/requires.txt
9
- get_hc_secrets.egg-info/top_level.txt
10
- src/__init__.py
11
- src/get_secrets.py
9
+ get_hc_secrets.egg-info/top_level.txt
@@ -2,8 +2,8 @@ from setuptools import setup
2
2
 
3
3
  setup(
4
4
  name='get_hc_secrets',
5
- version='1.5.0',
6
- packages=['src'],
5
+ version='1.5.2',
6
+ packages=[],
7
7
  url='https://github.com/xmayeur/getSecrets',
8
8
  license='',
9
9
  author='Xavier Mayeur',
File without changes
@@ -1,136 +0,0 @@
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
File without changes
File without changes
File without changes