def _get_credentials(rse, endpoint): """ Pass an endpoint and return its credentials. :param endpoint: URL endpoint string. :param rse: RSE name. :returns: Dictionary of credentials. """ key = '%s_%s' % (rse, endpoint) result = REGION.get(key) if type(result) is NoValue: try: logging.debug("Loading account credentials") result = config.get_rse_credentials(None) if result and rse in result: result = result[rse] result['is_secure'] = result['is_secure'][endpoint] REGION.set(key, result) else: raise Exception("Failed to load account credentials") logging.debug("Loaded account credentials") except KeyError, e: raise exception.CannotAuthenticate( 'RSE %s endpoint %s not in rse account cfg: %s' % (rse, endpoint, e)) except:
def _get_connection(rse, endpoint): """ Pass an endpoint and return a connection to object store. :param rse: RSE name. :param endpoint: URL endpoint string. :returns: Connection object. """ key = "connection:%s_%s" % (rse, endpoint) result = REGION.get(key) if type(result) is NoValue: try: logging.debug("Creating connection object") result = None credentials = _get_credentials(rse, endpoint) if 'access_key' in credentials and credentials['access_key'] and \ 'secret_key' in credentials and credentials['secret_key'] and \ 'is_secure' in credentials and credentials['is_secure'] is not None: parsed = urlparse.urlparse(endpoint) hostname = parsed.netloc.partition(':')[0] port = parsed.netloc.partition(':')[2] result = boto.connect_s3( aws_access_key_id=credentials['access_key'], aws_secret_access_key=credentials['secret_key'], host=hostname, port=int(port), is_secure=credentials['is_secure'], calling_format=boto.s3.connection.OrdinaryCallingFormat()) REGION.set(key, result) logging.debug("Created connection object") else: raise exception.CannotAuthenticate( "Either access_key, secret_key or is_secure is not defined for RSE %s endpoint %s" % (rse, endpoint)) except exception.RucioException as e: raise e except: raise exception.RucioException( "Failed to get connection for RSE(%s) endpoint(%s), error: %s" % (rse, endpoint, traceback.format_exc())) return result