Skip to content

Commit

Permalink
add a flag to credstash get to return metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
kiran committed Feb 12, 2020
1 parent 082c51f commit 34136db
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions credstash.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,16 @@ def getSecretAction(args, region, **session_params):
output_args = {}
sys.stdout.write(output_func(secrets, **output_args))
else:
sys.stdout.write(repr(getSecretAndMetadata(args.credential, args.version,
region=region, table=args.table,
context=args.context,
**session_params)))
if args.include_metadata:
sys.stdout.write(repr(getSecretAndMetadata(args.credential, args.version,
region=region, table=args.table,
context=args.context,
**session_params)))
else:
sys.stdout.write(getSecret(args.credential, args.version,
region=region, table=args.table,
context=args.context,
**session_params))
if not args.noline:
sys.stdout.write("\n")
except ItemNotFound as e:
Expand All @@ -497,14 +503,14 @@ def getSecret(name, version="", region=None,
fetch and decrypt the secret called `name`
'''
secret, context = getSecretAndMetadata(name=name, version=version, region=region,
table=table, context=context, dynamodb=dynamodb,
kms=kms, **kwargs)
table=table, context=context, dynamodb=dynamodb,
kms=kms, **kwargs)
return secret


def getSecretAndMetadata(name, version="", region=None,
table="credential-store", context=None,
dynamodb=None, kms=None, **kwargs):
table="credential-store", context=None,
dynamodb=None, kms=None, **kwargs):
"""
fetch and decrypt the secret called `name`, and also return its version and
comments.
Expand Down Expand Up @@ -855,6 +861,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

0 comments on commit 34136db

Please sign in to comment.