コード例 #1
0
ファイル: minio.py プロジェクト: cofin/django-minio-storage
 def policy_set(self, storage, bucket_name, policy: Policy):
     try:
         policy = Policy(policy)
         storage.client.set_bucket_policy(bucket_name,
                                          policy.bucket(bucket_name))
     except minio.error.NoSuchBucket as e:
         raise CommandError(e.message)
コード例 #2
0
    def __init__(self):
        client = create_minio_client_from_settings()
        base_url = get_setting("MINIO_STORAGE_STATIC_URL", None)
        bucket_name = get_setting("MINIO_STORAGE_STATIC_BUCKET_NAME")
        auto_create_bucket = get_setting(
            "MINIO_STORAGE_AUTO_CREATE_STATIC_BUCKET", False)
        auto_create_policy = get_setting(
            "MINIO_STORAGE_AUTO_CREATE_STATIC_POLICY", "GET_ONLY")

        policy_type = Policy.get
        if isinstance(auto_create_policy, str):
            policy_type = Policy(auto_create_policy)
            auto_create_policy = True

        presign_urls = get_setting("MINIO_STORAGE_STATIC_USE_PRESIGNED", False)

        assume_bucket_exists = get_setting(
            "MINIO_STORAGE_ASSUME_STATIC_BUCKET_EXISTS", False)

        object_metadata = get_setting("MINIO_STORAGE_STATIC_OBJECT_METADATA",
                                      None)

        super().__init__(
            client,
            bucket_name,
            auto_create_bucket=auto_create_bucket,
            auto_create_policy=auto_create_policy,
            policy_type=policy_type,
            base_url=base_url,
            presign_urls=presign_urls,
            assume_bucket_exists=assume_bucket_exists,
            object_metadata=object_metadata,
        )
コード例 #3
0
ファイル: minio.py プロジェクト: cofin/django-minio-storage
    def handle(self, *args, **options):
        storage = self.storage(options)
        bucket_name = options["bucket"] or storage.bucket_name
        command = options["command"] or ""
        if command == self.CHECK:
            return self.bucket_exists(storage, bucket_name)
        if command == self.CREATE:
            return self.bucket_create(storage, bucket_name)
        elif command == self.DELETE:
            return self.bucket_delete(storage, bucket_name)
        elif command == self.LIST:
            if options["buckets"]:
                return self.list_buckets(storage)

            list_dirs = True
            list_files = True
            summary = True
            if options["dirs"] or options["files"]:
                list_dirs = options["dirs"]
                list_files = options["files"]
                summary = False

            return self.bucket_list(
                storage,
                bucket_name,
                prefix=options["prefix"],
                list_dirs=list_dirs,
                list_files=list_files,
                recursive=options["recursive"],
                format=options["format"],
                summary=summary,
            )
        elif command == self.POLICY:
            if options["set"] is not None:
                return self.policy_set(storage,
                                       bucket_name,
                                       policy=Policy(options["set"]))
            return self.policy_get(storage, bucket_name)
        self.print_help("minio", "")
        if command != "":
            raise CommandError(f"don't know how to handle command: {command}")
        raise CommandError("command name required")
コード例 #4
0
    def __init__(self):
        client = create_minio_client_from_settings()
        bucket_name = get_setting("MINIO_STORAGE_MEDIA_BUCKET_NAME")
        base_url = get_setting("MINIO_STORAGE_MEDIA_URL", None)
        external_base_url = get_setting("MINIO_STORAGE_MEDIA_EXTERNAL_URL", None)
        auto_create_bucket = get_setting(
            "MINIO_STORAGE_AUTO_CREATE_MEDIA_BUCKET", False
        )
        auto_create_policy = get_setting(
            "MINIO_STORAGE_AUTO_CREATE_MEDIA_POLICY", "GET_ONLY"
        )

        policy_type = Policy.get
        if isinstance(auto_create_policy, str):
            policy_type = Policy(auto_create_policy)
            auto_create_policy = True

        presign_urls = get_setting("MINIO_STORAGE_MEDIA_USE_PRESIGNED", False)
        backup_format = get_setting("MINIO_STORAGE_MEDIA_BACKUP_FORMAT", False)
        backup_bucket = get_setting("MINIO_STORAGE_MEDIA_BACKUP_BUCKET", False)

        assume_bucket_exists = get_setting(
            "MINIO_STORAGE_ASSUME_MEDIA_BUCKET_EXISTS", False
        )

        object_metadata = get_setting("MINIO_STORAGE_MEDIA_OBJECT_METADATA", None)
        # print("SETTING", object_metadata)

        super().__init__(
            client,
            bucket_name,
            auto_create_bucket=auto_create_bucket,
            auto_create_policy=auto_create_policy,
            policy_type=policy_type,
            base_url=base_url,
            external_base_url=external_base_url,
            presign_urls=presign_urls,
            backup_format=backup_format,
            backup_bucket=backup_bucket,
            assume_bucket_exists=assume_bucket_exists,
            object_metadata=object_metadata,
        )