containers: get mysql creds
This commit is contained in:
parent
62075c2b6d
commit
8c0d7aaa58
|
@ -12,7 +12,6 @@ class Container:
|
||||||
|
|
||||||
def __init__(self, data: dict):
|
def __init__(self, data: dict):
|
||||||
self._data = data
|
self._data = data
|
||||||
|
|
||||||
self._state = data.get('State')
|
self._state = data.get('State')
|
||||||
self._config = data.get('Config')
|
self._config = data.get('Config')
|
||||||
self._mounts = [Mount(mnt, container=self) for mnt in data.get('Mounts')]
|
self._mounts = [Mount(mnt, container=self) for mnt in data.get('Mounts')]
|
||||||
|
@ -45,10 +44,16 @@ class Container:
|
||||||
return self.get_config('Image')
|
return self.get_config('Image')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def environment(self) -> dict:
|
def environment(self) -> list:
|
||||||
"""All configured env vars for the container"""
|
"""All configured env vars for the container as a list"""
|
||||||
return self.get_config('Env', default=[])
|
return self.get_config('Env', default=[])
|
||||||
|
|
||||||
|
def get_config_env(self, name) -> str:
|
||||||
|
"""Get a config environment variable by name"""
|
||||||
|
# convert to dict and fetch env var by name
|
||||||
|
data = {i[0:i.find('=')]: i[i.find('=')+1:] for i in self.environment}
|
||||||
|
return data.get(name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def volumes(self) -> dict:
|
def volumes(self) -> dict:
|
||||||
"""
|
"""
|
||||||
|
@ -160,6 +165,14 @@ class Container:
|
||||||
|
|
||||||
return volumes
|
return volumes
|
||||||
|
|
||||||
|
def get_mysql_credentials(self):
|
||||||
|
return {
|
||||||
|
'host': self.hostname,
|
||||||
|
'username': self.get_config_env('MYSQL_USER'),
|
||||||
|
'password': self.get_config_env('MYSQL_PASSWORD'),
|
||||||
|
'port': "3306",
|
||||||
|
}
|
||||||
|
|
||||||
def _parse_pattern(self, value):
|
def _parse_pattern(self, value):
|
||||||
if not value:
|
if not value:
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Reference in New Issue