From c506500936bf70cd3904840d87e9cf7c6fca5fbe Mon Sep 17 00:00:00 2001 From: jem Date: Sat, 11 Apr 2020 15:12:02 +0200 Subject: [PATCH] make gopass yml syntax accessable --- build.py | 2 +- src/main/python/ddadevops/__init__.py | 2 +- src/main/python/ddadevops/credential.py | 22 +++++++++++++++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/build.py b/build.py index 23fe6b1..715f859 100644 --- a/build.py +++ b/build.py @@ -28,7 +28,7 @@ use_plugin("python.distutils") default_task = "publish" name = "ddadevops" -version = "0.5.0.dev1" +version = "0.5.0.dev2" summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud" description = __doc__ authors = [Author("meissa GmbH", "buero@meissa-gmbh.de")] diff --git a/src/main/python/ddadevops/__init__.py b/src/main/python/ddadevops/__init__.py index d711bf3..c04ea36 100644 --- a/src/main/python/ddadevops/__init__.py +++ b/src/main/python/ddadevops/__init__.py @@ -4,7 +4,7 @@ terraform, dda-pallet, aws & hetzner-cloud. """ -from .credential import gopass_credential_from_env_path, gopass_credential_from_path +from .credential import gopass_credential_from_env_path, gopass_credential_from_path, gopass_password_from_path, gopass_field_from_path from .devops_build import DevopsBuild, create_devops_build_config, get_devops_build from .devops_terraform_build import WorkaroundTerraform, DevopsTerraformBuild, create_devops_terraform_build_config from .hetzner_mixin import HetznerMixin, add_hetzner_mixin_config diff --git a/src/main/python/ddadevops/credential.py b/src/main/python/ddadevops/credential.py index 5494cad..9effdac 100644 --- a/src/main/python/ddadevops/credential.py +++ b/src/main/python/ddadevops/credential.py @@ -4,17 +4,33 @@ import sys def gopass_credential_from_env_path (env_var): env_path = os.environ.get(env_var, None) - return gopass_credential_from_path(env_path) + return gopass_password_from_path(env_path) def gopass_credential_from_path (path): + return gopass_password_from_path(path) + + +def gopass_field_from_path (path, field): + credential = None + + if path and field: + print('get credential for: ' + path) + if sys.version_info.major == 3: + credential = check_output(['gopass', 'show', path, field], encoding='UTF-8') + else: + credential = check_output(['gopass', 'show', path, field]) + + return credential + +def gopass_password_from_path (path): credential = None if path: print('get credential for: ' + path) if sys.version_info.major == 3: - credential = check_output(['gopass', path], encoding='UTF-8') + credential = check_output(['gopass', 'show', '--password', path], encoding='UTF-8') else: - credential = check_output(['gopass', path]) + credential = check_output(['gopass', 'show', '--password', path]) return credential