예제 #1
0
    def get(self, prefix=""):
        parser = init_parser().copy()
        parser.add_argument("bucket_name", type=str)
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        bucket_name = args["bucket_name"]
        if args["bucket_name"]:
            bucket_name, prefix = utils.get_bucket_key(args["bucket_name"])

        try:
            if args["bucket_name"]:
                buckets = bucket.get_objects(
                    get_resources(args["access_key"], secret_key), bucket_name,
                    prefix)
                objects = list_objects(buckets)
                if not objects:
                    return response(200, f"Bucket is Empty.")
                return response(200, data=objects)

            buckets = bucket.buckets(
                get_resources(args["access_key"], secret_key))
            all_bucket = []
            for index, buck in enumerate(buckets):
                all_bucket.append({
                    "name": buck.name,
                    "creation_date": f"{buck.creation_date:%Y-%m-%d %H:%M:%S}",
                    "ACL": buck.Acl().grants,
                })
            if not all_bucket:
                return response(200, f"Storage is Empty.")
            return response(200, data=all_bucket)
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
예제 #2
0
def buckets(resource):
    """Print all bucket with specified attribute."""
    try:
        all_buckets = bucket_lib.buckets(resource)
        for bucket in all_buckets:
            click.secho(f"{bucket.creation_date:%Y-%m-%d %H:%M:%S} {bucket.name}")
    except Exception as exc:
        click.secho(f"Bucket listing failed. \n{exc}", fg="yellow", bold=True, err=True)
예제 #3
0
 def test_buckets(self):
     assert bucket.buckets(self.fake_resource()) == [
         "bucket-one",
         "satu-b21f6bb7-39d5",
     ]