You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.4 KiB
58 lines
1.4 KiB
import click
|
|
import logging
|
|
import datetime
|
|
from pprint import pprint
|
|
|
|
from . import __version__
|
|
from .mass_s3 import MassS3
|
|
|
|
@click.group()
|
|
def cli():
|
|
"""
|
|
Tool for running an operation on a bunch of objects in S3 a little quicker
|
|
"""
|
|
pass
|
|
|
|
@cli.command()
|
|
@click.argument('bucket')
|
|
@click.argument('path')
|
|
@click.argument('new_acl')
|
|
@click.option('-m', '--modified-since', 'modified_since', default=None, required=False)
|
|
@click.option('-o', '--owner', 'owner', default=None, required=False)
|
|
def put_object_acl(bucket, path, new_acl, modified_since, owner):
|
|
"""Find all files in BUCKET prefixed with PATH and apply NEW_ACL.
|
|
"""
|
|
logger = logging.getLogger("mass_s3")
|
|
logger.info("Starting")
|
|
|
|
if modified_since is not None:
|
|
modified_since = modified_since.split('-')
|
|
if len(modified_since) != 3:
|
|
raise Exception('Could not parse modified_since')
|
|
modified_since = datetime.datetime(int(modified_since[0]), int(modified_since[1]), int(modified_since[2]), tzinfo=datetime.timezone.utc)
|
|
|
|
if path[0:1] == "/":
|
|
path = path[1:]
|
|
|
|
filters = {}
|
|
if modified_since is not None:
|
|
filters['modified_since'] = modified_since
|
|
if owner is not None:
|
|
filters['owner'] = owner
|
|
|
|
|
|
ms3 = MassS3()
|
|
ms3.put_object_acl(bucket, path, new_acl, filters)
|
|
|
|
logger.info("Done")
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
def version():
|
|
"""Display the program version
|
|
"""
|
|
print(__version__)
|
|
|
|
|