def _get_special(self, section, option): key = self._makekey(section, option) parent_val = None try: parent_val = ConfigParser.RawConfigParser.get(self, section, option) except ConfigParser.NoOptionError: pass if parent_val is None: return None extracted_val = None mtch = ENV_PAT.match(parent_val) if mtch: env_key = mtch.group(1).strip() def_val = mtch.group(2) if not def_val and not env_key: msg = "Invalid bash-like value \"%s\" for \"%s\"" % (parent_val, key) raise excp.BadParamException(msg) if not env_key or env.get_key(env_key) is None: LOG.debug("Extracting default value from config provided default value \"%s\" for \"%s\"" % (def_val, key)) actual_def_val = self._extract_default(def_val) LOG.debug("Using config provided default value \"%s\" for \"%s\" (no environment key)" % (actual_def_val, key)) extracted_val = actual_def_val else: env_val = env.get_key(env_key) LOG.debug("Using enviroment provided value \"%s\" for \"%s\"" % (env_val, key)) extracted_val = env_val else: LOG.debug("Using raw config provided value \"%s\" for \"%s\"" % (parent_val, key)) extracted_val = parent_val return extracted_val
def _get_suids(): uid = env.get_key(SUDO_UID) if uid is not None: uid = int(uid) gid = env.get_key(SUDO_GID) if gid is not None: gid = int(gid) return (uid, gid)
def _get_bashed(self, section, option): value = IgnoreMissingConfigParser.get(self, section, option) if value is None: return value extracted_val = '' mtch = ENV_PAT.match(value) if mtch: env_key = mtch.group(1).strip() def_val = mtch.group(2).strip() if not def_val and not env_key: msg = "Invalid bash-like value %r" % (value) raise excp.BadParamException(msg) env_value = env.get_key(env_key) if env_value is None: LOG.debug( "Extracting value from config provided default value %r" % (def_val)) extracted_val = self._resolve_replacements(def_val) LOG.debug( "Using config provided default value %r (no environment key)" % (extracted_val)) else: extracted_val = env_value LOG.debug("Using enviroment provided value %r" % (extracted_val)) else: extracted_val = value LOG.debug("Using raw config provided value %r" % (extracted_val)) return extracted_val
def password(pw_prompt=None, pw_len=8): pw = "" ask_for_pw = env.get_key(PASS_ASK_ENV) if ask_for_pw is not None: ask_for_pw = ask_for_pw.lower().strip() if ask_for_pw not in ['f', 'false', '0', 'off']: pw = prompt_password(pw_prompt) if not pw: return _gen_password(pw_len) else: return pw
def _get_bashed(self, section, option, auto_pw): value = IgnoreMissingConfigParser.get(self, section, option) if value is None: return value extracted_val = '' mtch = ENV_PAT.match(value) if mtch: env_key = mtch.group(1).strip() def_val = mtch.group(2).strip() if not def_val and not env_key: msg = "Invalid bash-like value [%s]" % (value) raise excp.BadParamException(msg) env_value = env.get_key(env_key) if env_value is None: LOG.debug("Extracting value from config provided default value [%s]" % (def_val)) extracted_val = self._resolve_replacements(def_val, auto_pw) LOG.debug("Using config provided default value [%s] (no environment key)" % (extracted_val)) else: extracted_val = env_value LOG.debug("Using enviroment provided value [%s]" % (extracted_val)) else: extracted_val = value LOG.debug("Using raw config provided value [%s]" % (extracted_val)) return extracted_val
def _git_cache_download(storewhere, uri, branch=None): cdir = env.get_key(GIT_CACHE_DIR_ENV) if cdir and sh.isdir(cdir): #TODO pass return False