def options_parse_environment(): # Used for defining vars in cloud environment # Takes priority over rootthebox.cfg variables if os.environ.get("PORT", None) is not None: # Heroku uses $PORT to define listen_port options.listen_port = int(os.environ.get("PORT")) logging.info("Environment Configuration (PORT): %d" % options.listen_port) images = ["ctf_logo", "story_character", "scoreboard_right_image"] for item in options.as_dict(): config = os.environ.get(item.upper(), os.environ.get(item, None)) if config is not None: if item in images: value = save_config_image(config) else: value = config value = set_type(value, options[item]) if isinstance(value, type(options[item])): logging.info("Environment Configuration (%s): %s" % (item.upper(), value)) options[item] = value else: logging.error( "Environment Confirguation (%s): unable to convert type %s to %s for %s" % (item.upper(), type(value), type(options[item]), value)) if os.environ.get("DEMO"): setup_xml(["setup/demo_juiceshop.xml"]) from libs.ConfigHelpers import create_demo_user logging.info("Setting Up Demo Environment...") create_demo_user() options.autostart_game = True
def update_configuration(config): """ Update Configuration options based on XML data """ if config is None: return else: """ Backup configuration """ copyfile(options.config, options.config + ".bak") images = ["ctf_logo", "story_character", "scoreboard_right_image"] for config_elem in config: try: if options[config_elem.tag] is not None: if config_elem.tag in images: value = save_config_image(get_child_text(config, config_elem.tag)) else: value = get_child_text(config, config_elem.tag) if isinstance(value, type(options[config_elem.tag])): logging.info("Configuration (%s): %s" % (config_elem.tag, value)) options[config_elem.tag] = value except BaseException as e: logging.exception("Faild to update configuration (%s)" % e) save_config()
def update_configuration(config): """ Update Configuration options based on XML data """ if config is None: return else: """ Backup configuration """ copyfile(options.config, options.config + ".bak") images = ["ctf_logo", "story_character", "scoreboard_right_image"] for config_elem in config: try: if options[config_elem.tag] is not None: if config_elem.tag in images: value = save_config_image( get_child_text(config, config_elem.tag)) elif isinstance(options[config_elem.tag], list): lines = [] for line in get_child_by_tag(config, config_elem.tag): lines.append(line.text) value = lines else: value = get_child_text(config, config_elem.tag) value = set_type(value, options[config_elem.tag]) if isinstance(value, type(options[config_elem.tag])): logging.info("Configuration (%s): %s" % (config_elem.tag, value)) options[config_elem.tag] = value else: logging.error( "Confirguation (%s): unable to convert type %s to %s for %s" % ( config_elem.tag, type(value), type(options[config_elem.tag]), value, )) except BaseException as e: logging.exception("Faild to update configuration (%s)" % e) save_config()