def _get_location(self): if get_default_region() in (Location.EU, Location.EUCentral1, Location.CACentral, Location.USWest, Location.USWest2, Location.SAEast, Location.APNortheast, Location.APSoutheast, Location.APSoutheast2, Location.CNNorth1): return get_default_region() else: return Location.DEFAULT
def from_config(cls, conf, credential_provider): credential_provider.validate() credentials = credential_provider.get_credentials() if conf: return cls( aws_access_key_id=credentials.get('AccessKeyId'), aws_secret_access_key=credentials.get('SecretAccessKey'), aws_security_token=credentials.get('SessionToken'), region=aws_conf.get_default_region(), host=conf.HOST.get(), proxy_address=conf.PROXY_ADDRESS.get(), proxy_port=conf.PROXY_PORT.get(), proxy_user=conf.PROXY_USER.get(), proxy_pass=conf.PROXY_PASS.get(), calling_format=conf.CALLING_FORMAT.get(), is_secure=conf.IS_SECURE.get(), expiration=credentials.get('Expiration') ) else: return cls( aws_access_key_id=credentials.get('AccessKeyId'), aws_secret_access_key=credentials.get('SecretAccessKey'), aws_security_token=credentials.get('SessionToken'), expiration=credentials.get('Expiration') )
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, aws_security_token=None, region=None, timeout=HTTP_SOCKET_TIMEOUT_S, host=None, proxy_address=None, proxy_port=None, proxy_user=None, proxy_pass=None, calling_format=None, is_secure=True): self._access_key_id = aws_access_key_id self._secret_access_key = aws_secret_access_key self._security_token = aws_security_token self._region = region.lower() if region else get_default_region() self._timeout = timeout self._host = host self._proxy_address = proxy_address self._proxy_port = proxy_port self._proxy_user = proxy_user self._proxy_pass = proxy_pass self._calling_format = DEFAULT_CALLING_FORMAT if calling_format is None else calling_format self._is_secure = is_secure if not boto.config.has_section('Boto'): boto.config.add_section('Boto') if not boto.config.get('Boto', 'http_socket_timeout'): boto.config.set('Boto', 'http_socket_timeout', str(self._timeout))
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, region=None, timeout=HTTP_SOCKET_TIMEOUT_S): self._access_key_id = aws_access_key_id self._secret_access_key = aws_secret_access_key self._region = region.lower() if region else get_default_region() self._timeout = timeout boto.config.add_section('Boto') boto.config.set('Boto', 'http_socket_timeout', str(self._timeout))
def test_get_default_region(): # Verify that Hue can infer region from subdomain hosts finish = conf.AWS_ACCOUNTS.set_for_testing({'default': {'host': 's3.ap-northeast-2.amazonaws.com'}}) try: assert_equal('ap-northeast-2', get_default_region()) finally: if finish: finish() # Verify that Hue can infer region from hyphenated hosts finish = conf.AWS_ACCOUNTS.set_for_testing({'default': {'host': 's3-ap-south-1.amazonaws.com'}}) try: assert_equal('ap-south-1', get_default_region()) finally: if finish: finish() # Verify that Hue can infer region from hyphenated hosts finish = conf.AWS_ACCOUNTS.set_for_testing({'default': {'host': 's3.dualstack.ap-southeast-2.amazonaws.com'}}) try: assert_equal('ap-southeast-2', get_default_region()) finally: if finish: finish() # Verify that Hue falls back to the default if the region is not valid finish = conf.AWS_ACCOUNTS.set_for_testing({'default': {'host': 's3-external-1.amazonaws.com'}}) try: assert_equal(Location.DEFAULT, get_default_region()) finally: if finish: finish() # Verify that Hue uses the region if specified finish = conf.AWS_ACCOUNTS.set_for_testing({'default': {'host': '', 'region': 'ca-central-1'}}) try: assert_equal('ca-central-1', get_default_region()) finally: if finish: finish()
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, aws_security_token=None, region=None, timeout=HTTP_SOCKET_TIMEOUT_S, proxy_address=None, proxy_port=None, calling_format=None, is_secure=True): self._access_key_id = aws_access_key_id self._secret_access_key = aws_secret_access_key self._security_token = aws_security_token self._region = region.lower() if region else get_default_region() self._timeout = timeout self._proxy_address = proxy_address self._proxy_port = proxy_port self._calling_format = DEFAULT_CALLING_FORMAT if calling_format is None else calling_format self._is_secure = is_secure boto.config.add_section('Boto') boto.config.set('Boto', 'http_socket_timeout', str(self._timeout))
def from_config(cls, conf): access_key_id = conf.ACCESS_KEY_ID.get() secret_access_key = conf.SECRET_ACCESS_KEY.get() security_token = conf.SECURITY_TOKEN.get() env_cred_allowed = conf.ALLOW_ENVIRONMENT_CREDENTIALS.get() if None in (access_key_id, secret_access_key) and not env_cred_allowed and not has_iam_metadata(): raise ValueError('Can\'t create AWS client, credential is not configured') return cls( aws_access_key_id=access_key_id, aws_secret_access_key=secret_access_key, aws_security_token=security_token, region=get_default_region(), host=conf.HOST.get(), proxy_address=conf.PROXY_ADDRESS.get(), proxy_port=conf.PROXY_PORT.get(), proxy_user=conf.PROXY_USER.get(), proxy_pass=conf.PROXY_PASS.get(), calling_format=conf.CALLING_FORMAT.get(), is_secure=conf.IS_SECURE.get() )
def _get_location(self): if get_default_region() in get_locations(): return get_default_region() else: return Location.DEFAULT
def _get_location(self): if get_default_region() in (Location.EU, Location.EUCentral1, Location.USWest, Location.USWest2, Location.SAEast, Location.APNortheast, Location.APSoutheast, Location.APSoutheast2, Location.CNNorth1): return get_default_region() else: return Location.DEFAULT