Пример #1
0
def update(environment, stage, output, pretend, parameters):
    """Updates (or creates) an environment."""
    if parameters:
        with open(parameters, "r") as f:
            parameters = yaml.load(f.read())
    env = Environment(environment, stage=stage, parameters=parameters)
    if not pretend:
        env.create(output_file=output, update=True)
Пример #2
0
def create(environment, stage, output, pretend, parameters):
    """Creates an environment."""
    if parameters:
        with open(parameters, "r") as f:
            parameters = _ensure_defaults(yaml.load(f.read()))

    env = Environment(environment, stage=stage, parameters=parameters)
    if not pretend:
        env.create(output_file=output, update=False)
Пример #3
0
def delete(environment, stage, pretend, parameters):
    """Deletes an environment that has been deployed to CF."""
    if parameters:
        with open(parameters, "r") as f:
            parameters = yaml.load(f.read())

    env = Environment(environment, stage=stage, parameters=parameters)
    if not pretend:
        env.delete()
Пример #4
0
def delete(environment, stage, pretend, parameters):
    """Deletes an environment that has been deployed to CF."""
    if parameters:
        with open(parameters, "r") as f:
            parameters = yaml.load(f.read())

    env = Environment(environment, stage=stage, parameters=parameters)
    if not pretend:
        env.delete()
Пример #5
0
def create(environment, stage, output, pretend, parameters):
    """Creates an environment."""
    if parameters:
        with open(parameters, "r") as f:
            parameters = _ensure_defaults(yaml.load(f.read()))
        parameters = parameters.get(stage, parameters.get("_default"))

    env = Environment(environment, stage=stage, parameters=parameters)
    if not pretend:
        env.create(output_file=output, update=False)
Пример #6
0
def update(environment, stage, output, pretend, parameters):
    """Updates (or creates) an environment."""
    if parameters:
        with open(parameters, "r") as f:
            parameters = yaml.load(f.read())
        parameters = parameters.get(stage, parameters.get("_default"))

    env = Environment(environment, stage=stage, parameters=parameters)
    if not pretend:
        env.create(output_file=output, update=True)
def deploy_secrets(environment_file, stage="dev"):
    """Deploy secrets to the secrets vault."""
    env = Environment(environment_file, stage=stage)

    print("Deploying secrets to environment vault ...")
    for local_key, vault_key in SECRETS.items():
        value = keyring.get_password(NAMESPACE, local_key)
        resp = env.set_secret(vault_key, value)
        status = resp['ResponseMetadata']['HTTPStatusCode']
        print("Setting secret '{}': [{}]".format(vault_key, status))
def deploy_secrets(environment_file, stage="dev"):
    """Deploy secrets to the secrets vault."""
    env = Environment(environment_file, stage=stage)

    print("Deploying secrets to environment vault ...")
    for local_key, vault_key in SECRETS.items():
        value = keyring.get_password(NAMESPACE, local_key)
        resp = env.set_secret(vault_key, value)
        status = resp['ResponseMetadata']['HTTPStatusCode']
        print("Setting secret '{}': [{}]".format(vault_key, status))
def deploy_secrets(environment_file, stage="dev"):
    """Deploy secrets to the secrets vault."""
    env = Environment(environment_file, stage=stage)

    print("Deploying secrets to environment vault ...")
    for local_key, vault_key in SECRETS.items():
        keychain_namespace = NAMESPACE.format(stage=stage.lower())
        value = keyring.get_password(keychain_namespace, local_key) or \
            os.environ.get(local_key.replace(".", "_").upper())

        if value is None:
            print("Secret {}/{} not found in local keychain nor SENTRY_DSN "
                  "environment variable: skipping".format(keychain_namespace,
                                                          local_key))
        else:
            resp = env.set_secret(vault_key, value)
            status = resp['ResponseMetadata']['HTTPStatusCode']
            print("Setting secret '{}': [{}]".format(vault_key, status))
Пример #10
0
def environment(settings):
    """The test environment: this fixtures creates it and takes care of
    removing it after tests have run."""
    env = Environment(settings.environment_path, stage=settings.stage)
    if os.environ.get("UPDATE", "yes") == "yes":
        env.create(update=True, output_file=settings.output_path)
    else:
        env.create(output_file=settings.output_path)

    val = keyring.get_password(
        "humilis-kinesis-processor/{}".format(settings.stage), "sentry/dsn")
    env.set_secret("sentry.dsn", val)
    yield env
    if os.environ.get("DESTROY", "yes") == "yes":
        # Empty the S3 bucket
        bucket = env.outputs["storage"]["BucketName"]
        os.system("aws s3 rm s3://{} --recursive".format(bucket))
        env.delete()
Пример #11
0
def test_environment_params(environment_definition_j2_path,
                            environment_params_path, test_environment):
    """Tests using a params file in combination with an env def file."""
    with open(environment_params_path, "r") as f:
        params = yaml.load(f.read())
    env = Environment(environment_definition_j2_path, parameters=params)

    layer_params = env.layers[0].meta["parameters"]
    assert layer_params["vpc_cidr"]["value"] == params["vpc_cidr"]
Пример #12
0
def deploy_secrets(environment_file, stage="dev"):
    """Deploy secrets to the secrets vault."""
    env = Environment(environment_file, stage=stage)

    print("Deploying secrets to environment vault ...")
    for local_key, vault_key in SECRETS.items():
        keychain_namespace = NAMESPACE.format(stage=stage.lower())
        value = keyring.get_password(keychain_namespace, local_key) or \
            os.environ.get(local_key.replace(".", "_").upper())

        if value is None:
            print("Secret {}/{} not found in local keychain nor SENTRY_DSN "
                  "environment variable: skipping".format(
                      keychain_namespace, local_key))
        else:
            resp = env.set_secret(vault_key, value)
            status = resp['ResponseMetadata']['HTTPStatusCode']
            print("Setting secret '{}': [{}]".format(vault_key, status))
Пример #13
0
def environment(settings):
    """The test environment: this fixture creates it and takes care of
    removing it after tests have run."""
    env = Environment(settings.environment_path, stage=settings.stage)
    if settings.update == "yes":
        env.create(update=True)
    else:
        env.create()
    yield env
    if settings.destroy == "yes":
        env.delete()
Пример #14
0
def environment(settings):
    """The test environment: this fixtures creates it and takes care of
    removing it after tests have run."""
    env = Environment(settings.environment_path, stage=settings.stage)
    if os.environ.get("UPDATE", "yes") == "yes":
        env.create(update=True, output_file=settings.output_path)
    else:
        env.create(output_file=settings.output_path)
    yield env
    if os.environ.get("DESTROY", "yes") == "yes":
        env.delete()
Пример #15
0
def environment(settings):
    """The test environment: this fixtures creates it and takes care of
    removing it after tests have run."""
    env = Environment(settings.environment_path, stage=settings.stage)

    if os.environ.get("UPDATE", "yes") == "yes":
        env.create(update=True, output_file=settings.output_path)
    else:
        env.create(output_file=settings.output_path)
    yield env
    if os.environ.get("DESTROY", "no").lower() == "yes":
        bucket = env.outputs["asg"]["BucketName"]
        empty_bucket(bucket)
        try:
            env.delete()
        except AwsError as err:
            # Some files may have arrived to the bucket after the bucket was
            # emptied for the first time.
            empty_bucket(bucket)
            env.delete()
Пример #16
0
def produce_environment(envpath, stage, parameters=None):
    """Produce humilis environment object."""
    if parameters:
        with open(parameters, "r") as f:
            parameters = yaml.load(f.read())
            stage_params = parameters.get(stage, {})
            stage_params["_default"] = parameters.get("_default", {})
    else:
        stage_params = {}

    return Environment(envpath, stage=stage, parameters=stage_params)
Пример #17
0
def environment():
    """The test environment: this fixtures creates it and takes care of
    removing it after tests have run."""
    env = Environment("tests/integration/secrets-vault.yaml")
    env.create()
    yield env
    env.delete()
Пример #18
0
def environment(settings):
    """The test environment: this fixtures creates it and takes care of
    removing it after tests have run."""
    env = Environment(settings.environment_path, stage=settings.stage)
    if os.environ.get("UPDATE", "yes") == "yes":
        env.create(update=True, output_file=settings.output_path)
    else:
        env.create(output_file=settings.output_path)

    val = keyring.get_password(
        "humilis-kinesis-processor/{}".format(settings.stage), "sentry/dsn")
    env.set_secret("sentry.dsn", val)
    yield env
    if os.environ.get("DESTROY", "yes") == "yes":
        # Empty the S3 bucket
        bucket = env.outputs["storage"]["BucketName"]
        os.system("aws s3 rm s3://{} --recursive".format(bucket))
        env.delete()
Пример #19
0
def environment(settings):
    """The test environment: this fixtures creates it and takes care of
    removing it after tests have run."""
    env = Environment(settings.environment_path, stage=settings.stage)
    if settings.update == "yes":
        env.create(update=True)
    else:
        env.create()
    yield env
    if settings.destroy == "yes":
        env.delete()
Пример #20
0
def test_plugin(envfile):
    """Create and destroy the test environment of a humilis plugin."""
    envfile_path = os.path.join(EXAMPLES_DIR, envfile)
    env = Environment(envfile_path, stage="TEST")
    try:
        env.create(update=True)
    finally:
        env.delete()
Пример #21
0
def environment(settings):
    """The test environment: this fixtures creates it and takes care of
    removing it after tests have run."""
    env = Environment(settings.environment_path, stage=settings.stage)
    env.create(update=True)
    yield env
    if os.environ.get("DESTROY", "yes").lower() == "yes":
        env.delete()
Пример #22
0
def environment(settings):
    """The test environment: this fixtures creates it and takes care of
    removing it after tests have run."""
    env = Environment(settings.environment_path, stage=settings.stage)
    if os.environ.get("UPDATE", "yes") == "yes":
        env.create(update=True, output_file=settings.output_path)
    else:
        env.create(output_file=settings.output_path)
    yield env
    if os.environ.get("DESTROY", "yes") == "yes":
        # Empty the S3 bucket
        bucket = env.outputs["storage"]["BucketName"]
        os.system("aws s3 rm s3://{} --recursive".format(bucket))
        env.delete()
Пример #23
0
def main(ctx, envpath, stage, parameters):
    """Polku sample app: deployment CLI."""
    ctx.obj = {"env": Environment(envpath, stage=stage, parameters=parameters)}
    config.context = ctx.obj
Пример #24
0
def delete(environment, stage, pretend, parameters):
    """Deletes an environment that has been deployed to CF."""
    env = Environment(environment, stage=stage, parameters=parameters)
    if not pretend:
        env.delete()
Пример #25
0
def test_environment(environment_definition_path, test_config):
    """A humilis environment based on the sample environment definition."""
    return Environment(environment_definition_path)
Пример #26
0
def get_secret(environment, key, stage, pretend):
    """Gets a secret from the vault."""
    env = Environment(environment, stage=stage)
    if not pretend:
        resp = env.get_secret(key)
        print(resp)
Пример #27
0
def update(environment, stage, output, pretend, parameters):
    """Updates (or creates) an environment."""
    env = Environment(environment, stage=stage, parameters=parameters)
    if not pretend:
        env.create(output_file=output, update=True)
Пример #28
0
def set_secret(environment, key, value, stage, pretend):
    """Stores a secret in the vault."""
    env = Environment(environment, stage=stage)
    if not pretend:
        env.set_secret(key, value)
Пример #29
0
def create(environment, stage, output, pretend, parameters, debug):
    """Creates an environment."""
    env = Environment(environment, stage=stage, parameters=parameters)
    if not pretend:
        env.create(output_file=output, update=False, debug=debug)
Пример #30
0
def set_secret(environment, key, value, stage, pretend):
    """Stores a secret in the vault."""
    env = Environment(environment, stage=stage)
    if not pretend:
        env.set_secret(key, value)
Пример #31
0
def get_secret(environment, key, stage, pretend):
    """Gets a secret from the vault."""
    env = Environment(environment, stage=stage)
    if not pretend:
        resp = env.get_secret(key)
        print(resp)
Пример #32
0
def environment(settings):
    """The io-streams-test humilis environment."""
    env = Environment(settings.environment_path, stage=settings.stage)
    env.create()
    return env