コード例 #1
0
ファイル: SampleAppService.cs プロジェクト: cocosip/AutoS3
        protected IAmazonS3 GetClient()
        {
            return(_s3ClientFactory.GetOrAdd("default", () =>
            {
                var configuration = new S3ClientConfiguration()
                {
                    Vendor = _options.S3Vendor,
                    AccessKeyId = _options.AccessKeyId,
                    SecretAccessKey = _options.SecretAccessKey,
                    MaxClient = 10
                };

                if (_options.S3Vendor == S3VendorType.Amazon)
                {
                    configuration.Config = new AmazonS3Config()
                    {
                        ServiceURL = _options.ServerUrl,
                        ForcePathStyle = _options.ForcePathStyle,
                        SignatureVersion = _options.SignatureVersion
                    };
                }
                else
                {
                    configuration.Config = new AmazonKS3Config()
                    {
                        ServiceURL = _options.ServerUrl,
                        ForcePathStyle = _options.ForcePathStyle,
                        SignatureVersion = _options.SignatureVersion
                    };
                }
                return configuration;
            }));
        }
コード例 #2
0
        public void Get_BuildClient_Times_Test()
        {
            var s3ClientConfiguration = new S3ClientConfiguration()
            {
                Vendor          = S3VendorType.Amazon,
                AccessKeyId     = "123456",
                SecretAccessKey = "12345",
                MaxClient       = 2,
                Config          = new AmazonS3Config()
                {
                    ServiceURL       = "http://192.168.0.100",
                    ForcePathStyle   = true,
                    SignatureVersion = "2.0"
                }
            };
            var mockLogger    = new Mock <ILogger <DefaultS3ClientPool> >();
            var mockIAmazonS3 = new Mock <IAmazonS3>();

            var mockS3ClientBuilder = new Mock <IS3ClientBuilder>();

            mockS3ClientBuilder.Setup(x => x.BuildClient(It.IsAny <S3ClientConfiguration>())).Returns(mockIAmazonS3.Object);

            IS3ClientPool s3ClientPool = new DefaultS3ClientPool(mockLogger.Object, s3ClientConfiguration, mockS3ClientBuilder.Object);

            var client1 = s3ClientPool.Get();
            var client2 = s3ClientPool.Get();
            var client3 = s3ClientPool.Get();

            mockS3ClientBuilder.Verify(x => x.BuildClient(It.IsAny <S3ClientConfiguration>()), Times.Between(1, 3, Range.Exclusive));
        }
コード例 #3
0
ファイル: KS3ClientBuilder.cs プロジェクト: cocosip/AutoS3
        /// <summary>
        /// Build a amazon s3 client <see cref="Amazon.S3.IAmazonS3"/>
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public IAmazonS3 BuildClient(S3ClientConfiguration configuration)
        {
            _logger.LogDebug("Create client with configuration:{0}", configuration.ToString());

            if (configuration.Config is AmazonKS3Config kS3Config)
            {
                IAmazonS3 client = new AmazonKS3Client(
                    configuration.AccessKeyId,
                    configuration.SecretAccessKey,
                    kS3Config);
                return(client);
            }

            throw new ArgumentException($"The configuration {configuration}, create ks3 client fail, config was not a type of 'AmazonKS3Config'! ");
        }
コード例 #4
0
        protected virtual IAmazonS3 GetS3Client(FileProviderArgs args)
        {
            var configuration = args.Configuration.GetS3Configuration();

            var containerName = GetContainerName(args);

            var amazonS3 = S3ClientFactory.GetOrAdd(containerName, () =>
            {
                var s3ClientConfiguration = new S3ClientConfiguration()
                {
                    Vendor          = (S3VendorType)configuration.VendorType,
                    AccessKeyId     = configuration.AccessKeyId,
                    SecretAccessKey = configuration.SecretAccessKey,
                    MaxClient       = configuration.MaxClient,
                };

                if (configuration.VendorType == (int)S3VendorType.KS3)
                {
                    s3ClientConfiguration.Config = new AmazonS3Config()
                    {
                        ServiceURL       = configuration.ServerUrl,
                        ForcePathStyle   = configuration.ForcePathStyle,
                        SignatureVersion = configuration.SignatureVersion
                    };
                }
                else
                {
                    s3ClientConfiguration.Config = new AmazonKS3Config()
                    {
                        ServiceURL       = configuration.ServerUrl,
                        ForcePathStyle   = configuration.ForcePathStyle,
                        SignatureVersion = configuration.SignatureVersion
                    };
                }

                return(s3ClientConfiguration);
            });

            return(amazonS3);
        }