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

return context with secret material with getSecretAndContext #258

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 40 additions & 10 deletions credstash.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,26 @@ def getSecretAction(args, region, kms_region, **session_params):
output_args = {}
sys.stdout.write(output_func(secrets, **output_args))
else:
sys.stdout.write(getSecret(
args.credential,
version=args.version,
region=region,
kms_region=kms_region,
table=args.table,
context=args.context,
**session_params
))
if args.include_metadata:
sys.stdout.write(repr(getSecretAndMetadata(
args.credential,
version=args.version,
region=region,
kms_region=kms_region,
table=args.table,
context=args.context,
**session_params
)))
else:
sys.stdout.write(getSecret(
args.credential,
version=args.version,
region=region,
kms_region=kms_region,
table=args.table,
context=args.context,
**session_params
))
if not args.noline:
sys.stdout.write("\n")
except ItemNotFound as e:
Expand All @@ -554,6 +565,19 @@ def getSecret(name, version="", region=None, table="credential-store", context=N
'''
fetch and decrypt the secret called `name`
'''
secret, context = getSecretAndMetadata(name=name, version=version, region=region,
table=table, context=context, dynamodb=dynamodb,
kms=kms, kms_region=kms_region, **kwargs)
return secret


def getSecretAndMetadata(name, version="", region=None,
table="credential-store", context=None,
dynamodb=None, kms=None, kms_region=None, **kwargs):
"""
fetch and decrypt the secret called `name`, and also return its version and
comments.
"""
if not context:
context = {}

Expand Down Expand Up @@ -587,7 +611,10 @@ def getSecret(name, version="", region=None, table="credential-store", context=N

key_service = KeyService(kms, None, context)

return open_aes_ctr_legacy(key_service, material)
return (
open_aes_ctr_legacy(key_service, material),
{"version": material.get("version"), "comment": material.get("comment")}
)


@clean_fail
Expand Down Expand Up @@ -961,6 +988,9 @@ def get_parser():
([] if NO_YAML else ["yaml"]),
help="Output format. json(default) " +
("" if NO_YAML else "yaml ") + " csv or dotenv.")
parsers[action].add_argument("-m", "--include-metadata", action="store_true",
help="Return secret metadata (version and comment)"
"along with the secret itself.")
parsers[action].set_defaults(action=action)

action = 'getall'
Expand Down