2323import io .milvus .bulkwriter .common .clientenum .CloudStorage ;
2424import io .milvus .bulkwriter .model .CompleteMultipartUploadOutputModel ;
2525import io .milvus .bulkwriter .storage .StorageClient ;
26- import io .minio .*;
26+ import io .minio .BucketExistsArgs ;
27+ import io .minio .MinioAsyncClient ;
28+ import io .minio .ObjectWriteResponse ;
29+ import io .minio .PutObjectArgs ;
30+ import io .minio .S3Base ;
31+ import io .minio .StatObjectArgs ;
32+ import io .minio .StatObjectResponse ;
33+ import io .minio .Xml ;
34+ import io .minio .credentials .Provider ;
2735import io .minio .credentials .StaticProvider ;
2836import io .minio .errors .ErrorResponseException ;
2937import io .minio .errors .InsufficientDataException ;
3341import io .minio .messages .CompleteMultipartUpload ;
3442import io .minio .messages .ErrorResponse ;
3543import io .minio .messages .Part ;
44+ import okhttp3 .Interceptor ;
3645import okhttp3 .OkHttpClient ;
46+ import okhttp3 .Request ;
3747import org .apache .commons .lang3 .StringUtils ;
3848import org .slf4j .Logger ;
3949import org .slf4j .LoggerFactory ;
@@ -65,8 +75,14 @@ public static MinioStorageClient getStorageClient(String cloudName,
6575 String region ,
6676 OkHttpClient httpClient ) {
6777 MinioAsyncClient .Builder minioClientBuilder = MinioAsyncClient .builder ()
68- .endpoint (endpoint )
69- .credentialsProvider (new StaticProvider (accessKey , secretKey , sessionToken ));
78+ .endpoint (endpoint );
79+
80+ if (CloudStorage .isGcpCloud (cloudName ) && StringUtils .isNotEmpty (sessionToken )) {
81+ httpClient = buildAuthorizedClient (httpClient , sessionToken );
82+ } else {
83+ Provider credentialsProvider = new StaticProvider (accessKey , secretKey , sessionToken );
84+ minioClientBuilder .credentialsProvider (credentialsProvider );
85+ }
7086
7187 if (StringUtils .isNotEmpty (region )) {
7288 minioClientBuilder .region (region );
@@ -84,6 +100,26 @@ public static MinioStorageClient getStorageClient(String cloudName,
84100 return new MinioStorageClient (minioClient );
85101 }
86102
103+ private static OkHttpClient buildAuthorizedClient (OkHttpClient httpClient , String sessionToken ) {
104+ Interceptor authInterceptor = chain -> {
105+ Request original = chain .request ();
106+ Request requestWithAuth = original .newBuilder ()
107+ .header ("Authorization" , "Bearer " + sessionToken )
108+ .build ();
109+ return chain .proceed (requestWithAuth );
110+ };
111+
112+ if (httpClient != null ) {
113+ return httpClient .newBuilder ()
114+ .addInterceptor (authInterceptor )
115+ .build ();
116+ } else {
117+ return new OkHttpClient .Builder ()
118+ .addInterceptor (authInterceptor )
119+ .build ();
120+ }
121+ }
122+
87123 public Long getObjectEntity (String bucketName , String objectKey ) throws Exception {
88124 StatObjectArgs statObjectArgs = StatObjectArgs .builder ()
89125 .bucket (bucketName )
0 commit comments