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'] }
import boto3 from deployment_helpers.constants import (get_aws_credentials, get_global_config) AWS_CREDENTIIALS = get_aws_credentials() GLOBAL_CONFIGURATION = get_global_config() def _get_client(client_type): """ connect to a boto3 CLIENT in the appropriate type and region. """ return boto3.client( client_type, aws_access_key_id=AWS_CREDENTIIALS["AWS_ACCESS_KEY_ID"], aws_secret_access_key=AWS_CREDENTIIALS["AWS_SECRET_ACCESS_KEY"], region_name=GLOBAL_CONFIGURATION["AWS_REGION"], ) def _get_resource(client_type): """ connect to a boto3 RESOURCE in the appropriate type and region. """ return boto3.resource( client_type, aws_access_key_id=AWS_CREDENTIIALS["AWS_ACCESS_KEY_ID"], aws_secret_access_key=AWS_CREDENTIIALS["AWS_SECRET_ACCESS_KEY"], region_name=GLOBAL_CONFIGURATION["AWS_REGION"], ) def create_ec2_client(): return _get_client('ec2')