1- using Amazon ;
1+ using Amazon ;
22using Amazon . Runtime ;
33using Amazon . S3 ;
44using Microsoft . Extensions . Configuration ;
@@ -8,49 +8,40 @@ namespace Storage.Benchmark.Utils;
88
99internal static class BenchmarkHelper
1010{
11- public static readonly byte [ ] StreamBuffer = new byte [ 2048 ] ;
12-
13- // ReSharper disable once InconsistentNaming
14- public static AmazonS3Client CreateAWSClient ( S3Settings settings )
11+ public static readonly byte [ ] StreamBuffer = new byte [ 2048 ] ;
12+
13+ // ReSharper disable once InconsistentNaming
14+ public static AmazonS3Client CreateAWSClient ( S3BucketSettings settings )
1515 {
16- var scheme = settings . UseHttps ? Uri . UriSchemeHttps : Uri . UriSchemeHttp ;
17- var port = settings . Port . HasValue ? $ ":{ settings . Port } " : string . Empty ;
18-
1916 return new AmazonS3Client (
2017 new BasicAWSCredentials ( settings . AccessKey , settings . SecretKey ) ,
2118 new AmazonS3Config
2219 {
2320 RegionEndpoint = RegionEndpoint . USEast1 ,
24- ServiceURL = $ " { scheme } :// { settings . EndPoint } { port } " ,
25- ForcePathStyle = true , // MUST be true to work correctly with MinIO server
21+ ServiceURL = settings . Endpoint ,
22+ ForcePathStyle = true , // MUST be true to work correctly with MinIO server
2623 } ) ;
2724 }
2825
29- public static IMinioClient CreateMinioClient ( S3Settings settings )
26+ public static IMinioClient CreateMinioClient ( S3BucketSettings settings )
3027 {
31- var builder = new MinioClient ( ) ;
32- var port = settings . Port ;
33- if ( port . HasValue )
34- {
35- builder . WithEndpoint ( settings . EndPoint , port . Value ) ;
36- }
37- else
38- {
39- builder . WithEndpoint ( settings . EndPoint ) ;
40- }
28+ Uri endpoint = new ( settings . Endpoint ) ;
4129
30+ var builder = new MinioClient ( ) ;
31+
4232 return builder
33+ . WithEndpoint ( endpoint )
4334 . WithCredentials ( settings . AccessKey , settings . SecretKey )
44- . WithSSL ( settings . UseHttps )
35+
4536 . Build ( ) ;
4637 }
4738
48- public static S3Client CreateStoragesClient ( S3Settings settings )
39+ public static S3BucketClient CreateStoragesClient ( S3BucketSettings settings )
4940 {
50- return new S3Client ( settings ) ;
41+ return new S3BucketClient ( new HttpClient ( ) , settings ) ;
5142 }
5243
53- public static void EnsureBucketExists ( S3Client client , CancellationToken cancellation )
44+ public static void EnsureBucketExists ( S3BucketClient client , CancellationToken cancellation )
5445 {
5546 if ( client . IsBucketExists ( cancellation ) . GetAwaiter ( ) . GetResult ( ) )
5647 {
@@ -62,7 +53,7 @@ public static void EnsureBucketExists(S3Client client, CancellationToken cancell
6253
6354 public static void EnsureFileExists (
6455 IConfiguration config ,
65- S3Client client ,
56+ S3BucketClient client ,
6657 string fileName ,
6758 CancellationToken cancellation )
6859 {
@@ -76,7 +67,7 @@ public static void EnsureFileExists(
7667
7768 if ( ! result )
7869 {
79- throw new Exception ( "File isn't uploaded" ) ;
70+ throw new FileLoadException ( "File isn't uploaded" ) ;
8071 }
8172 }
8273
@@ -86,7 +77,7 @@ public static byte[] ReadBigArray(IConfiguration config)
8677
8778 return ! string . IsNullOrEmpty ( filePath ) && File . Exists ( filePath )
8879 ? File . ReadAllBytes ( filePath )
89- : GetByteArray ( 123 * 1024 * 1024 ) ; // 123 Mb
80+ : GetByteArray ( 123 * 1024 * 1024 ) ; // 123 Mb
9081 }
9182
9283 public static InputStream ReadBigFile ( IConfiguration config )
@@ -114,28 +105,28 @@ public static async Task<int> ReadStreamMock(Stream input, byte[] buffer, Cancel
114105 return result ;
115106 }
116107
117- public static S3Settings ReadSettings ( IConfiguration config )
108+ public static S3BucketSettings ReadSettings ( IConfiguration config )
118109 {
119- var settings = config . GetRequiredSection ( "S3Storage" ) . Get < S3Settings > ( ) ;
120- if ( settings == null || string . IsNullOrEmpty ( settings . EndPoint ) )
110+ var settings = config . GetRequiredSection ( "S3Storage" ) . Get < S3BucketSettings > ( ) ;
111+ if ( settings == null || string . IsNullOrEmpty ( settings . Endpoint ) )
121112 {
122- throw new Exception ( "S3Storage configuration is not found" ) ;
113+ throw new UriFormatException ( "S3Storage configuration is not found" ) ;
123114 }
124115
125116 var isContainer = Environment . GetEnvironmentVariable ( "DOTNET_RUNNING_IN_CONTAINER" ) ;
126117 if ( isContainer != null && bool . TryParse ( isContainer , out var value ) && value )
127118 {
128- settings = new S3Settings
119+ Uri endpointUri = new ( settings . Endpoint ) ;
120+
121+ settings = new S3BucketSettings
129122 {
130123 AccessKey = settings . AccessKey ,
131124 Bucket = settings . Bucket ,
132- EndPoint = "host.docker.internal" ,
133- Port = settings . Port ,
125+ Endpoint = $ "{ endpointUri . Scheme } ://host.docker.internal:{ endpointUri . Port } ",
134126 Region = settings . Region ,
135127 SecretKey = settings . SecretKey ,
136128 Service = settings . Service ,
137129 UseHttp2 = settings . UseHttp2 ,
138- UseHttps = settings . UseHttps ,
139130 } ;
140131 }
141132
0 commit comments