Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update keyvalue.py to be able to add new values without leaking them in the shell history. #5164

Merged
8 changes: 6 additions & 2 deletions st2client/st2client/commands/keyvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def __init__(self, resource, *args, **kwargs):
self.parser.add_argument(
"name", metavar="name", help="Name of the key value pair."
)
self.parser.add_argument("value", help="Value paired with the key.")
self.parser.add_argument("value", help="Value paired with the key.", nargs="?")
self.parser.add_argument(
"-l",
"--ttl",
Expand Down Expand Up @@ -285,10 +285,14 @@ def run(self, args, **kwargs):
instance = KeyValuePair()
instance.id = args.name # TODO: refactor and get rid of id
instance.name = args.name
instance.value = args.value
instance.scope = args.scope
instance.user = args.user

if not args.value:
instance.value = input("Please insert value for key: ")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also getpass.getpass() which displays entered value masked on the screen.

But if we go with that approach, we will likely need to ask for confirmation (aka input the secret value twice).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything you want to change here or will it be implemented in version 3.5? Nevertheless it is possible to check the value after it was inserted in the key value store.

Copy link
Member

@cognifloyd cognifloyd Jun 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a future PR, I think we could add getpass.getpass() support, but only turn it on if encrypt is True. I think this PR is good enough to merge as is.

else:
instance.value = args.value

if args.secret:
instance.secret = args.secret

Expand Down