Skip to content

Commit

Permalink
REL-4242 - KSM CLI - Add --profile-name to ksm profile import com…
Browse files Browse the repository at this point in the history
…mand (#532)

* Added --profile-name option to `ksm profile import` command (#478)
  • Loading branch information
maksimu authored Sep 16, 2023
1 parent ab6b737 commit 5986508
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
4 changes: 4 additions & 0 deletions integration/keeper_secrets_manager_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ For more information see our official documentation page https://docs.keeper.io/

# Change History

## 1.1.1

* KSM-429 - Add `--profile-name` to `ksm profile import` command

## 1.1.0
* KSM-395 - New feature to load configurations from AWS Secrets Manager

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,16 @@ def profile_export_command(ctx, plain, file_format, profile_name):
cls=HelpColorsCommand,
help_options_color='blue'
)
@click.option('--profile-name', '-p', type=str, required=False, help='Config profile to import into.')
@click.option('--output-file', '-f', type=str, required=False, help='Create the config in a specific file location.')
@click.argument('config-base64', type=str, required=True, nargs=1)
@click.pass_context
def profile_import_command(ctx, output_file, config_base64):
def profile_import_command(ctx, profile_name, output_file, config_base64):
"""Import an encrypted config file"""
Profile(cli=ctx.obj["cli"], config=global_config).import_config(
file=output_file,
config_base64=config_base64,
file=output_file,
profile_name=profile_name,
launched_from_app=global_config.launched_from_app
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,7 @@ def import_config(config_base64, file=None, profile_name=None, launched_from_app

"""
Take base64 config file and write it back to disk.
This file could be a JSON or a Keeper ini file.
"""

config_data = base64.urlsafe_b64decode(config_base64.encode())
Expand All @@ -392,15 +390,26 @@ def import_config(config_base64, file=None, profile_name=None, launched_from_app

# If a JSON file was import, convert the JSON to a INI.
if is_json is True:
if profile_name is None:
profile_name = os.environ.get("KSM_CLI_PROFILE", Profile.default_profile)
config = Config(ini_file=file)

try:
# If the file exists attempt to load as INI to merge new config
config.load()
except:
pass # doesn't exists, inaccessible, or not INI: create new

config.set_profile_using_base64(
profile_name=Profile.default_profile,
profile_name=profile_name,
base64_config=config_base64
)
config.save()

# Else just save the INI. It's in the right format, just save it. No processing needed.
else:
if profile_name:
print("Ignored option --profile-name as incompaible with INI file format that can handle multiple profiles.")
with open(file, "w") as fh:
fh.write(config_data.decode())
fh.close()
Expand Down
4 changes: 2 additions & 2 deletions integration/keeper_secrets_manager_cli/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
keeper-secrets-manager-core>=16.5.4
keeper-secrets-manager-core>=16.6.2
keeper-secrets-manager-helper
keeper-secrets-manager-storage>=1.0.1
keeper-secrets-manager-storage>=1.0.2
prompt-toolkit~=2.0
jsonpath-rw-ext
colorama
Expand Down
2 changes: 1 addition & 1 deletion integration/keeper_secrets_manager_cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# Version set in the keeper_secrets_manager_cli.version file.
setup(
name="keeper-secrets-manager-cli",
version="1.1.0",
version="1.1.1",
description="Command line tool for Keeper Secrets Manager",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 5986508

Please sign in to comment.