def get_bucket(bucket_name, output='camelized', include_created=False, **conn): """ Orchestrates all the calls required to fully build out an S3 bucket in the following format: { "Arn": ..., "Owner": ..., "Grants": ..., "LifecycleRules": ..., "Logging": ..., "Policy": ..., "Tags": ..., "Versioning": ..., "Website": ..., "Cors": ..., "Notifications": ..., "Acceleration": ..., "Replication": ..., "Created": ..., "_version": 1 } :param include_created: :param bucket_name: str bucket name :param output: Determines whether keys should be returned camelized or underscored. :param conn: dict containing enough information to make a connection to the desired account. Must at least have 'assume_role' key. :return: dict containing a fully built out bucket. """ region = get_bucket_region(Bucket=bucket_name, **conn) if not region: return modify(dict(Error='Unauthorized'), format=output) conn['region'] = region grants, owner = get_grants(bucket_name, include_owner=True, **conn) result = { 'arn': "arn:aws:s3:::{name}".format(name=bucket_name), 'grants': grants, 'owner': owner, 'lifecycle_rules': get_lifecycle(bucket_name, **conn), 'logging': get_logging(bucket_name, **conn), 'policy': get_policy(bucket_name, **conn), 'region': region, 'tags': get_tags(bucket_name, **conn), 'versioning': get_versioning(bucket_name, **conn), 'website': get_website(bucket_name, **conn), 'cors': get_cors(bucket_name, **conn), 'notifications': get_notifications(bucket_name, **conn), 'acceleration': get_acceleration(bucket_name, **conn), 'replication': get_replication(bucket_name, **conn), '_version': 2 } if include_created: result["Created"] = get_bucket_created(bucket_name, **conn) return modify(result, format=output)
def get_bucket(bucket_name, include_created=None, flags=FLAGS.ALL ^ FLAGS.CREATED_DATE, **conn): """ Orchestrates all the calls required to fully build out an S3 bucket in the following format: { "Arn": ..., "Name": ..., "Region": ..., "Owner": ..., "Grants": ..., "GrantReferences": ..., "LifecycleRules": ..., "Logging": ..., "Policy": ..., "Tags": ..., "Versioning": ..., "Website": ..., "Cors": ..., "Notifications": ..., "Acceleration": ..., "Replication": ..., "CreationDate": ..., "AnalyticsConfigurations": ..., "MetricsConfigurations": ..., "InventoryConfigurations": ..., "_version": 9 } NOTE: "GrantReferences" is an ephemeral field that is not guaranteed to be consistent -- do not base logic off of it :param include_created: legacy param moved to FLAGS. :param bucket_name: str bucket name :param flags: By default, set to ALL fields except for FLAGS.CREATED_DATE as obtaining that information is a slow and expensive process. :param conn: dict containing enough information to make a connection to the desired account. Must at least have 'assume_role' key. :return: dict containing a fully built out bucket. """ if type(include_created) is bool: # coerce the legacy param "include_created" into the flags param. if include_created: flags = flags | FLAGS.CREATED_DATE else: flags = flags & ~FLAGS.CREATED_DATE region = get_bucket_region(Bucket=bucket_name, **conn) if not region: return dict(Error='Unauthorized') conn['region'] = region return registry.build_out(flags, bucket_name, **conn)