-
Notifications
You must be signed in to change notification settings - Fork 60
Feature request: ability to specify keystore parameters as environment variables #955
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
Comments
Looked at this during the dev call, looks like a good feature. |
If I do this, I would like to extract all the duplicated declarations of --name, --base and --passcode Option 1I could use https://docs.python.org/3/library/argparse.html#parents and then a common module to create the key store arguments parser: # cli.common.habbing module
from argparse import ArgumentParser
from os import getenv
def createKeystoreArgsParser(required: bool = True):
parser = ArgumentParser(add_help=False)
parser.add_argument('--name', '-n',
help='keystore name and file location of KERI keystore',
required=required,
default=getenv("KLI_KEYSTORE_NAME", None))
parser.add_argument('--base', '-b',
help='additional optional prefix to file location of KERI keystore',
required=False,
default=getenv("KLI_KEYSTORE_BASE", ""))
parser.add_argument('--passcode', '-p',
help='21 character encryption passcode for keystore (is not saved)',
dest="bran",
default=None)
return parser
# cli.sample-command module
from cli.common.habbing import createKeystoreArgsParser
from argparse import ArgumentParser
parser = argparse.ArgumentParser(description='Do some magic with the keystore', parents=[createKeystoreArgsParser()])
parser.set_defaults(handler=handler)
parser.add_argument('--other', '-o', help='some useful option specific to this command') Option 2Use a function that adds arguments to an existing parser # cli.common.habbing module
from argparse import ArgumentParser
from os import getenv
def addKeystoreArgs(parser: ArgumentParser, required: bool = True):
parser.add_argument('--name', '-n',
help='keystore name and file location of KERI keystore',
required=required,
default=getenv("KLI_KEYSTORE_NAME", None))
parser.add_argument('--base', '-b',
help='additional optional prefix to file location of KERI keystore',
required=False,
default=getenv("KLI_KEYSTORE_BASE", ""))
parser.add_argument('--passcode', '-p',
help='21 character encryption passcode for keystore (is not saved)',
dest="bran",
default=None)
return parser
# cli.sample-command module
from cli.common.habbing import addKeystoreArgs
from argparse import ArgumentParser
parser = argparse.ArgumentParser(description='Do some magic with the keystore'])
parser.set_defaults(handler=handler)
addKeystoreArgs(parser)
parser.add_argument('--other', '-o', help='some useful option specific to this command') Option 3I could use a shared Option 4I simply add default to all commands. Other options |
Option 1 seems like the best option since that integrates with how argparse works. It does seem very similar to the function in Option 2. |
Uh oh!
There was an error while loading. Please reload this page.
Feature request description/rationale
I would like to be able to call kli commands that require keystore parameters such as
--name
,--base
and possibly--passcode
without having to supply them on the command line.Example use:
The environment variables can be stored in files that I can source or load whichever way I want. If I run kli in a docker container, I would set the environment variables as part of the docker runtime.
Implementation
Implementation would be rather straightforward I think. We can just add default variables to the arguments.
If you accept this feature request, I can open up a PR. Let me know your opinion. Also, whether or not you think the passcode can be added to the environment as well? If you think it is unsafe, we can add call it
KERIPY_UNSAFE_PASSCODE
or something, or skip it.The text was updated successfully, but these errors were encountered: