예제 #1
0
def do_help_setup_new_environment():
    print(HELP_SETUP_NEW_ENVIRONMENT)
    name = prompt_for_new_eb_environment_name()
    do_fail_if_bad_environment_name(name)
    do_fail_if_environment_exists(name)

    beiwe_environment_fp = get_beiwe_python_environment_variables_file_path(
        name)
    processing_server_settings_fp = get_server_configuration_file_path(name)
    extant_files = os.listdir(DEPLOYMENT_SPECIFIC_CONFIG_FOLDER)

    for fp in (beiwe_environment_fp, processing_server_settings_fp):
        if os.path.basename(fp) in extant_files:
            log.error("is already a file at %s" %
                      relpath(beiwe_environment_fp))
            EXIT(1)

    with open(beiwe_environment_fp, 'w') as f:
        json.dump(reference_environment_configuration_file(), f, indent=1)
    with open(processing_server_settings_fp, 'w') as f:
        json.dump(reference_data_processing_server_configuration(),
                  f,
                  indent=1)

    print("Environment specific files have been created at %s and %s." % (
        relpath(beiwe_environment_fp),
        relpath(processing_server_settings_fp),
    ))

    # Note: we actually cannot generate RDS credentials until we have a server, this is because
    # the hostname cannot exist until the server exists.
    print(
        """After filling in the required contents of these newly created files you will be able
    to run the -create-environment command.  Note that several more credentials files will be
    generated as part of that process. """)
예제 #2
0
def validate_beiwe_environment_config(eb_environment_name):
    # DOMAIN_NAME
    # SENTRY_ANDROID_DSN
    # SENTRY_DATA_PROCESSING_DSN
    # SENTRY_ELASTIC_BEANSTALK_DSN
    # SENTRY_JAVASCRIPT_DSN
    # SYSADMIN_EMAILS
    errors = []
    try:
        aws_credentials = get_aws_credentials()
        global_config = get_global_config()
        beiwe_variables = get_beiwe_environment_variables(eb_environment_name)
    except Exception as e:
        log.error(
            "encountered an error while trying to read configuration files.")
        log.error(e)
        EXIT(1)

    beiwe_variables_name = os.path.basename(
        get_beiwe_python_environment_variables_file_path(eb_environment_name))
    reference_environment_configuration_keys = reference_environment_configuration_file(
    ).keys()
    # Validate the data

    sysadmin_email = global_config.get('SYSTEM_ADMINISTRATOR_EMAIL', "")
    if not sysadmin_email:
        errors.append(
            '(Global Configuration) System administrator email cannot be empty.'
        )
    else:
        if not re.match('^[\S]+@[\S]+\.[\S]+$', sysadmin_email):
            errors.append(
                '(Global Configuration) Invalid email address: {}'.format(
                    sysadmin_email))

    # check sentry urls
    sentry_dsns = {
        "SENTRY_ELASTIC_BEANSTALK_DSN":
        beiwe_variables.get('SENTRY_ELASTIC_BEANSTALK_DSN', ''),
        "SENTRY_DATA_PROCESSING_DSN":
        beiwe_variables.get('SENTRY_DATA_PROCESSING_DSN', ''),
        "SENTRY_ANDROID_DSN":
        beiwe_variables.get('SENTRY_ANDROID_DSN', ''),
        "SENTRY_JAVASCRIPT_DSN":
        beiwe_variables.get('SENTRY_JAVASCRIPT_DSN', ''),
    }

    for name, dsn in sentry_dsns.iteritems():
        if ensure_nonempty_string(dsn, name, errors, beiwe_variables_name):
            if not DSN_REGEX.match(dsn):
                errors.append('({}) Invalid DSN: {}'.format(
                    beiwe_variables_name, dsn))
            # if name == "SENTRY_JAVASCRIPT_DSN":
            #     if not PUBLIC_DSN_REGEX.match(dsn):
            #         errors.append('({}) Invalid DSN: {}'.format(beiwe_variables_name, dsn))
            # elif not PRIVATE_DSN_REGEX.match(dsn):
            #     errors.append('({}) Invalid DSN: {}'.format(beiwe_variables_name, dsn))

    domain_name = beiwe_variables.get('DOMAIN', None)
    ensure_nonempty_string(domain_name, 'Domain name', errors,
                           beiwe_variables_name)

    for key in reference_environment_configuration_keys:
        if key not in beiwe_variables:
            errors.append("{} is missing.".format(key))

    for key in beiwe_variables:
        if key not in reference_environment_configuration_keys:
            errors.append("{} is present but was not expected.".format(key))

    # Raise any errors
    if errors:
        for e in errors:
            log.error(e)
        sleep(
            0.1
        )  # python logging has some issues if you exit too fast... isn't it supposed to be synchronous?
        EXIT(1)  # forcibly exit, do not continue to run any code.

    # Check for presence of the server settings file:
    if not file_exists(
            get_server_configuration_file_path(eb_environment_name)):
        log.error("No server settings file exists at %s." %
                  get_server_configuration_file_path(eb_environment_name))
        EXIT(1)

    # Put the data into one dict to be returned
    return {
        'DOMAIN_NAME': domain_name,
        'SYSADMIN_EMAILS': sysadmin_email,
        'SENTRY_ELASTIC_BEANSTALK_DSN':
        sentry_dsns['SENTRY_ELASTIC_BEANSTALK_DSN'],
        'SENTRY_DATA_PROCESSING_DSN':
        sentry_dsns['SENTRY_DATA_PROCESSING_DSN'],
        'SENTRY_ANDROID_DSN': sentry_dsns['SENTRY_ANDROID_DSN'],
        'SENTRY_JAVASCRIPT_DSN': sentry_dsns['SENTRY_JAVASCRIPT_DSN']
    }