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)
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)
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()
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)
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(): 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))
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()
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"]
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))
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()
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()
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()
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)
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()
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()
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()
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()
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()
def main(ctx, envpath, stage, parameters): """Polku sample app: deployment CLI.""" ctx.obj = {"env": Environment(envpath, stage=stage, parameters=parameters)} config.context = ctx.obj
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()
def test_environment(environment_definition_path, test_config): """A humilis environment based on the sample environment definition.""" return Environment(environment_definition_path)
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)
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)
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)
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)
def environment(settings): """The io-streams-test humilis environment.""" env = Environment(settings.environment_path, stage=settings.stage) env.create() return env