Ejemplo n.º 1
0
    # A map like this is actually defined in boto.s3 in newer versions of boto
    # but we reproduce it here for the folks (notably, Ubuntu 12.04) on older
    # versions.
    'us-west-1': 's3-us-west-1.amazonaws.com',
    'us-west-2': 's3-us-west-2.amazonaws.com',
    'ap-northeast-1': 's3-ap-northeast-1.amazonaws.com',
    'ap-southeast-1': 's3-ap-southeast-1.amazonaws.com',
    'ap-southeast-2': 's3-ap-southeast-2.amazonaws.com',
    'eu-west-1': 's3-eu-west-1.amazonaws.com',
}


try:
    # Override our hard-coded region map with boto's mappings if available.
    from boto.s3 import regions
    _S3_REGIONS.update(dict((r.name, r.endpoint) for r in regions()))
except ImportError:
    pass


def s3_endpoint_for_uri(s3_uri, c_args=None, c_kwargs=None, connection=None):
    # 'connection' argument is used for unit test dependency injection
    # Work around boto/443 (https://github.com/boto/boto/issues/443)
    bucket_name = urlparse(s3_uri).netloc
    default = 's3.amazonaws.com'

    if bucket_name not in s3_endpoint_for_uri.cache:
        c_args = c_args or ()
        c_kwargs = c_kwargs or {}

        if bucket_name.lower() != bucket_name:
Ejemplo n.º 2
0
_S3_REGIONS = {
    # A map like this is actually defined in boto.s3 in newer versions of boto
    # but we reproduce it here for the folks (notably, Ubuntu 12.04) on older
    # versions.
    'us-west-1': 's3-us-west-1.amazonaws.com',
    'us-west-2': 's3-us-west-2.amazonaws.com',
    'ap-northeast-1': 's3-ap-northeast-1.amazonaws.com',
    'ap-southeast-1': 's3-ap-southeast-1.amazonaws.com',
    'ap-southeast-2': 's3-ap-southeast-2.amazonaws.com',
    'eu-west-1': 's3-eu-west-1.amazonaws.com',
}

try:
    # Override our hard-coded region map with boto's mappings if available.
    from boto.s3 import regions
    _S3_REGIONS.update(dict((r.name, r.endpoint) for r in regions()))
except ImportError:
    pass


def s3_endpoint_for_uri(s3_uri, c_args=None, c_kwargs=None, connection=None):
    # 'connection' argument is used for unit test dependency injection
    # Work around boto/443 (https://github.com/boto/boto/issues/443)
    bucket_name = urlparse(s3_uri).netloc
    default = 's3.amazonaws.com'

    if bucket_name not in s3_endpoint_for_uri.cache:
        try:
            # Attempting to use .get_bucket() with OrdinaryCallingFormat raises
            # a S3ResponseError (status 301).  See boto/443 referenced above.
            c_args = c_args or ()
Ejemplo n.º 3
0
    'ap-northeast-1': u's3-ap-northeast-1.amazonaws.com',
    'ap-southeast-1': u's3-ap-southeast-1.amazonaws.com',
    'ap-southeast-2': u's3-ap-southeast-2.amazonaws.com',
    'eu-central-1': u's3-eu-central-1.amazonaws.com',
    'eu-west-1': u's3-eu-west-1.amazonaws.com',
    'sa-east-1': u's3-sa-east-1.amazonaws.com',
    'us-east-1': u's3.amazonaws.com',
    'us-west-1': u's3-us-west-1.amazonaws.com',
    'us-west-2': u's3-us-west-2.amazonaws.com',
}

try:
    # Override the hard-coded region map with boto's mappings if
    # available.
    from boto.s3 import regions
    _S3_REGIONS.update(dict((r.name, unicode(r.endpoint)) for r in regions()))
except ImportError:
    pass


def _is_ipv4_like(s):
    """Find if a string superficially looks like an IPv4 address.

    AWS documentation plays it fast and loose with this; in other
    regions, it seems like even non-valid IPv4 addresses (in
    particular, ones that possess decimal numbers out of range for
    IPv4) are rejected.
    """
    parts = s.split('.')

    if len(parts) != 4:
Ejemplo n.º 4
0
SHARDS = ([chr(i) for i in range(ord('a'), ord('z') + 1)] +
          [chr(i) for i in range(ord('0'), ord('9') + 1)])

DEFAULTS = {
    'concurrency': len(SHARDS),
}

CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])


@click.command(context_settings=CONTEXT_SETTINGS)
@click.version_option()
@click.option('-c', '--config-file', type=click.Path(dir_okay=False, writable=True),
              default=os.path.join(os.path.expanduser('~'), '.s3tailrc'),
              help='Configuration file', show_default=True)
@click.option('-r', '--region', type=click.Choice(r.name for r in s3.regions()),
              help='AWS region to use when connecting')
@click.option('-l', '--log-level',
              type=click.Choice(['debug', 'info', 'warning', 'error', 'critical']),
              help='set logging level')
@click.option('--log-file', metavar='FILENAME', help='write logs to FILENAME')
@click.option('--concurrency', type=int, default=DEFAULTS['concurrency'], show_default=True,
              help='set number of workers processing jobs simultaneously')
@click.option('--select', 'selection_string',
              help='provide comparisons against object name, size, md5, or last_modified to limit '
                   'selection')
@click.option('--reduce', 'reduction_string',
              help='provide reduction logic against the accumulator value for all selected objects')
@click.option('--accumulator', 'accumulation_string', default='0', show_default=True,
              help='provide a different initial accumulation value for the reduce option')
@click.argument('command', type=click.Choice(['list', 'delete']))
Ejemplo n.º 5
0
 def get_regions(self):
   """Get all available regions for the Amazon S3 service."""
   return s3.regions()