Exemplo n.º 1
0
def install_postgis(db):
    create_postgis_sql = sql.text("""
        CREATE EXTENSION postgis;
    """)

    try:
        db.engine.execute(create_postgis_sql)
    except sqlalchemy.exc.ProgrammingError:
        utils.step_print('postgis already installed')
Exemplo n.º 2
0
def reference_old_user_params(param_paths):
    utils.step_print('hyp3 user already exists')

    prefix = 'SSM Parameter Store Path -> '

    return {
        'HyP3ApiKey': prefix + param_paths['api-key'],
        'HyP3Username': prefix + param_paths['username']
    }
Exemplo n.º 3
0
def is_new(db, user):
    utils.step_print('checking if user exists')

    users = db.session \
        .query(hyp3_models.User) \
        .filter(hyp3_models.User.username == user.name) \
        .all()

    utils.step_print(users)
    return len(users) == 0
Exemplo n.º 4
0
def get_param_store_paths():
    stack_name = utils.get_environ_params('HyP3StackName').pop()
    [username_param_name,
     api_key_param_name] = utils.get_environ_params("ParamNameHyP3Username",
                                                    "ParamNameHyP3ApiKey")
    utils.step_print(stack_name)

    return {
        'username': '******'.format(stack_name, username_param_name),
        'api-key': '/{}/{}'.format(stack_name, api_key_param_name)
    }
Exemplo n.º 5
0
def make_hyp3_admin_user(db):
    user = get_user()
    param_paths = get_param_store_paths()

    if hyp3_user.is_new(db, user):
        utils.step_print('Creating new user')
        step_output = add_new_user(db, user, param_paths)
    else:
        utils.step_print('User already exists')
        step_output = reference_old_user_params(param_paths)

    return step_output
Exemplo n.º 6
0
def new(db):
    exisiting_processes_text_ids = [
        p.text_id for p in db.session.query(hyp3_models.Process).all()
    ]

    new_default_processes = [
        hyp3_models.Process(**p) for p in get_processes()
        if p['text_id'] not in exisiting_processes_text_ids
    ]

    for p in new_default_processes:
        utils.step_print(f'adding new process {p.text_id}')

    return new_default_processes
Exemplo n.º 7
0
def add_db_user(db):
    user, password, db_name = utils.get_environ_params('HyP3DBUser',
                                                       'HyP3DBPass',
                                                       'HyP3DBName')

    if does_db_user_exists(db, user):
        utils.step_print(f'user {user} already exists')
        return

    add_user_sql = sql.text(f"""
        CREATE USER {user} WITH PASSWORD :password;
        GRANT ALL PRIVILEGES ON DATABASE {db_name} to {user};
    """)

    db.engine.execute(add_user_sql, password=password)
Exemplo n.º 8
0
def get_processes():
    bucket, key = utils.get_environ_params('DefaultProcessesBucket',
                                           'DefaultProcessesKey')

    s3 = boto3.resource('s3')

    base_path = pl.Path('/tmp') if \
        'prod' in os.environ.get('Maturity', 'prod') \
        else pl.Path('.')

    file_path = (base_path / pl.Path(key).name)

    utils.step_print('downloading default processes')
    s3.Bucket(bucket) \
        .download_file(key, str(file_path))

    with file_path.open('r') as f:
        processes = json.load(f)

    return processes