Пример #1
0
def get_credentials(options, environment):
    """ Get credentials or prompt for them from options """
    if options['--username'] or options['--auth']:
        if not options['--username']:
            options['<username>'] = lib.prompt("Please enter the username for %s..." % environment)
        if not options['--password']:
            options['<password>'] = lib.prompt("Please enter the password for %s..." % environment, secret=True)
    return options
Пример #2
0
def get_credentials(options, environment):
    """ Get credentials or prompt for them from options """
    if options['--username'] or options['--auth']:
        if not options['--username']:
            options['<username>'] = lib.prompt("Please enter the username for %s..." % environment)
        if not options['--password']:
            options['<password>'] = lib.prompt("Please enter the password for %s..." % environment, secret=True)
    return options
Пример #3
0
def get_credentials(options, environment):
    """ Get credentials or prompt for them from options """
    if options.username or options.auth:
        if not options.username:
            options.username = lib.prompt("Please enter the username for %s..." % environment)
        if not options.password:
            options.password = lib.prompt("Please enter the password for %s..." % environment, secret=True)
    return options
Пример #4
0
    def get_input(self, key, force=False):
        """ Get the value of <key> if it already exists, or prompt for it if not """
        if key not in self._inputs:
            raise InputException("Key {0} is not a valid input!".format(key))

        if self._inputs[key].prompt:
            prompt = self._inputs[key].prompt
        elif self._inputs[key].is_bool():
            prompt = "{0}?".format(key)
        else:
            prompt = "please enter your {0}".format(key)
        help_text = self._inputs[key].help if hasattr(self._inputs[key], 'help') else None

        if self._inputs[key].value is EMPTY or force:

            default_value = None
            if self._inputs[key].default is not EMPTY:
                default_value = self._inputs[key].default
            if self._inputs[key].value is not EMPTY:
                default_value = self._inputs[key].value

            input_value = EMPTY
            while input_value is EMPTY or input_value == '?':
                if input_value == '?' and help_text:
                    print(help_text)
                input_value = lib.prompt(
                    prompt,
                    default=default_value,
                    bool_type=self._inputs[key].in_type,
                    secret=self._inputs[key].is_secret)
            self._inputs[key].value = input_value

        return self._inputs[key].value
Пример #5
0
    def get_input(self, key, force=False):
        """ Get the value of <key> if it already exists, or prompt for it if not """
        if key not in self._inputs:
            raise InputException("Key {0} is not a valid input!".format(key))

        if self._inputs[key].prompt:
            prompt = self._inputs[key].prompt
        elif self._inputs[key].is_bool():
            prompt = "{0}?".format(key)
        else:
            prompt = "please enter your {0}".format(key)
        help_text = self._inputs[key].help if hasattr(self._inputs[key],
                                                      'help') else None

        if self._inputs[key].value is EMPTY or force:

            default_value = None
            if self._inputs[key].default is not EMPTY:
                default_value = self._inputs[key].default
            if self._inputs[key].value is not EMPTY:
                default_value = self._inputs[key].value

            input_value = EMPTY
            while input_value is EMPTY or input_value == '?':
                if input_value == '?' and help_text:
                    print(help_text)
                input_value = lib.prompt(prompt,
                                         default=default_value,
                                         bool_type=self._inputs[key].in_type,
                                         secret=self._inputs[key].is_secret)
            self._inputs[key].value = input_value

        return self._inputs[key].value
Пример #6
0
 def get_input(self, key, force=False):
     """ Get the value of <key> if it already exists, or prompt for it if not """
     if key not in self._inputs:
         raise InputException("Key {0} is not a valid input!".format(key))
     if key not in self._values or force:
         self._values[key] = lib.prompt("please enter your %s" % key,
                                        default=(self._values.get(key, None) or self._defaults.get(key, None)),
                                        secret=(key in self._secret_values))
     return self._values[key]
Пример #7
0
 def get_config(self, param_name, default=None, secret=False, force_prompt=False):
     """
     grabs a config from the user space; if it doesn't exist, it will prompt for it.
     """
     if not self.has_option('config', param_name) or force_prompt:
         self.set('config', param_name, lib.prompt("please enter your %s" % param_name,
                                                   default=default,
                                                   secret=secret))
     if secret:
         self.temporary_config_variables.append(param_name)
     return self.get('config', param_name)
Пример #8
0
 def get_input(self, key, force=False):
     """ Get the value of <key> if it already exists, or prompt for it if not """
     if key not in self._inputs:
         raise InputException("Key {0} is not a valid input!".format(key))
     if key not in self._values or force:
         self._values[key] = lib.prompt(
             "please enter your %s" % key,
             default=(self._values.get(key, None)
                      or self._defaults.get(key, None)),
             secret=(key in self._secret_values))
     return self._values[key]
Пример #9
0
def _configure_env_source_rc(config):
    """ Configures wether to have .env source .rc """
    config.set('global', 'env_source_rc', False)
    if system.is_osx():
        logger.info("On OSX, login shells are default, which only source sprinter's 'env' configuration.")
        logger.info("I.E. environment variables would be sourced, but not shell functions "
                    + "or terminal status lines.")
        logger.info("The typical solution to get around this is to source your rc file (.bashrc, .zshrc) "
                    + "from your login shell.")
        env_source_rc = lib.prompt("would you like sprinter to source the rc file too?", default="yes",
                                   boolean=True)
        config.set('global', 'env_source_rc', env_source_rc)
Пример #10
0
def _configure_env_source_rc(config):
    """ Configures wether to have .env source .rc """
    config.set('global', 'env_source_rc', False)
    if system.is_osx():
        logger.info("On OSX, login shells are default, which only source sprinter's 'env' configuration.")
        logger.info("I.E. environment variables would be sourced, but not shell functions "
                    + "or terminal status lines.")
        logger.info("The typical solution to get around this is to source your rc file (.bashrc, .zshrc) "
                    + "from your login shell.")
        env_source_rc = lib.prompt("would you like sprinter to source the rc file too?", default="yes",
                                   boolean=True)
        config.set('global', 'env_source_rc', env_source_rc)
Пример #11
0
 def prompt(self):
     if self.environment.phase in (PHASE.INSTALL, PHASE.UPDATE):
         if os.path.exists(ssh_config_path):
             if not self.target.has('use_global_ssh'):
                 self.target.prompt("use_global_ssh", 
                                    "Would you like to use existing ssh configuration?",
                                    default="no")
             if (self.injections.in_noninjected_file(
                     ssh_config_path, "Host %s" % self.target.get('host')) and
                not self.target.has('override')):
                 self.logger.info("SSH config for host %s already exists! Override?" %
                                  self.target.get('host'))
                 self.logger.info("Your existing config will not be overwritten, simply inactive.")
                 self.target.set('override', lib.prompt("Override?", boolean=True, default="no"))
Пример #12
0
def _configure_shell(config):
    """ Checks and queries values for the shell """
    config.add_section('shell')
    logger.info("What shells or environments would you like sprinter to work with?\n" +
                "(Sprinter will not try to inject into environments not specified here.)\n" +
                "If you specify 'gui', sprinter will attempt to inject it's state into graphical programs as well.\n" +
                "i.e. environment variables sprinter set will affect programs as well, not just shells")
    environments = list(enumerate(sorted(SHELL_CONFIG), start=1))
    logger.info("[0]: All, " + ", ".join(["[%d]: %s" % (index, val) for index, val in environments]))
    desired_environments = lib.prompt("type the environment, comma-separated", default="0")
    for index, val in environments:
        if str(index) in desired_environments or "0" in desired_environments:
            config.set('shell', val, 'true')
        else:
            config.set('shell', val, 'false')
Пример #13
0
 def install_sandboxes(self):
     if self.target:
         if system.is_osx():
             if not self.target.is_affirmative('config', 'use_global_packagemanagers'):
                 self._install_sandbox('brew', brew.install_brew)
             elif lib.which('brew') is None:
                 install_brew = lib.prompt(
                     "Looks like you don't have brew, " +
                     "which is sprinter's package manager of choice for OSX.\n"
                     "Would you like sprinter to install brew for you?",
                     default="yes", boolean=True)
                 if install_brew:
                     lib.call("sudo mkdir -p /usr/local/", stdout=None,
                              output_log_level=logging.DEBUG)
                     lib.call("sudo chown -R %s /usr/local/" % getpass.getuser(),
                              output_log_level=logging.DEBUG, stdout=None)
                     brew.install_brew('/usr/local')
Пример #14
0
 def prompt(self):
     if self.environment.phase in (PHASE.INSTALL, PHASE.UPDATE):
         if os.path.exists(ssh_config_path):
             if not self.target.has('use_global_ssh'):
                 self.target.prompt(
                     "use_global_ssh",
                     "Would you like to use existing ssh configuration?",
                     default="no")
             if (self.injections.in_noninjected_file(
                     ssh_config_path, "Host %s" % self.target.get('host'))
                     and not self.target.has('override')):
                 self.logger.info(
                     "SSH config for host %s already exists! Override?" %
                     self.target.get('host'))
                 self.logger.info(
                     "Your existing config will not be overwritten, simply inactive."
                 )
                 self.target.set(
                     'override',
                     lib.prompt("Override?", boolean=True, default="no"))
Пример #15
0
    def _prompt_value(self, key, prompt_string, default=None, only_if_empty=True):
        """prompts the user for a value, and saves it to either the target or
        source manifest (whichever is appropriate for the phase)
        
        this method takes will default to the original value passed by
        the user in the case one exists. e.g. if a user already
        answered 'yes' to a question, it will use 'yes' as the default
        vs the one passed into this method.
        """
        main_manifest = self.target or self.source

        if only_if_empty and main_manifest.has(key):
            return main_manifest.get(key)

        prompt_default = default
        if self.source and self.source.has(key):
            prompt_default = self.source.get(key)

        main_manifest.set(key,
                          lib.prompt(prompt_string,
                                     default=prompt_default))
Пример #16
0
    def get_input(self, key, force=False):
        """ Get the value of <key> if it already exists, or prompt for it if not """
        prompt = "please enter your {0}".format(key)
        if self._inputs[key].prompt:
            prompt = self._inputs[key].prompt
        if key not in self._inputs:
            raise InputException("Key {0} is not a valid input!".format(key))

        if self._inputs[key].value is EMPTY or force:

            default_value = None
            if self._inputs[key].default is not EMPTY:
                default_value = self._inputs[key].default
            if self._inputs[key].value is not EMPTY:
                default_value = self._inputs[key].value

            self._inputs[key].value = lib.prompt(
                prompt,
                default=default_value,
                secret=self._inputs[key].is_secret)

        return self._inputs[key].value
Пример #17
0
 def install_sandboxes(self):
     if self.target:
         if system.is_osx():
             if not self.target.is_affirmative(
                     'config', 'use_global_packagemanagers'):
                 self._install_sandbox('brew', brew.install_brew)
             elif lib.which('brew') is None:
                 install_brew = lib.prompt(
                     "Looks like you don't have brew, " +
                     "which is sprinter's package manager of choice for OSX.\n"
                     "Would you like sprinter to install brew for you?",
                     default="yes",
                     boolean=True)
                 if install_brew:
                     lib.call("sudo mkdir -p /usr/local/",
                              stdout=None,
                              output_log_level=logging.DEBUG)
                     lib.call("sudo chown -R %s /usr/local/" %
                              getpass.getuser(),
                              output_log_level=logging.DEBUG,
                              stdout=None)
                     brew.install_brew('/usr/local')
Пример #18
0
    def _prompt_value(self,
                      key,
                      prompt_string,
                      default=None,
                      only_if_empty=True):
        """prompts the user for a value, and saves it to either the target or
        source manifest (whichever is appropriate for the phase)

        this method takes will default to the original value passed by
        the user in the case one exists. e.g. if a user already
        answered 'yes' to a question, it will use 'yes' as the default
        vs the one passed into this method.
        """
        main_manifest = self.target or self.source

        if only_if_empty and main_manifest.has(key):
            return main_manifest.get(key)

        prompt_default = default
        if self.source and self.source.has(key):
            prompt_default = self.source.get(key)

        main_manifest.set(key, lib.prompt(prompt_string,
                                          default=prompt_default))
Пример #19
0
 def prompt(self, param, message, default=None, only_if_empty=False):
     """ Prompts the user for a value, passing a default if it exists """
     if self.has(param) and only_if_empty:
         return
     value = lib.prompt(message, default=default)
     self.set(param, value)
Пример #20
0
 def prompt(self, param, message, default=None, only_if_empty=False):
     """ Prompts the user for a value, passing a default if it exists """
     if self.has(param) and only_if_empty:
         return
     value = lib.prompt(message, default=default)
     self.set(param, value)