コード例 #1
0
ファイル: __init__.py プロジェクト: CuBoulder/atlas
def _delete_database(site):
    if environment != "local":
        # TODO: Make file location config.
        os.environ["MYSQL_TEST_LOGIN_FILE"] = "/home/{0}/.mylogin.cnf".format(ssh_user)
        mysql_login_path = "invsqlagnt_{0}_poolb".format(environment)
        mysql_info = "/usr/local/mysql/bin/mysql --login-path={0} -e".format(mysql_login_path)
        database_password = utilities.decrypt_string(site["db_key"])
        local("{0} 'drop database `{1}`;'".format(mysql_info, site["sid"]))
        # TODO: Make IP addresses config.
        local(
            "{0} \"drop user '{1}'@'172.20.62.0/255.255.255.0' identified by '{2}';\"".format(
                mysql_info, site["sid"], database_password
            )
        )
    else:
        with settings(host_string="express.local"):
            run("mysql -e 'drop database `{}`;'".format(site["sid"]))
コード例 #2
0
ファイル: __init__.py プロジェクト: CuBoulder/atlas
def _create_settings_files(site, profile_name):
    sid = site["sid"]
    if "path" in site:
        path = site["path"]
    else:
        path = site["sid"]
    # If the site is launching or launched, we add 'cu_path' and redirect the
    # p1 URL.
    status = site["status"]

    database_password = utilities.decrypt_string(site["db_key"])

    # Call the template file and render the variables into it.
    template = jinja_env.get_template("settings.local_pre.php")
    local_pre_settings = template.render(
        profile=profile_name, sid=sid, path=path, status=status, pool_full=site["pool"]
    )
    # Write the file to a temporary location.
    with open("/tmp/{0}.settings.local_pre.php".format(sid), "w") as ofile:
        ofile.write(local_pre_settings)

    template = jinja_env.get_template("settings.local_post.php")
    local_post_settings = template.render(
        sid=sid,
        pw=database_password,
        database_servers=env.roledefs["database_servers"],
        memcache_servers=env.roledefs["memcache_servers"],
        environment=environment if environment != "prod" else "",
    )
    with open("/tmp/{0}.settings.local_post.php".format(sid), "w") as ofile:
        ofile.write(local_post_settings)

    template = jinja_env.get_template("settings.php")
    settings_php = template.render(
        profile=profile_name,
        sid=sid,
        reverse_proxies=env.roledefs["varnish_servers"],
        varnish_control=varnish_control_terminals[environment],
        memcache_servers=env.roledefs["memcache_servers"],
        environment=environment if environment != "prod" else "",
    )
    with open("/tmp/{0}.settings.php".format(sid), "w") as ofile:
        ofile.write(settings_php)
コード例 #3
0
def switch_settings_files(instance):
    """Create settings.php from template and render the resulting file onto the server.

    Arguments:
        instance {dict} -- full instance record
    """
    log.info('Instance | Settings file | Instance ID - %s', instance['_id'])

    # If the settings file exists, change permissions to allow us to update the template.
    file_destination = "{0}/{1}/{1}/sites/default/settings.php".format(
        INSTANCE_ROOT, instance['sid'])
    # Check to see if file exists and is writable.
    utilities.file_accessable_and_writable(file_destination)

    # Setup variables
    if instance['settings'].get('siteimprove_site'):
        siteimprove_site = instance['settings']['siteimprove_site']
    else:
        siteimprove_site = None
    if instance['settings'].get('siteimprove_group'):
        siteimprove_group = instance['settings']['siteimprove_group']
    else:
        siteimprove_group = None

    profile = utilities.get_single_eve('code', instance['code']['profile'])

    if ('cse_creator' in instance['settings']) and ('cse_id'
                                                    in instance['settings']):
        google_cse_csx = instance['settings']['cse_creator'] + ':' + instance[
            'settings']['cse_id']
    else:
        google_cse_csx = None

    if NFS_MOUNT_FILES_DIR:
        tmp_path = '{0}/{1}/tmp'.format(NFS_MOUNT_LOCATION[ENVIRONMENT],
                                        instance['sid'])
    else:
        tmp_path = '/tmp'

    if 'google_tag_client_container_id' in instance['settings']:
        google_tag_client_container_id = instance['settings'][
            'google_tag_client_container_id']
    else:
        google_tag_client_container_id = None

    domain = BASE_URLS[ENVIRONMENT].split('://')[1]

    settings_variables = {
        'profile': profile['meta']['name'],
        'sid': instance['sid'],
        'atlas_id': instance['_id'],
        'atlas_url': API_URLS[ENVIRONMENT] + '/',
        'atlas_logging_url': ATLAS_LOGGING_URLS[ENVIRONMENT],
        'atlas_username': SERVICE_ACCOUNT_USERNAME,
        'atlas_password': SERVICE_ACCOUNT_PASSWORD,
        'path': instance['path'],
        'status': instance['status'],
        'atlas_statistics_id': instance['statistics'],
        'siteimprove_site': siteimprove_site,
        'siteimprove_group': siteimprove_group,
        'google_cse_csx': google_cse_csx,
        'google_tag_client_container_id': google_tag_client_container_id,
        'reverse_proxies': SERVERDEFS[ENVIRONMENT]['varnish_servers'],
        'varnish_control': VARNISH_CONTROL_TERMINALS[ENVIRONMENT],
        'varnish_control_key': VARNISH_CONTROL_KEY,
        'pw': utilities.decrypt_string(instance['db_key']),
        'page_cache_maximum_age':
        instance['settings']['page_cache_maximum_age'],
        'database_servers': SERVERDEFS[ENVIRONMENT]['database_servers'],
        'environment': ENVIRONMENT,
        'tmp_path': tmp_path,
        'saml_pw': SAML_AUTH,
        'smtp_client_hostname': BASE_URLS[ENVIRONMENT],
        'smtp_password': SMTP_PASSWORD,
        'base_url': BASE_URLS[ENVIRONMENT],
        'domain': domain,
        'servicenow_key': SERVICENOW_KEY
    }

    log.info(
        'Instance | Settings file | Render settings file | Instance ID - %s',
        instance['_id'])
    # Create a template environment with the default settings and a loader that looks up the
    # templates in the templates folder inside the Atlas python package.
    # We don't do autoescaping, because there is no PHP support.
    jinja_env = Environment(loader=PackageLoader('atlas', 'templates'))
    template = jinja_env.get_template('settings.php')
    render = template.render(settings_variables)
    # Remove the existing file.
    if os.access(file_destination, os.F_OK):
        os.remove(file_destination)
    # Write the render to a file.
    with open(file_destination, "wb") as open_file:
        open_file.write(render)
    # Set file permissions
    # Octet mode, Python 3 compatible
    os.chmod(file_destination, 0o444)