From f9ad7b20f01cbd31c83516ded21be888611284cc Mon Sep 17 00:00:00 2001 From: bvanroll Date: Mon, 22 Mar 2021 13:20:22 +0100 Subject: [PATCH] initial setup of the class --- .gitignore | 2 ++ python-vault-db.toml | 1 + src/python-vault-db/__init__.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/.gitignore b/.gitignore index b6e4761..e4e0ac0 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,5 @@ dmypy.json # Pyre type checker .pyre/ + +.idea \ No newline at end of file diff --git a/python-vault-db.toml b/python-vault-db.toml index b5a3c46..adacb2e 100644 --- a/python-vault-db.toml +++ b/python-vault-db.toml @@ -1,6 +1,7 @@ [build-system] requires = [ "setuptools>=42", + "requests=2.25.1", "wheel" ] build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/src/python-vault-db/__init__.py b/src/python-vault-db/__init__.py index e69de29..3cae3e8 100644 --- a/src/python-vault-db/__init__.py +++ b/src/python-vault-db/__init__.py @@ -0,0 +1,30 @@ +import requests as rq + +class Database: + def __init__(self, dbname, vault_url, token): + self.dbname = dbname + self.url = vault_url + self.valid = False + 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 get_creds(self): + self.check_valid() + if (self.valid): + return {"username": self.username, "password": self.password} + else: + rq.get(url=self.url, headers={"X-Vault-Token":self.token}) + #TODO set datetime for current datetime + #TODO set these to the correct response values + self.username = None + self.password = None \ No newline at end of file