From: Frank Brehm Date: Mon, 6 Sep 2021 14:15:32 +0000 (+0200) Subject: Asking for vSphere user credentials, if they are not configured X-Git-Tag: 1.5.2^2~25 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=ab44e7c3e6c9ef28d4d891bce2f23a6d5aac4b07;p=pixelpark%2Fcreate-terraform.git Asking for vSphere user credentials, if they are not configured --- diff --git a/lib/cr_tf/app.py b/lib/cr_tf/app.py index 7836f8e..d597af4 100644 --- a/lib/cr_tf/app.py +++ b/lib/cr_tf/app.py @@ -29,6 +29,7 @@ from fb_tools.common import pp from fb_tools.app import BaseApplication from fb_tools.errors import ExpectedHandlerError, CommandNotFoundError +from fb_tools.errors import TerraformHandlerError, TerraformVSphereError from fb_tools.config import ConfigError @@ -45,7 +46,7 @@ from .xlate import __base_dir__ as __xlate_base_dir__ from .xlate import __mo_file__ as __xlate_mo_file__ from .xlate import XLATOR, LOCALE_DIR, DOMAIN -__version__ = '1.1.6' +__version__ = '1.1.7' LOG = logging.getLogger(__name__) SIGNAL_NAMES = { @@ -326,9 +327,6 @@ class CrTfApplication(BaseApplication): simulate=self.simulate, force=self.force, config=self.config, terminal_has_colors=self.terminal_has_colors) - self.handler.get_secret = self.get_secret - self.handler.exit = self.exit - if self.args.stop_after: self.handler.stop_at_step = self.args.stop_after @@ -486,12 +484,52 @@ class CrTfApplication(BaseApplication): a=self.appname, v=__pkg_version__)) try: - self.handler(self.yaml_file) + if self.handler.first_call(yaml_file): + self.verify_vsphere_credentials() + self.handler(self.yaml_file) except ExpectedHandlerError as e: self.handler = None self.handle_error(str(e), _("Create Terraform environment")) self.exit(5) + # ------------------------------------------------------------------------- + def verify_vsphere_credentials(self): + + if not self.handler: + raise TerraformHandlerError(_("No handler object available.")) + + if not self.handler.vsphere_user: + + msg = '\n' + _("Please input the {}:").format(self.colored( + _('vSphere user name'), 'AQUA')) + print(msg) + self.handler.vsphere_user = input(_('vSphere user name') + ': ') + if not self.handler.vsphere_user: + msg = _("No {} given.").format(_('vSphere user name')) + raise ExpectedHandlerError(msg) + + for vname in self.handler.vsphere.keys(): + LOG.debug(_("Setting user for vSphere {vs!r} to {usr!r}.").format( + vs=vname, usr=self.handler.vsphere_user)) + # Dirty, but else a change of fb_tools would be necessary (later) + self.handler.vsphere[vname]._user = self.handler.vsphere_user + + if not self.handler.vsphere_password: + + prompt = _("User password") + item = _('Password for user {u!r} of vSphere {n} on {h!r}').format( + u=vsphere_user, n=vname, h=self.config.vsphere[vname].host) + self.handler.vsphere_password = self.get_secret(prompt=prompt, item_name=item) + if not self.handler.vsphere_password: + msg = _("No {} given.").format(_('password of vSphere user')) + raise ExpectedHandlerError(msg) + + for vname in self.handler.vsphere.keys(): + LOG.debug(_("Setting passwort of vSphere {vs!r} user {usr!r}.").format( + vs=vname, usr=self.handler.vsphere_user)) + # Dirty, but else a change of fb_tools would be necessary (later) + self.handler.vsphere[vname]._password = self.handler.vsphere_password + # ------------------------------------------------------------------------- def post_run(self): """ diff --git a/lib/cr_tf/handler.py b/lib/cr_tf/handler.py index ed45dc4..551b04a 100644 --- a/lib/cr_tf/handler.py +++ b/lib/cr_tf/handler.py @@ -67,7 +67,7 @@ from .terraform.disk import TerraformDisk from .xlate import XLATOR -__version__ = '3.5.3' +__version__ = '3.5.4' LOG = logging.getLogger(__name__) _ = XLATOR.gettext