示例#1
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}")
示例#2
0
    def get(self, bucket_name):
        parser = init_parser().copy()
        parser.add_argument("object_name", type=str, default="")
        parser.add_argument("upload_id", type=str)
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        try:
            if args["upload_id"]:
                parts = bucket.list_part(
                    get_resources(args["access_key"], secret_key),
                    bucket_name,
                    args["object_name"],
                    args["upload_id"],
                )
                if parts is None:
                    return response(
                        404, f"Part not found, please abort this object.")
                for part in parts:
                    part[
                        "LastModified"] = f'{part["LastModified"]:%Y-%m-%d %H:%M:%S}'
                return response(201, data=parts)

            mpu = bucket.list_multipart_upload(
                get_resources(args["access_key"], secret_key),
                bucket_name,
                args["object_name"],
            )
            list_objects(mpu, "Uploads", "Initiated")
            return response(200, data=mpu)
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
示例#3
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}")
示例#4
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}")
示例#5
0
    def get(self):
        parser = init_parser().copy()
        parser.add_argument("bucket_name", type=str)
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        try:
            if args["bucket_name"]:
                total_size, total_objects = bucket.bucket_usage(
                    get_resources(args["access_key"], secret_key),
                    args["bucket_name"])
                bucket_usage = {
                    "name": args["bucket_name"],
                    "size": total_size,
                    "objects": total_objects,
                }
                return response(200, data=bucket_usage)

            disk_usage = {"bucket": [], "total_usage": 0}
            disk_usages = bucket.disk_usage(
                get_resources(args["access_key"], secret_key))
            for usage in disk_usages:
                bucket_name = usage[0]
                total_size, total_objects = usage[1]
                disk_usage["total_usage"] += total_size
                disk_usage["bucket"].append({
                    "name": bucket_name,
                    "size": total_size,
                    "objects": total_objects
                })
            disk_usage["total_usage"] = f"{disk_usage['total_usage']}"
            return response(200, data=disk_usage)
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
示例#6
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}")
示例#7
0
    def delete(self, bucket_name):
        parser = init_parser().copy()
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        try:
            result = bucket.remove_bucket(
                get_resources(args["access_key"], secret_key), bucket_name)
            return response(200, f"Bucket {bucket_name} deleted successfully.",
                            result)
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
示例#8
0
    def get(self):
        try:
            msg = []
            policies = gmt.get_policies()

            for zone in policies:
                policy_id, description, _ = policies[zone].values()
                if not description:
                    description = "No description"
                msg.append({"Name": zone, "Id": policy_id, "Description": description})
            return response(200, data=msg)
        except Exception as e:
            current_app.logger.error(f"{e}")
            return response(500, f"{e}")
示例#9
0
    def post(self):
        options = {
            "userId": "",
            "groupId": "",
            "userType": "User",
            "fullName": "",
            "emailAddr": "",
            "address1": "",
            "city": "",
            "state": "",
            "zip": "",
            "country": "",
            "phone": "",
            "website": "",
            "active": True,
            "ldapEnabled": False,
        }

        parser = reqparse.RequestParser()
        for index, option in options.items():
            if index in ["userId", "groupId", "fullName"]:
                parser.add_argument(index, type=str, required=True)
            elif index in ["active", "ldapEnabled"]:
                parser.add_argument(index, type=inputs.boolean)
            else:
                parser.add_argument(index, type=str)
        parser.add_argument("quotaLimit", type=int)
        parser.add_argument("debug", type=inputs.boolean, default=False)
        args = parser.parse_args()

        try:
            for index, option in options.items():
                if args[index] not in (option, None):
                    options[index] = args[index]
            options = utils.user_sanitize(options)
            status = user.create(get_client(), options)
            if args["quotaLimit"]:
                status = qos.set(get_client(), args["userId"], args["groupId"],
                                 args["quotaLimit"])
            if "reason" in status:
                current_app.logger.error(status["reason"])
                return response(status["status_code"],
                                message=status["reason"])
            else:
                return response(
                    201, f"User {options['userId']} created successfully.")
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
示例#10
0
    def delete(self, bucket_name):
        parser = reqparse.RequestParser()
        parser.add_argument("access_key", type=str, required=True)
        parser.add_argument("secret_key", type=str, required=True)
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        try:
            result = bucket.remove_bucket(
                get_resources(args["access_key"], secret_key), bucket_name
            )
            return response(200, f"Bucket {bucket_name} deleted successfully.", result)
        except Exception as e:
            current_app.logger.error(f"{e}")
            return response(500, f"{e}")
示例#11
0
    def get(self):
        args = init_parser().parse_args()

        try:
            status = admin_usage.usage(get_client(), args["userId"],
                                       args["groupId"])
            if "reason" in status:
                current_app.logger.error(status["reason"])
                return response(status["status_code"],
                                message=status["reason"])

            return response(200, data=status[0])
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
示例#12
0
    def get(self):
        args = init_parser().parse_args()

        try:
            cred_list = credential.list(get_client(), args["userId"],
                                        args["groupId"])
            if "reason" in cred_list:
                current_app.logger.error(cred_list["reason"])
                return response(cred_list["status_code"],
                                message=cred_list["reason"])

            return response(200, data=cred_list)
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
示例#13
0
    def get(self, bucket_name):
        parser = init_parser().copy()
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        try:
            bucket_info = bucket.bucket_info(
                get_resources(args["access_key"], secret_key),
                bucket_name,
                get_plain_auth(args["access_key"], secret_key),
            )
            return response(200, data=bucket_info)
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
示例#14
0
    def delete(self):
        args = init_parser().parse_args()

        try:
            status = user.remove(get_client(), args["userId"], args["groupId"])
            if "reason" in status:
                current_app.logger.error(status["reason"])
                return response(status["status_code"],
                                message=status["reason"])

            return response(200,
                            f"User {args['userId']} deleted successfully.")
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
示例#15
0
    def delete(self):
        args = init_parser().parse_args()

        try:
            status = qos.rm(get_client(), args["userId"], args["groupId"])
            if "reason" in status:
                current_app.logger.error(status["reason"])
                return response(status["status_code"],
                                message=status["reason"])

            return response(
                200, f"User {args['userId']} quota changed to unlimited.",
                status)
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
示例#16
0
    def get(self, bucket_name):
        parser = init_parser().copy()
        parser.add_argument("object_name", type=str, default="")
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        with tempfile.TemporaryDirectory() as tempdir:
            try:
                os.chdir(tempdir)
                resources = get_resources(args["access_key"], secret_key)

                if args["object_name"] == "":
                    name = archive(resources, f"{bucket_name}/", bucket_name,
                                   "")
                elif args["object_name"][-1] == "/":
                    name = archive(resources, args["object_name"], bucket_name,
                                   args["object_name"])
                else:
                    bucket.download_object(resources, bucket_name,
                                           args["object_name"])
                    name = args["object_name"]
                file = send_from_directory(tempdir, name, as_attachment=True)
                return file
            except Exception as e:
                current_app.logger.error(f"{e}", exc_info=args["debug"])
                return response(500, f"{e}")
示例#17
0
    def get(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, default="")
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        with tempfile.TemporaryDirectory() as tempdir:
            try:
                os.chdir(tempdir)

                resources = get_resources(args["access_key"], secret_key)
                file_download(resources, bucket_name, args["object_name"])

                if args["object_name"] == "":
                    name = archive(bucket_name + "/")
                elif args["object_name"][-1] == "/":
                    name = archive(args["object_name"])
                else:
                    name = args["object_name"]
                file = send_from_directory(tempdir, name, as_attachment=True)
                return file
            except Exception as e:
                current_app.logger.error(f"{e}")
                return response(500, f"{e}")
示例#18
0
    def get(self, bucket_name, object_name):
        parser = init_parser().copy()
        parser.add_argument("expire", type=int)
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        try:
            url = bucket.generate_url(
                get_resources(args["access_key"], secret_key),
                bucket_name,
                object_name,
                args["expire"],
            )
            return response(200, data=url)
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
示例#19
0
    def get(self, bucket_name):
        parser = reqparse.RequestParser()
        parser.add_argument("access_key", type=str, required=True)
        parser.add_argument("secret_key", type=str, required=True)
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        try:
            bucket_info = bucket.bucket_info(
                get_resources(args["access_key"], secret_key),
                bucket_name,
                get_plain_auth(args["access_key"], secret_key),
            )
            return response(200, data=bucket_info)
        except Exception as e:
            current_app.logger.error(f"{e}")
            return response(500, f"{e}")
示例#20
0
    def delete(self):
        parser = reqparse.RequestParser()
        parser.add_argument("access_key", type=str, required=True)
        args = parser.parse_args()

        try:
            status = credential.rm(get_client(), args["access_key"])
            if "reason" in status:
                current_app.logger.error(status["reason"])
                return response(status["status_code"],
                                message=status["reason"])

            return response(
                200, f"Access key {args['access_key']} deleted successfully.")
        except Exception as e:
            current_app.logger.error(f"{e}")
            return response(500, f"{e}")
示例#21
0
    def get(self):
        args = init_parser().parse_args()

        try:
            infos = qos.info(get_client(), args["userId"], args["groupId"])
            infos["Storage Limit"] = (
                infos["qosLimitList"][0]["value"] * 1024
                if infos["qosLimitList"][0]["value"] != -1 else "unlimited")

            if "reason" in infos:
                current_app.logger.error(infos["reason"])
                return response(infos["status_code"], message=infos["reason"])

            return response(200, data=infos)
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
示例#22
0
    def post(self, bucket_name):
        parser = init_parser().copy()
        parser.add_argument("directory", type=str, required=True)
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        try:
            result = bucket.mkdir(
                get_resources(args["access_key"], secret_key),
                bucket_name,
                args["directory"],
            )
            return response(
                201, f"Directory {args['directory']} added successfully.",
                result)
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
示例#23
0
    def delete(self, bucket_name):
        parser = init_parser().copy()
        parser.add_argument("object_name", type=str, required=True)
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        try:
            result = bucket.remove_object(
                get_resources(args["access_key"], secret_key),
                bucket_name,
                args["object_name"],
            )
            return response(
                200, f"Object {args['object_name']} deleted successfully.",
                result)
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
示例#24
0
    def get(self, bucket_name):
        parser = init_parser().copy()
        parser.add_argument("object_name", type=str, required=True)
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        try:
            object_info = bucket.object_info(
                get_resources(args["access_key"], secret_key),
                bucket_name,
                args["object_name"],
            )
            for key, value in object_info.items():
                object_info[key] = f"{value}"
            return response(200, data=object_info)
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
示例#25
0
    def delete(self):
        parser = reqparse.RequestParser()
        parser.add_argument("userId", type=str, required=True)
        parser.add_argument("groupId", type=str, required=True)
        args = parser.parse_args()

        try:
            status = user.remove(get_client(), args["userId"], args["groupId"])
            if "reason" in status:
                current_app.logger.error(status["reason"])
                return response(status["status_code"],
                                message=status["reason"])

            return response(200,
                            f"User {args['userId']} deleted successfully.")
        except Exception as e:
            current_app.logger.error(f"{e}")
            return response(500, f"{e}")
示例#26
0
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument("userId", type=str, required=True)
        parser.add_argument("groupId", type=str, required=True)
        args = parser.parse_args()

        try:
            status = admin_usage.usage(get_client(), args["userId"],
                                       args["groupId"])
            if "reason" in status:
                current_app.logger.error(status["reason"])
                return response(status["status_code"],
                                message=status["reason"])

            return response(200, data=status[0])
        except Exception as e:
            current_app.logger.error(f"{e}")
            return response(500, f"{e}")
示例#27
0
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument("userId", type=str, required=True)
        parser.add_argument("groupId", type=str, required=True)
        args = parser.parse_args()

        try:
            cred_list = credential.list(get_client(), args["userId"],
                                        args["groupId"])
            if "reason" in cred_list:
                current_app.logger.error(cred_list["reason"])
                return response(cred_list["status_code"],
                                message=cred_list["reason"])

            return response(200, data=cred_list)
        except Exception as e:
            current_app.logger.error(f"{e}")
            return response(500, f"{e}")
示例#28
0
    def post(self):
        parser = init_parser().copy()
        parser.add_argument("limit", type=int, required=True)
        args = parser.parse_args()

        try:
            status = qos.set(get_client(), args["userId"], args["groupId"],
                             args["limit"])
            if "reason" in status:
                current_app.logger.error(status["reason"])
                return response(status["status_code"],
                                message=status["reason"])

            return response(
                201, f"User {args['userId']} quota changed successfully.",
                status)
        except Exception as e:
            current_app.logger.error(f"{e}", exc_info=args["debug"])
            return response(500, f"{e}")
示例#29
0
    def get(self, bucket_name, object_name):
        parser = reqparse.RequestParser()
        parser.add_argument("expire", type=int)
        parser.add_argument("access_key", type=str, required=True)
        parser.add_argument("secret_key", type=str, required=True)
        args = parser.parse_args()
        secret_key = args["secret_key"].replace(" ", "+")

        try:
            url = bucket.generate_url(
                get_resources(args["access_key"], secret_key),
                bucket_name,
                object_name,
                args["expire"],
            )
            return response(200, data=url)
        except Exception as e:
            current_app.logger.error(f"{e}")
            return response(500, f"{e}")
示例#30
0
    def put(self):
        parser = reqparse.RequestParser()
        parser.add_argument("access_key", type=str, required=True)
        parser.add_argument("status", type=str, required=True, default="true")
        args = parser.parse_args()

        try:
            stats = "activated" if args["status"].lower(
            ) == "true" else "deactivated"
            status = credential.status(get_client(), args["access_key"],
                                       args["status"])
            if "reason" in status:
                current_app.logger.error(status["reason"])
                return response(status["status_code"],
                                message=status["reason"])

            return response(200, f"Credential status has been {stats}.")
        except Exception as e:
            current_app.logger.error(f"{e}")
            return response(500, f"{e}")