11 Commits
0.0.1 ... 0.0.9

Author SHA1 Message Date
f960d43543 depth is important maybe? 2021-03-24 11:16:02 +01:00
35f3e33cfd idk man 2021-03-24 09:52:27 +01:00
afd725d5b4 if you change your config files to use the new dir, don't forget to actually set up the new dir 2021-03-24 09:43:51 +01:00
b2c7772ca1 imports werken niet voor een of andere reden :( 2021-03-24 09:40:44 +01:00
5fd9987486 versioning fix :) 2021-03-23 13:48:56 +01:00
ed19d7468f todooooo 2021-03-23 13:25:04 +01:00
7e6cfab28e toch geen verbose :) 2021-03-23 13:23:00 +01:00
d8886090f6 verbose upload 2021-03-23 13:20:53 +01:00
f6550a28bb ok, now we use testpypi 2021-03-23 13:16:59 +01:00
b4a378d6e0 Merge remote-tracking branch 'origin/master' 2021-03-23 13:04:38 +01:00
7e356263b2 github actions test 2 :) 2021-03-23 13:02:43 +01:00
7 changed files with 94 additions and 5 deletions

View File

@@ -28,4 +28,4 @@ jobs:
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
twine upload --repository testpypi dist/*

3
TODO.md Normal file
View File

@@ -0,0 +1,3 @@
# TODO
1: add proper versioning (usage of tags during publish pipeline)

View File

@@ -4,8 +4,10 @@ with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setuptools.setup(
name="vaultdatabaseengine-bvanroll", # Replace with your own username
name="VaultDb",
version="0.0.1",
version_config=True,
setup_requires=['setuptools-git-versioning'],
author="Beppe Vanrolleghem",
author_email="beppe.vanrolleghem@gmail.com",
description="A vault creds reader for the vault database engine",
@@ -20,7 +22,7 @@ setuptools.setup(
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
package_dir={"": "src"},
packages=setuptools.find_packages(where="src"),
package_dir={"": "VaultDb"},
packages=setuptools.find_packages(where="VaultDb"),
python_requires=">=3.6",
)
)

48
src/VaultDb/__main__.py Normal file
View File

@@ -0,0 +1,48 @@
import requests as rq
import datetime as dt
class Database2:
def __init__(self, dbname, vault_url, token, vault_port=8200):
self.dbname = dbname
self.url = vault_url + ":" + str(vault_port) + "/v1/database/creds/" + dbname
self.lastReq = None #TODO some datetime in here
self.ttl = None
self.token = token
self.username = ""
self.password = ""
self.get_creds()
def check_valid(self):
#TODO check datetime for current datetime
if self.ttl == None:
return False
return True
def update_creds(self):
r = rq.get(url=self.url, headers={"X-Vault-Token": self.token, "Content-Type": "application/json"})
# print(r.status_code)
# print(r.text)
if r.status_code != 200:
raise Exception("status code was nog 200")
data = r.json()
# TODO set datetime for current datetime
# TODO set these to the correct response values
self.username = data["data"]["username"]
self.password = data["data"]["password"]
self.lease_id = data["lease_id"]
self.request_id = data["request_id"]
self.wrap_info = data["wrap_info"]
self.warnings = data["warnings"]
self.auth = data["auth"]
self.ttl = dt.datetime.now() + dt.timedelta(seconds=float(data["lease_duration"]))
def get_creds(self):
if not (self.check_valid()):
self.update_creds()
return {"username": self.username, "password": self.password}
def get_username(self):
if not (self.check_valid()):
self.update_creds()
return self.username

36
test/database.py Normal file
View File

@@ -0,0 +1,36 @@
import unittest
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
import src
class MyTestCase(unittest.TestCase):
def test_psql(self):
#TODO exec psql connect
print("hi")
test = src.Database()
test.check_valid()
self.assertEqual(test.valid, False)
def test_psql_invalid_vault_url(self):
#TODO figure out how to fail unit test check
try:
src.Database(dbname="sdfk", vault_url="localhost", vault_port=8200, token="bla")
except:
print("did it")
return
def test_psql_invalid_vault_port(self):
try:
src.Database(dbname="sdfk", vault_url="localhost", vault_port="a", token="bla")
except:
return
def test_psql_valid(self):
print(src.Database(dbname="psql", vault_url="http://localhost", token="s.GoR2nisHPeKU1vOaw9hZ5L7h").get_creds())
if __name__ == '__main__':
unittest.main()