コード例 #1
0
def _create_s3_connection(config, region):
    calling_format = bsc.OrdinaryCallingFormat()
    if region:
        conn = bs.connect_to_region(
            region,
            aws_access_key_id=config[tac.key_id],
            aws_secret_access_key=config[tac.secret_key],
            proxy=config.get(tac.proxy_hostname),
            proxy_port=config.get(tac.proxy_port),
            proxy_user=config.get(tac.proxy_username),
            proxy_pass=config.get(tac.proxy_password),
            is_secure=True,
            validate_certs=True,
            calling_format=calling_format)
    else:
        if (not os.environ.get("S3_USE_SIGV4") and
                not config.get(asc.bucket_name)):
            calling_format = bsc.SubdomainCallingFormat()

        conn = boto.connect_s3(
            host=config[asc.host_name],
            aws_access_key_id=config[tac.key_id],
            aws_secret_access_key=config[tac.secret_key],
            proxy=config.get(tac.proxy_hostname),
            proxy_port=config.get(tac.proxy_port),
            proxy_user=config.get(tac.proxy_username),
            proxy_pass=config.get(tac.proxy_password),
            is_secure=True,
            validate_certs=True,
            calling_format=calling_format)
    return conn
コード例 #2
0
def _s3connection_opts_from_uri(impl):
    # 'impl' should look like:
    #
    #    <protocol>+<calling_format>://[user:pass]@<host>[:port]
    #
    # A concrete example:
    #
    #     https+virtualhost://user:pass@localhost:1235
    o = urlparse.urlparse(impl, allow_fragments=False)

    if o.scheme is not None:
        proto_match = re.match(
            r'(?P<protocol>http|https)\+'
            r'(?P<format>virtualhost|path|subdomain)', o.scheme)
        if proto_match is None:
            raise UserException(
                msg='WALE_S3_ENDPOINT URI scheme is invalid',
                detail='The scheme defined is ' + repr(o.scheme),
                hint='An example of a valid scheme is https+virtualhost.')

    opts = {}

    if proto_match.group('protocol') == 'http':
        opts['is_secure'] = False
    else:
        # Constrained by prior regexp.
        proto_match.group('protocol') == 'https'
        opts['is_secure'] = True

    f = proto_match.group('format')
    if f == 'virtualhost':
        opts['calling_format'] = connection.VHostCallingFormat()
    elif f == 'path':
        opts['calling_format'] = connection.OrdinaryCallingFormat()
    elif f == 'subdomain':
        opts['calling_format'] = connection.SubdomainCallingFormat()
    else:
        # Constrained by prior regexp.
        assert False

    if o.username is not None or o.password is not None:
        raise UserException(
            msg='WALE_S3_ENDPOINT does not support username or password')

    if o.hostname is not None:
        opts['host'] = o.hostname

    if o.port is not None:
        opts['port'] = o.port

    if o.path:
        raise UserException(
            msg='WALE_S3_ENDPOINT does not support a URI path',
            detail='Path is {0!r}'.format(o.path))

    if o.query:
        raise UserException(
            msg='WALE_S3_ENDPOINT does not support query parameters')

    return opts
コード例 #3
0
    def __connect(self):
        '''Connect, leaving self.__conn and self.__bucket valid.'''
        self.__conn = None  # make sure it's bound even on failure
        self.__bucket = None  # ditto

        log.debug('attempting to connect to s3')
        self.__conn = connection.S3Connection(host=self.__opts.get(
            's3_host', connection.S3Connection.DefaultHost))
        self.__conn.calling_format = connection.SubdomainCallingFormat()
        self.__bucket = self.__conn.lookup(self.bucket_name)
コード例 #4
0
    def __connect(self):
        '''Connect, leaving self.__conn and self.__bucket valid.'''
        self.__conn = None  # make sure it's bound even on failure
        self.__the_bucket = None  # ditto

        log.debug('attempting to connect to s3')
        self.__conn = connection.S3Connection(
            host=self.__opts.get('s3_host',
                                 connection.S3Connection.DefaultHost),
            proxy=self.__opts.get('proxy', None),
            proxy_port=self.__opts.get('proxy_port', None),
            is_secure=self.__opts.get('https', True),
            aws_access_key_id=self.__opts.get('aws_access_key_id', None),
            aws_secret_access_key=self.__opts.get('aws_secret_access_key',
                                                  None))
        self.__conn.calling_format = connection.SubdomainCallingFormat()

        self.__the_bucket = self.__conn.lookup(self.bucket_name)