Ejemplo n.º 1
0
    def post(self, bucket_name):
        parser = init_parser().copy()
        parser.add_argument("object_name", type=str)
        parser.add_argument("acl", type=str)
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        file = request.files["files"]
        filename = secure_filename(file.filename)
        object_name = args["object_name"] if args["object_name"] else filename

        try:
            object_name = utils.sanitize("upload", object_name)
            result = bucket.upload_bin_object(
                resource=get_resources(args["access_key"], secret_key),
                bucket_name=bucket_name,
                fileobj=file,
                object_name=object_name,
                content_type=file.content_type,
            )
            if args["acl"]:
                bucket.set_acl(
                    resource=get_resources(args["access_key"], secret_key),
                    bucket_name=bucket_name,
                    object_name=object_name,
                    acl_type="object",
                    acl=args["acl"],
                )
            return response(201,
                            f"Object {object_name} uploaded successfully.",
                            result)
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
Ejemplo n.º 2
0
def set_acl(**kwargs):
    try:
        bucket_lib.set_acl(**kwargs)
        click.secho(f"ACL changed successfully", fg="green")
    except Exception as exc:
        click.secho(f"ACL change failed. \n{exc}",
                    fg="yellow",
                    bold=True,
                    err=True)
Ejemplo n.º 3
0
    def post(self):
        parser = init_parser().copy()
        parser.add_argument("bucket_name", type=str, required=True)
        parser.add_argument("object_name", type=str)
        parser.add_argument("acl", type=str, default="")
        parser.add_argument("grant_fullcontrol", type=str)
        parser.add_argument("grant_read", type=str)
        parser.add_argument("grant_readACP", type=str)
        parser.add_argument("grant_write", type=str)
        parser.add_argument("grant_writeACP", type=str)
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        try:
            name = args["object_name"] if args["object_name"] else args[
                "bucket_name"]
            attr = {arg: val for arg, val in args.items() if "key" not in arg}
            attr["resource"] = get_resources(args["access_key"], secret_key)
            attr["acl_type"] = "object" if args["object_name"] else "bucket"

            result = bucket.set_acl(**attr)
            return response(200, f"Added access to {attr['acl_type']} {name}.",
                            result)
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
Ejemplo n.º 4
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument("access_key", type=str, required=True)
        parser.add_argument("secret_key", type=str, required=True)
        parser.add_argument("bucket_name", type=str, required=True)
        parser.add_argument("object_name", type=str)
        parser.add_argument("acl", type=str, default="private")
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        acl_type = "object" if args["object_name"] else "bucket"
        name = args["object_name"] if args["object_name"] else args["bucket_name"]

        try:
            result = bucket.set_acl(
                resource=get_resources(args["access_key"], secret_key),
                bucket_name=args["bucket_name"],
                object_name=args["object_name"],
                acl_type=acl_type,
                acl=args["acl"],
            )
            return response(
                200, f"Added {args['acl']} access to {acl_type} {name}.", result
            )
        except Exception as e:
            current_app.logger.error(f"{e}")
            return response(500, f"{e}")
Ejemplo n.º 5
0
    def post(self, bucket_name):
        parser = reqparse.RequestParser()
        parser.add_argument("access_key", type=str, required=True)
        parser.add_argument("secret_key", type=str, required=True)
        parser.add_argument("object_name", type=str)
        parser.add_argument("acl", type=str)
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        file = request.files["files"]
        filename = secure_filename(file.filename)
        object_name = args["object_name"] if args["object_name"] else filename

        try:
            regex = r"[\"\{}^%`\]\[~<>|#]|[^\x00-\x7F]"
            object_name = re.sub(regex, "", object_name)

            result = bucket.upload_bin_object(
                resource=get_resources(args["access_key"], secret_key),
                bucket_name=bucket_name,
                fileobj=file,
                object_name=object_name,
                content_type=file.content_type,
            )
            if args["acl"]:
                bucket.set_acl(
                    resource=get_resources(args["access_key"], secret_key),
                    bucket_name=bucket_name,
                    object_name=object_name,
                    acl_type="object",
                    acl=args["acl"],
                )
            return response(201, f"Object {object_name} uploaded successfully.", result)
        except Exception as e:
            current_app.logger.error(f"{e}")
            return response(500, f"{e}")