def __init__(self, bucket_name=None):

        # we can create the minio client ourselves or use
        # create_minio_client_from_settings convinience function while providing it with
        # extra args.
        #
        client = create_minio_client_from_settings(
            minio_kwargs={"region": "us-east-1"})

        # or use our own Django setting
        #
        if bucket_name is None:
            bucket_name = get_setting("SECRET_BUCKET_NAME")

        # Run the super constructor and make a choice to only use presigned urls with
        # this bucket so that we can keep files more private here than how media files
        # usually are public readable.
        #
        super(SecretStorage, self).__init__(
            client,
            bucket_name,
            auto_create_bucket=True,
            auto_create_policy=False,
            presign_urls=True,
        )
示例#2
0
    def __init__(self):
        client = create_minio_client_from_settings()
        bucket_name = get_setting("MINIO_STORAGE_COG_BUCKET_NAME")
        base_url = get_setting("MINIO_STORAGE_COG_URL", None)
        auto_create_bucket = get_setting(
            "MINIO_STORAGE_AUTO_CREATE_COG_BUCKET", False)
        auto_create_policy = get_setting(
            "MINIO_STORAGE_AUTO_CREATE_COG_POLICY", False)
        presign_urls = get_setting('MINIO_STORAGE_COG_USE_PRESIGNED', False)
        backup_format = get_setting("MINIO_STORAGE_COG_BACKUP_FORMAT", False)
        backup_bucket = get_setting("MINIO_STORAGE_COG_BACKUP_BUCKET", False)

        super(MinioCogStorage,
              self).__init__(client,
                             bucket_name,
                             auto_create_bucket=auto_create_bucket,
                             auto_create_policy=auto_create_policy,
                             base_url=base_url,
                             presign_urls=presign_urls,
                             backup_format=backup_format,
                             backup_bucket=backup_bucket)
示例#3
0
def serve_dump_file(filename: str, catalog: str = None) -> HttpResponse:
    try:
        dump_file = DumpFile.get_from_path(filename, catalog)
    except DumpFile.DoesNotExist:
        raise Http404

    if isinstance(dump_file,
                  DumpFile) and (dump_file.file_name,
                                 dump_file.file_type) in DumpFile.ZIP_FILES:
        raise Http404

    if dump_file.file is None:
        return HttpResponse(DUMP_ERROR, status=500)

    conn = create_minio_client_from_settings()

    # Devuelvo el archivo desde nginx, de estar configurado
    if getattr(settings, 'MINIO_SERVE_FILES_URL', None):
        headers = {
            'response-content-disposition':
            f'attachment; filename="{filename}"'
        }
        response = conn.presigned_get_object(
            settings.MINIO_STORAGE_MEDIA_BUCKET_NAME,
            dump_file.file.name,
            response_headers=headers)

        parsed = urlparse(response)
        response = redirect(
            f'{settings.MINIO_SERVE_FILES_URL}{parsed.path}?{parsed.query}')
        response['Content-Disposition'] = f"attachment; {filename}"
        return redirect(
            f'{settings.MINIO_SERVE_FILES_URL}{parsed.path}?{parsed.query}')

    response = conn.presigned_get_object(
        settings.MINIO_STORAGE_MEDIA_BUCKET_NAME, dump_file.file.name)

    return HttpResponseRedirect(response)
示例#4
0
 def __init__(self, *args, **kwargs):
     # A minio.api.Minio instance cannot be serialized by Django. Since all constructor
     # arguments are serialized by the @deconstructible decorator, passing a Minio client as a
     # constructor argument causes makemigrations to fail.
     kwargs['minio_client'] = create_minio_client_from_settings()
     super().__init__(*args, **kwargs)
示例#5
0
 def delete(self, using=None, keep_parents=False):
     if self.file:
         minio = create_minio_client_from_settings()
         minio.remove_object(settings.MINIO_STORAGE_MEDIA_BUCKET_NAME, self.file.name)
     super(DumpFile, self).delete(using, keep_parents)