diff --git a/calm/dsl/cli/bp_commands.py b/calm/dsl/cli/bp_commands.py index 52625b4f..85ff007f 100644 --- a/calm/dsl/cli/bp_commands.py +++ b/calm/dsl/cli/bp_commands.py @@ -256,6 +256,13 @@ def create_blueprint_command(bp_file, name, description, force): @launch.command("bp") @click.argument("blueprint_name") +@click.option( + "--with_secrets", + "-ws", + is_flag=True, + default=False, + help="Preserve secrets while launching the blueprint", +) @click.option( "--environment", "-e", default=None, help="Environment for the application" ) @@ -299,6 +306,7 @@ def create_blueprint_command(bp_file, name, description, force): def launch_blueprint_command( blueprint_name, environment, + with_secrets, app_name, ignore_runtime_variables, profile_name, @@ -368,7 +376,7 @@ def launch_blueprint_command( app_name = app_name or "App-{}-{}".format(blueprint_name, int(time.time())) blueprint_name, blueprint = patch_bp_if_required( - environment, blueprint_name, profile_name + with_secrets, environment, blueprint_name, profile_name ) launch_blueprint_simple( diff --git a/calm/dsl/cli/bps.py b/calm/dsl/cli/bps.py index 5d7cd322..524e3326 100644 --- a/calm/dsl/cli/bps.py +++ b/calm/dsl/cli/bps.py @@ -1551,7 +1551,8 @@ def launch_blueprint_simple( LOG.error("[{}] - {}".format(err["code"], err["error"])) sys.exit("Unable to retrieve protection policies") protection_policies = [p["status"] for p in res.json()["entities"]] - res, err = client.environment.list() + payload = {"filter": "uuid=={}". format(env_uuids[0])} + res, err = client.environment.list(payload) if err: LOG.error("[{}] - {}".format(err["code"], err["error"])) sys.exit("Unable to retrieve environments") @@ -1745,7 +1746,7 @@ def delete_blueprint(blueprint_names): def create_patched_blueprint( - blueprint, project_data, environment_data, profile_name=None + blueprint, project_data, environment_data, profile_name=None, with_secrets=False ): """Patch the blueprint with the given environment to create a new blueprint""" client = get_api_client() @@ -1766,13 +1767,19 @@ def create_patched_blueprint( { "environment": {"uuid": env_uuid}, "app_profile": {"name": profile_name}, + "keep_secrets": with_secrets, } ], "new_blueprint": {"name": new_bp_name}, }, } - LOG.info("Creating Patched blueprint") + msg = ( + "Creating Patched blueprint with secrets preserved" + if with_secrets + else "Creating Patched blueprint" + ) + LOG.info(msg) bp_res, err = client.blueprint.patch_with_environment(org_bp_uuid, request_spec) if err: LOG.error("[{}] - {}".format(err["code"], err["error"])) @@ -1787,7 +1794,9 @@ def create_patched_blueprint( return bp_res -def patch_bp_if_required(environment_name=None, blueprint_name=None, profile_name=None): +def patch_bp_if_required( + with_secrets=False, environment_name=None, blueprint_name=None, profile_name=None +): """Patch the blueprint with the given environment to create a new blueprint if the requested app profile is not already linked to the given environment""" if environment_name: @@ -1816,7 +1825,7 @@ def patch_bp_if_required(environment_name=None, blueprint_name=None, profile_nam ) if ref_env_uuid != env_uuid: new_blueprint = create_patched_blueprint( - bp, project_data, environment_data, profile_name + bp, project_data, environment_data, profile_name, with_secrets ) return new_blueprint["metadata"]["name"], new_blueprint