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

Resolves #93: Uses boto3 to find region if possible #180

Open
wants to merge 2 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
17 changes: 6 additions & 11 deletions credstash.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
DEFAULT_DIGEST = 'SHA256'
HASHING_ALGORITHMS = _hash_classes.keys()
LEGACY_NONCE = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
DEFAULT_REGION = "us-east-1"
PAD_LEN = 19 # number of digits in sys.maxint
WILDCARD_CHAR = "*"

Expand Down Expand Up @@ -665,13 +664,10 @@ def get_parser():
description="A credential/secret storage system")

parsers['super'].add_argument("-r", "--region",
help="the AWS region in which to operate. "
help="The AWS region in which to operate. "
"If a region is not specified, credstash "
"will use the value of the "
"AWS_DEFAULT_REGION env variable, "
"or if that is not set, the value in "
"`~/.aws/config`. As a last resort, "
"it will use " + DEFAULT_REGION)
"will follow the default credential provider"
"chain as defined in the boto3 documentation.")
parsers['super'].add_argument("-t", "--table", default="credential-store",
help="DynamoDB table to use for "
"credential storage")
Expand Down Expand Up @@ -791,14 +787,13 @@ def main():

# Check for assume role and set session params
session_params = get_session_params(args.profile, args.arn)
region = args.region if args.region else None

try:
region = args.region
session = get_session(**session_params)
session.resource('dynamodb', region_name=region)
except botocore.exceptions.NoRegionError:
if 'AWS_DEFAULT_REGION' not in os.environ:
region = DEFAULT_REGION
except botocore.exceptions.NoRegionError as e:
fatal(e)

if "action" in vars(args):
if args.action == "delete":
Expand Down