Merge "Initialize aws client with proxies"
This commit is contained in:
commit
e1a8602378
|
@ -15,6 +15,7 @@ BuildRequires: python2-wheel
|
|||
BuildRequires: systemd
|
||||
Requires: pyparted
|
||||
Requires: python-boto3
|
||||
Requires: python2-botocore >= 1.11.0
|
||||
Requires: python-docker
|
||||
Requires: python-eventlet
|
||||
Requires: python-ipaddr
|
||||
|
|
|
@ -4,6 +4,7 @@ amqplib>=0.6.1
|
|||
anyjson>=0.3.3
|
||||
argparse
|
||||
boto3
|
||||
botocore>=1.11.0
|
||||
cryptography!=2.0 # BSD/Apache-2.0
|
||||
eventlet==0.20.0
|
||||
greenlet>=0.3.2 # MIT
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
"""Utilities and helper functions."""
|
||||
|
||||
import boto3
|
||||
from botocore.config import Config
|
||||
import collections
|
||||
import contextlib
|
||||
import datetime
|
||||
|
@ -2147,19 +2148,51 @@ def get_local_docker_registry_auth():
|
|||
password=registry_password)
|
||||
|
||||
|
||||
def get_aws_ecr_registry_credentials(registry, username, password):
|
||||
region = re.compile("[0-9]*.dkr.ecr.(.*).amazonaws.com.*").match(registry)
|
||||
if region:
|
||||
ecr_region = region.groups()[0]
|
||||
else:
|
||||
ecr_region = 'us-west-2'
|
||||
def get_aws_ecr_registry_credentials(dbapi, registry, username, password):
|
||||
def _set_advanced_config_for_botocore_client(dbapi):
|
||||
""" This function is to set advanced configuration
|
||||
for botocore client
|
||||
|
||||
supported configuration:
|
||||
proxies(optional): A dictionary of proxy servers
|
||||
to use by protocal or endpoint.
|
||||
e.g.:
|
||||
{'http': 'http://128.224.150.2:3128',
|
||||
'https': 'http://128.224.150.2:3129'}
|
||||
|
||||
"""
|
||||
config = None
|
||||
|
||||
proxies = dbapi.service_parameter_get_all(
|
||||
service=constants.SERVICE_TYPE_DOCKER,
|
||||
section=constants.SERVICE_PARAM_SECTION_DOCKER_PROXY)
|
||||
|
||||
proxies_dict = {}
|
||||
for proxy in proxies:
|
||||
if proxy.name == constants.SERVICE_PARAM_NAME_DOCKER_HTTP_PROXY:
|
||||
proxies_dict.update({'http': str(proxy.value)})
|
||||
|
||||
elif proxy.name == constants.SERVICE_PARAM_NAME_DOCKER_HTTPS_PROXY:
|
||||
proxies_dict.update({'https': str(proxy.value)})
|
||||
|
||||
if proxies_dict:
|
||||
config = Config(proxies=proxies_dict)
|
||||
return config
|
||||
|
||||
try:
|
||||
region = re.compile("[0-9]*.dkr.ecr.(.*).amazonaws.com.*").match(registry)
|
||||
if region:
|
||||
ecr_region = region.groups()[0]
|
||||
else:
|
||||
ecr_region = 'us-west-2'
|
||||
|
||||
config = _set_advanced_config_for_botocore_client(dbapi)
|
||||
client = boto3.client(
|
||||
'ecr',
|
||||
region_name=ecr_region,
|
||||
aws_access_key_id=username,
|
||||
aws_secret_access_key=password)
|
||||
aws_secret_access_key=password,
|
||||
config=config)
|
||||
|
||||
response = client.get_authorization_token()
|
||||
token = response['authorizationData'][0]['authorizationToken']
|
||||
|
|
|
@ -2685,7 +2685,7 @@ class DockerHelper(object):
|
|||
if (section in registries_type and
|
||||
registries_type[section] == constants.DOCKER_REGISTRY_TYPE_AWS_ECR):
|
||||
auth = cutils.get_aws_ecr_registry_credentials(
|
||||
url, auth['username'], auth['password'])
|
||||
self._dbapi, url, auth['username'], auth['password'])
|
||||
self.registries_info[section]['registry_auth'] = auth
|
||||
except exception.SysinvException:
|
||||
raise exception.SysinvException(_(
|
||||
|
|
Loading…
Reference in New Issue