@@ -42,47 +42,73 @@ public MinIoClientFactory(IOptions<StorageServiceConfiguration> options)
4242 _clients = new ConcurrentDictionary < string , MinioClient > ( ) ;
4343 }
4444
45- public MinioClient GetClient ( )
45+ public IMinioClient GetClient ( )
4646 {
4747 return _clients . GetOrAdd ( DefaultClient , _ =>
48- {
49- var accessKey = Options . Settings [ ConfigurationKeys . AccessKey ] ;
50- var accessToken = Options . Settings [ ConfigurationKeys . AccessToken ] ;
51- var client = CreateClient ( accessKey , accessToken ) ;
48+ {
49+ var accessKey = Options . Settings [ ConfigurationKeys . AccessKey ] ;
50+ var accessToken = Options . Settings [ ConfigurationKeys . AccessToken ] ;
51+ var client = CreateClient ( accessKey , accessToken ) ;
5252
53- return client . Build ( ) ;
54- } ) ;
53+ return client . Build ( ) ;
54+ } ) ;
5555 }
5656
57- public MinioClient GetClient ( Credentials credentials )
57+ public IMinioClient GetClient ( Credentials credentials )
5858 {
5959 return GetClient ( credentials , string . Empty ) ;
6060 }
6161
62- public MinioClient GetClient ( Credentials credentials , string region )
62+ public IMinioClient GetClient ( Credentials credentials , string region )
6363 {
64- Guard . Against . Null ( credentials , nameof ( credentials ) ) ;
65- Guard . Against . NullOrWhiteSpace ( credentials . AccessKeyId , nameof ( credentials . AccessKeyId ) ) ;
66- Guard . Against . NullOrWhiteSpace ( credentials . SecretAccessKey , nameof ( credentials . SecretAccessKey ) ) ;
67- Guard . Against . NullOrWhiteSpace ( credentials . SessionToken , nameof ( credentials . SessionToken ) ) ;
64+ return GetClientInternal ( credentials , region ) ;
65+ }
6866
69- return _clients . GetOrAdd ( credentials . SessionToken , _ =>
67+ public IBucketOperations GetBucketOperationsClient ( )
68+ {
69+ return _clients . GetOrAdd ( DefaultClient , _ =>
7070 {
71- var client = CreateClient ( credentials . AccessKeyId , credentials . SecretAccessKey ) ;
72- client . WithSessionToken ( credentials . SessionToken ) ;
73-
74- if ( ! string . IsNullOrWhiteSpace ( region ) )
75- {
76- client . WithRegion ( region ) ;
77- }
71+ var accessKey = Options . Settings [ ConfigurationKeys . AccessKey ] ;
72+ var accessToken = Options . Settings [ ConfigurationKeys . AccessToken ] ;
73+ var client = CreateClient ( accessKey , accessToken ) ;
7874
7975 return client . Build ( ) ;
8076 } ) ;
77+ }
8178
79+ public IBucketOperations GetBucketOperationsClient ( Credentials credentials )
80+ {
81+ return GetClientInternal ( credentials , string . Empty ) ;
82+ }
8283
84+ public IBucketOperations GetBucketOperationsClient ( Credentials credentials , string region )
85+ {
86+ return GetClientInternal ( credentials , region ) ;
8387 }
8488
85- private MinioClient CreateClient ( string accessKey , string accessToken )
89+ public IObjectOperations GetObjectOperationsClient ( )
90+ {
91+ return _clients . GetOrAdd ( DefaultClient , _ =>
92+ {
93+ var accessKey = Options . Settings [ ConfigurationKeys . AccessKey ] ;
94+ var accessToken = Options . Settings [ ConfigurationKeys . AccessToken ] ;
95+ var client = CreateClient ( accessKey , accessToken ) ;
96+
97+ return client . Build ( ) ;
98+ } ) ;
99+ }
100+
101+ public IObjectOperations GetObjectOperationsClient ( Credentials credentials )
102+ {
103+ return GetClientInternal ( credentials , string . Empty ) ;
104+ }
105+
106+ public IObjectOperations GetObjectOperationsClient ( Credentials credentials , string region )
107+ {
108+ return GetClientInternal ( credentials , region ) ;
109+ }
110+
111+ private IMinioClient CreateClient ( string accessKey , string accessToken )
86112 {
87113 var endpoint = Options . Settings [ ConfigurationKeys . EndPoint ] ;
88114 var securedConnection = Options . Settings [ ConfigurationKeys . SecuredConnection ] ;
@@ -99,6 +125,27 @@ private MinioClient CreateClient(string accessKey, string accessToken)
99125 return client ;
100126 }
101127
128+ private MinioClient GetClientInternal ( Credentials credentials , string region )
129+ {
130+ Guard . Against . Null ( credentials , nameof ( credentials ) ) ;
131+ Guard . Against . NullOrWhiteSpace ( credentials . AccessKeyId , nameof ( credentials . AccessKeyId ) ) ;
132+ Guard . Against . NullOrWhiteSpace ( credentials . SecretAccessKey , nameof ( credentials . SecretAccessKey ) ) ;
133+ Guard . Against . NullOrWhiteSpace ( credentials . SessionToken , nameof ( credentials . SessionToken ) ) ;
134+
135+ return _clients . GetOrAdd ( credentials . SessionToken , _ =>
136+ {
137+ var client = CreateClient ( credentials . AccessKeyId , credentials . SecretAccessKey ) ;
138+ client . WithSessionToken ( credentials . SessionToken ) ;
139+
140+ if ( ! string . IsNullOrWhiteSpace ( region ) )
141+ {
142+ client . WithRegion ( region ) ;
143+ }
144+
145+ return client . Build ( ) ;
146+ } ) ;
147+ }
148+
102149 private void ValidateConfiguration ( StorageServiceConfiguration configuration )
103150 {
104151 Guard . Against . Null ( configuration , nameof ( configuration ) ) ;
0 commit comments