Пример #1
0
 public void Init(string Endpoint, string MINIO_ACCESS_KEY, string MINIO_SECRET_KEY, bool WithSSL, int presignedGetObjectAsyncExpiresInt)
 {
     this.presignedGetObjectAsyncExpiresInt = presignedGetObjectAsyncExpiresInt;
     minioClient = new MinioClient()
                   .WithEndpoint(Endpoint)
                   .WithCredentials(MINIO_ACCESS_KEY, MINIO_SECRET_KEY);
     if (WithSSL)
     {
         minioClient.WithSSL();
     }
     minioClient.Build();
 }
Пример #2
0
        public MinioOSSService(IMemoryCache cache, OSSOptions options) : base(cache, options)
        {
            MinioClient client = new MinioClient()
                                 .WithEndpoint(options.Endpoint)
                                 .WithRegion(options.Region)
                                 .WithSessionToken(options.SessionToken)
                                 .WithCredentials(options.AccessKey, options.SecretKey);

            if (options.IsEnableHttps)
            {
                client = client.WithSSL();
            }
            this._client = client.Build();
        }
Пример #3
0
    protected virtual MinioClient GetMinioClient(BlobProviderArgs args)
    {
        var configuration = args.Configuration.GetMinioConfiguration();

        var client = new MinioClient()
                     .WithEndpoint(configuration.EndPoint)
                     .WithCredentials(configuration.AccessKey, configuration.SecretKey);

        if (configuration.WithSSL)
        {
            client.WithSSL();
        }

        return(client.Build());
    }
Пример #4
0
        public MinioFileStorage(MinioFileStorageOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var    connectionString = new MinioFileStorageConnectionStringBuilder(options.ConnectionString);
            string endpoint;
            bool   secure;

            if (connectionString.EndPoint.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
            {
                endpoint = connectionString.EndPoint.Substring(8);
                secure   = true;
            }
            else
            {
                secure   = false;
                endpoint = connectionString.EndPoint.StartsWith("http://", StringComparison.OrdinalIgnoreCase)
                    ? connectionString.EndPoint.Substring(7)
                    : connectionString.EndPoint;
            }

            _client = new MinioClient()
                      .WithEndpoint(endpoint)
                      .WithCredentials(connectionString.AccessKey, connectionString.SecretKey);

            if (!String.IsNullOrEmpty(connectionString.Region))
            {
                _client.WithRegion(connectionString.Region ?? String.Empty);
            }

            _client.Build();

            if (secure)
            {
                _client.WithSSL();
            }

            _bucket = connectionString.Bucket;
            _shouldAutoCreateBucket = options.AutoCreateBucket;
            _serializer             = options.Serializer ?? DefaultSerializer.Instance;
            _logger = options.LoggerFactory?.CreateLogger(typeof(MinioFileStorage)) ?? NullLogger.Instance;
        }
Пример #5
0
        public IOSSService Create(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                name = DefaultOptionName.Name;
            }
            var options = optionsMonitor.Get(name);

            if (options == null)
            {
                throw new ArgumentException($"Cannot get option by name '{name}'.");
            }
            if (string.IsNullOrEmpty(options.Endpoint))
            {
                throw new ArgumentNullException(nameof(options.Endpoint));
            }
            if (string.IsNullOrEmpty(options.SecretKey))
            {
                throw new ArgumentNullException(nameof(options.SecretKey));
            }
            if (string.IsNullOrEmpty(options.AccessKey))
            {
                throw new ArgumentNullException(nameof(options.AccessKey));
            }

            switch (options.Provider)
            {
            case OSSProvider.Aliyun:
            {
                OssClient client = new OssClient(options.Endpoint, options.AccessKey, options.SecretKey);
                return(new AliyunOSSService(client, _cacheProvider, options));
            }

            case OSSProvider.Minio:
            {
                MinioClient client = new MinioClient()
                                     .WithEndpoint(options.Endpoint)
                                     .WithRegion(options.Region)
                                     .WithSessionToken(options.SessionToken)
                                     .WithCredentials(options.AccessKey, options.SecretKey);

                if (options.IsEnableHttps)
                {
                    client = client.WithSSL();
                }
                return(new MinioOSSService(client.Build(), _cacheProvider, options));
            }

            case OSSProvider.QCloud:
            {
                CosXmlConfig config = new CosXmlConfig.Builder()
                                      .IsHttps(options.IsEnableHttps)
                                      .SetRegion(options.Region)
                                      .SetDebugLog(false)
                                      .Build();
                QCloudCredentialProvider cosCredentialProvider = new DefaultQCloudCredentialProvider(options.AccessKey, options.SecretKey, 600);
                CosXml cosXml = new CosXmlServer(config, cosCredentialProvider);
                return(new QCloudOSSService(cosXml, _cacheProvider, options));
            }

            default:
                throw new Exception("Unknow provider type");
            }
        }