def configure_keyring(self): LOG.info("Configuring keyring") sn_conf = "%s/.supernova" % common.get_home() if not common.check_file(sn_conf): LOG.error("No supernova conf found. Cannot configure") return False sn = ConfigParser.ConfigParser() sn.readfp(open(sn_conf)) if not sn.has_section("snail"): LOG.error("Supernova conf isn't a snail conf: " + "can't safely continue") return False venv_path = "%s/%s" % (self.install_path, ".venv") if not common.check_venv() and not common.enter_virtualenv(venv_path): LOG.error("Could not enter virtualenv") self.abort() snail_conf = "%s/snail.conf" % common.get_home() if not common.check_file(snail_conf): LOG.error("Could not locate snail.conf") self.abort() snail_config = ConfigParser.ConfigParser() snail_config.readfp(open(snail_conf)) sso = common.get_confirmed_password("Enter your SSO") for section in sn.sections(): if not sn.has_option(section, "type"): continue pw_type = "prompt" if snail_config.has_section(section) and snail_config.has_option(section, "pw_type"): pw_type = snail_config.get(section, "pw_type") do_prompt = pw_type == "prompt" prompt_msg = "Please enter your password" for k, v in sn.items(section): if v == "USE_KEYRING": pw = pw_type if pw_type == "sso": pw = sso if do_prompt: try: pw = common.get_confirmed_password(prompt_msg) except EOFError: LOG.error("Caught CTRL+D. Aborting") if DEBUG: exit(1) self.abort() scommon.pexpect_supernova(section, k.upper(), pw, verbose=self.verbose, noop=self.noop) scommon.pexpect_inovalogin(sso, verbose=self.verbose, noop=self.noop) LOG.info("If you did not like what you saw, rerun with --refresh") return True
def check_snail_conf(self): snail_conf = "%s/snail.conf" % common.get_home() if not common.check_file(snail_conf): LOG.error("Could not locate snail.conf") self.abort() snail_config = ConfigParser.ConfigParser() snail_config.readfp(open(snail_conf)) if not snail_config.has_section("snail"): LOG.error("snail.conf is missing snail section") common.exit(1) if not snail_config.has_option("snail", "inova_repo"): LOG.error("snail.conf is missing inova_repo option") common.exit(1) if not snail_config.has_option("snail", "template_repo"): LOG.error("snail.conf is missing template_repo option") common.exit(1) if not snail_config.has_option("snail", "inova_user"): LOG.error("snail.conf is missing inova_user option") common.exit(1) self.inova_repo = snail_config.get("snail", "inova_repo") self.template_repo = snail_config.get("snail", "template_repo") self.inova_user = snail_config.get("snail", "inova_user")
def backup_existing_inova_conf(self, overwrite=False): in_conf = "%s/.inova-login" % common.get_home() in_bak = in_conf + ".bak" if not common.check_file(in_conf): LOG.info("No pre-existing inova conf found") return True # check if existing supernova conf is a snail conf conf_check = ConfigParser.ConfigParser() conf_check.readfp(open(in_conf)) if conf_check.has_section("inova-login") and conf_check.has_option("inova-login", "snail-gen"): """ No need to back up a snail config file.""" return True if common.check_file(in_bak): if not overwrite: LOG.error("Backup already exists! Confirm with --overwrite") return False LOG.info("Backing up existing conf to %s" % in_bak) common.copy_file(in_conf, in_bak) return True
def generate_supernova_conf(self): repo = self.template_repo secure_dir = "%s/%s" % (self.install_path, "secure") if common.check_dir(secure_dir): common.remove_dir(secure_dir) if not common.clone_from_git_repo(repo, secure_dir): LOG.error("Could not clone %s" % repo) self.abort() seed_file = "%s/snail/supernova_seed.conf" % secure_dir remote_config = ConfigParser.ConfigParser() remote_config.readfp(open(seed_file)) snail_conf = "%s/snail.conf" % common.get_home() if not common.check_file(snail_conf): LOG.error("Could not locate snail.conf") self.abort() snail_config = ConfigParser.ConfigParser() snail_config.readfp(open(snail_conf)) inovas = {} supernovas = {} inova_template = None sn_template = None config_list = [remote_config, snail_config] ignored_keys = ["pw_type"] for config in config_list: sections = config.sections() for section in sections: td = {} for k, v in config.items(section): if k in ignored_keys: continue td[k] = v if section == "inova-template": inova_template = td continue elif section == "supernova-template": sn_template = td continue if not config.has_option(section, "type"): continue type = config.get(section, "type") if type == "inova": if section in inovas: inovas[section].update(td) else: inovas[section] = td elif type == "supernova": if section in supernovas: supernovas[section].update(td) else: supernovas[section] = td if not inova_template or not sn_template: LOG.error("Could not find inova or supernova template anywhere") common.self.abort() out_file = "%s/snail/supernova_out.conf" % secure_dir if common.check_file(out_file): common.remove_file(out_file) out_config = ConfigParser.ConfigParser() out_config.add_section("snail") out_config.set("snail", "version", "0.1") out_list = [(inovas, inova_template), (supernovas, sn_template)] for listing, template in out_list: for title, items in listing.items(): out_config.add_section(title) for template_key, template_value in template.items(): src = template_value.lower() value = template_value if src == "title": value = title if src in items: value = items[template_value.lower()] if template_key.lower() in items: value = items[template_key.lower()] out_config.set(title, template_key.upper(), value) for template_key, template_value in template.items(): src = template_value.lower() if src in items: del items[template_value.lower()] for item_key, item_value in items.items(): if not out_config.has_option(title, item_key): out_config.set(title, item_key, item_value) out_config.write(open(out_file, "w+")) sn_conf = "%s/.supernova" % common.get_home() common.copy_file(out_file, sn_conf) seed_file = "%s/snail/inova_seed.conf" % secure_dir remote_config = ConfigParser.ConfigParser() remote_config.readfp(open(seed_file)) out_file = "%s/snail/inovalogin_out.conf" % secure_dir if common.check_file(out_file): common.remove_file(out_file) out_config = ConfigParser.ConfigParser() out_config.add_section("inova-login") for k, v in remote_config.items("inova-login"): value = v if v == "USER": value = self.inova_user out_config.set("inova-login", k, value) out_config.set("inova-login", "snail_gen", "1") out_config.write(open(out_file, "w+")) sn_conf = "%s/.inova-login" % common.get_home() common.copy_file(out_file, sn_conf)
import ConfigParser import logging import snail.common as common import snail.snail_common as scommon LOG = logging.getLogger("snail." + __name__) DEBUG = True NO_INOVA = False INSTALL_PATH = "%s/bin/snail" % common.get_home() class AlreadyInstalledException(Exception): message = "Already installed" class SnailInstaller(object): verbose = False noop = False no_inova = False def __init__(self, verbose=False, noop=False, no_inova=False, uninstall=False): self.verbose = verbose self.noop = noop self.no_inova = no_inova self.install_path = INSTALL_PATH self.uninstall = uninstall self.inova_repo = None self.template_repo = None self.inova_user = None