i think auth is done.

This commit is contained in:
brent s. 2020-03-29 20:59:00 -04:00
parent 2b9b78d3f9
commit a904f158da
Signed by: bts
GPG Key ID: 8C004C2F93481F6B

View File

@ -27,6 +27,30 @@ class _AuthBase(object):
return(None) return(None)




class _BasicAuthBase(_AuthBase):
name = '_BasicAuthBase'
client = None
username = None
password = None
mount = None

def __init__(self, uri, auth_xml, default_mountpoint = 'userpass', *args, **kwargs):
super().__init__(uri, auth_xml, *args, **kwargs)
self.default_mountpoint = default_mountpoint
self.setCreds()

def setCreds(self):
self.username = self.xml.find('username').text
self.password = self.xml.find('password').text
_mntpt = self.xml.find('mountPoint')
if _mntpt is not None:
self.mount = _mntpt.text
else:
self.mount = self.default_mountpoint
self.client = hvac.Client(url = self.uri)
return(None)


class AppRole(_AuthBase): class AppRole(_AuthBase):
name = 'AppRole' name = 'AppRole'
config_name = 'appRole' config_name = 'appRole'
@ -46,26 +70,15 @@ class AppRole(_AuthBase):
return(None) return(None)




class LDAP(_AuthBase): class LDAP(_BasicAuthBase):
name = 'LDAP' name = 'LDAP'
config_name = 'ldap' config_name = 'ldap'
username = None
password = None
mount = None


def __init__(self, uri, auth_xml, *args, **kwargs): def __init__(self, uri, auth_xml, *args, **kwargs):
super().__init__(uri, auth_xml, *args, **kwargs) super().__init__(uri, auth_xml, default_mountpoint = 'ldap', *args, **kwargs)
self.getClient() self.getClient()


def getClient(self): def getClient(self):
self.username = self.xml.find('username').text
self.password = self.xml.find('password').text
_mntpt = self.xml.find('mountPoint')
if _mntpt is not None:
self.mount = _mntpt.text
else:
self.mount = 'ldap'
self.client = hvac.Client(url = self.uri)
self.client.auth.ldap.login(username = self.username, self.client.auth.ldap.login(username = self.username,
password = self.password, password = self.password,
mount_point = self.mount) mount_point = self.mount)
@ -132,3 +145,19 @@ class Token(_AuthBase):
self.client.token = self.token self.client.token = self.token
self.authCheck() self.authCheck()
return(None) return(None)


class UserPass(_BasicAuthBase):
name = 'UserPass'
config_name = 'userpass'

def __init__(self, uri, auth_xml, *args, **kwargs):
super().__init__(uri, auth_xml, default_mountpoint = 'userpass', *args, **kwargs)
self.getClient()

def getClient(self):
self.client.auth.userpass.login(username = self.username,
password = self.password,
mount_point = self.mount)
self.authCheck()
return(None)