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

allow specifying an endpoint_url override #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
21 changes: 15 additions & 6 deletions confidant_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def __init__(
retries=None,
backoff=None,
config_files=None,
profile=None
profile=None,
kms_endpoint_url=None
):
"""Create a ConfidantClient object.

Expand Down Expand Up @@ -78,6 +79,8 @@ def __init__(
configuration from. First file found will be used. Default:
['~/.confidant', '/etc/confidant/config']
profile: profile to read config values from.
kms_endpoint_url: A URL to override the default endpoint used to
access the KMS service. Default: None
"""
# Set defaults
self.config = {
Expand All @@ -90,7 +93,8 @@ def __init__(
'assume_role': None,
'region': None,
'retries': 0,
'backoff': 1
'backoff': 1,
'kms_endpoint_url': None
}
if config_files is None:
config_files = ['~/.confidant', '/etc/confidant/config']
Expand All @@ -108,7 +112,8 @@ def __init__(
'token_cache_file': token_cache_file,
'region': region,
'backoff': backoff,
'assume_role': assume_role
'assume_role': assume_role,
'kms_endpoint_url': kms_endpoint_url
}
for key, val in args_config.iteritems():
if val is not None:
Expand Down Expand Up @@ -138,7 +143,9 @@ def __init__(
)
self.kms_client = confidant_client.services.get_boto_client(
'kms',
region=self.config['region']
region=self.config['region'],
endpoint_url=self.config['kms_endpoint_url']

)
if self.config['assume_role']:
self.aws_creds = self._get_assume_role_creds(
Expand All @@ -157,7 +164,8 @@ def __init__(
token_version=self.config['token_version'],
token_cache_file=self.config['token_cache_file'],
token_lifetime=self.config['token_lifetime'],
aws_creds=self.aws_creds
aws_creds=self.aws_creds,
endpoint_url=self.config['kms_endpoint_url']
)
except kmsauth.ConfigurationError:
raise ClientConfigurationError('Error configuring kmsauth client.')
Expand Down Expand Up @@ -369,7 +377,8 @@ def _get_decrypted_pairs(self, credential):
region=self.config['region'],
aws_access_key_id=self.aws_creds['AccessKeyId'],
aws_secret_access_key=self.aws_creds['SecretAccessKey'],
aws_session_token=self.aws_creds['SessionToken']
aws_session_token=self.aws_creds['SessionToken'],
endpoint_url=self.config['kms_endpoint_url']
)
else:
_kms_client = self.kms_client
Expand Down
7 changes: 6 additions & 1 deletion confidant_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def _get_client_from_args(args):
region=args.region,
retries=args.retries,
config_files=config_files,
profile=args.profile
profile=args.profile,
kms_endpoint_url=args.kms_endpoint_url
)
return client

Expand Down Expand Up @@ -133,6 +134,10 @@ def _parse_args():
'--region',
help='Use the specified region for authentication.'
)
parser.add_argument(
'--kms-endpoint-url',
help='Use a different endpoint url for the KMS service.'
)
parser.add_argument(
'--log-level',
help='Logging verbosity.',
Expand Down
7 changes: 4 additions & 3 deletions confidant_client/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ def get_boto_client(
region=None,
aws_access_key_id=None,
aws_secret_access_key=None,
aws_session_token=None
aws_session_token=None,
endpoint_url=None
):
"""Get a boto3 client connection."""
cache_key = '{0}:{1}:{2}'.format(client, region, aws_access_key_id)
cache_key = '{0}:{1}:{2}:{3}'.format(client, region, aws_access_key_id, endpoint_url)
if not aws_session_token:
if cache_key in CLIENT_CACHE:
return CLIENT_CACHE[cache_key]
Expand All @@ -28,7 +29,7 @@ def get_boto_client(
logging.error("Failed to get {0} client.".format(client))
return None

CLIENT_CACHE[cache_key] = session.client(client)
CLIENT_CACHE[cache_key] = session.client(client, endpoint_url=endpoint_url)
return CLIENT_CACHE[cache_key]


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# Licence: Apache2
# Upstream url: https://github.com/lyft/python-kmsauth
# Use: client authentication to confidant
'kmsauth>=0.1.6,<1.0.0',
'kmsauth>=0.2.0,<1.0.0',

# Provides enhanced HTTPS support for httplib and urllib2 using PyOpenSSL
# License: BSD
Expand Down