Skip to content

Commit ec76525

Browse files
committed
WD-696 change MinIO to RustFS as target S3, update deserialization and tests
1 parent 6f32b41 commit ec76525

4 files changed

Lines changed: 35 additions & 12 deletions

File tree

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ APP_PORT=8080
33
S3_ENDPOINT=http://127.0.0.30:9000
44
S3_REGION=us-east-1
55
S3_BUCKET=test-bucket
6-
MINIO_ACCESS_KEY=my_access_key
7-
MINIO_SECRET_KEY=my_secret_key
6+
RUSTFS_ACCESS_KEY=my_access_key
7+
RUSTFS_SECRET_KEY=my_secret_key
88
JPG_TEST_OBJECT=100.jpg
99
PNG_TEST_OBJECT=100.png
1010
GIF_TEST_OBJECT=100.gif

docker-compose.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
version: '3'
22
services:
3-
minio:
4-
image: minio/minio
3+
rustfs:
4+
image: rustfs/rustfs
55
restart: always
66
logging:
77
driver: "json-file"
88
options:
99
max-size: "20m"
1010
max-file: "5"
11-
environment:
12-
MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY}
13-
MINIO_SECRET_KEY: ${MINIO_SECRET_KEY}
1411
ports:
1512
- ${APP_HOST}:9000:9000
13+
environment:
14+
RUSTFS_ACCESS_KEY: ${RUSTFS_ACCESS_KEY}
15+
RUSTFS_SECRET_KEY: ${RUSTFS_SECRET_KEY}
1616
volumes:
1717
- ./data:/data
18-
command: 'server /data'

storage-service/src/main/kotlin/com/icerockdev/service/storage/s3/policy/dto/Principal.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ package com.icerockdev.service.storage.s3.policy.dto
22

33
import com.fasterxml.jackson.annotation.JsonInclude
44
import com.fasterxml.jackson.annotation.JsonProperty
5+
import com.fasterxml.jackson.core.JsonParser
6+
import com.fasterxml.jackson.core.JsonProcessingException
7+
import com.fasterxml.jackson.databind.DeserializationContext
8+
import com.fasterxml.jackson.databind.JsonDeserializer
9+
import com.fasterxml.jackson.databind.JsonNode
10+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
511

612
@JsonInclude(JsonInclude.Include.NON_EMPTY)
713
data class Principal(
814
@JsonProperty("AWS")
15+
@JsonDeserialize(using = PrincipalAwsDeserializer::class)
916
val aws: List<String>,
1017
@JsonProperty("CanonicalUser")
1118
val canonicalUser: String?,
@@ -14,3 +21,20 @@ data class Principal(
1421
@JsonProperty("Service")
1522
val service: List<String> = emptyList(),
1623
)
24+
25+
class PrincipalAwsDeserializer : JsonDeserializer<List<String>>() {
26+
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): List<String> {
27+
try {
28+
val path = p?.parsingContext?.pathAsPointer()
29+
val node = p?.codec?.readTree<JsonNode>(p)
30+
return when {
31+
node?.isNull == true -> emptyList()
32+
node?.isArray == true -> p.codec?.treeToValue(node, Array<String>::class.java)?.toList() ?: emptyList()
33+
node?.isTextual == true -> p.codec?.treeToValue(node, String::class.java)?.let { listOf(it) } ?: emptyList()
34+
else -> throw IllegalArgumentException("Principal deserialization error. Unexpected value: $node at path: $path")
35+
}
36+
} catch (e: JsonProcessingException) {
37+
throw RuntimeException("Principal deserialization error happened at: ${e.location}", e)
38+
}
39+
}
40+
}

storage-service/src/test/kotlin/S3StorageTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class S3StorageTest {
5959
.credentialsProvider(
6060
StaticCredentialsProvider.create(
6161
AwsBasicCredentials.create(
62-
dotenv["MINIO_ACCESS_KEY"], dotenv["MINIO_SECRET_KEY"]
62+
dotenv["RUSTFS_ACCESS_KEY"], dotenv["RUSTFS_SECRET_KEY"]
6363
)
6464
)
6565
)
@@ -72,7 +72,7 @@ class S3StorageTest {
7272
.credentialsProvider(
7373
StaticCredentialsProvider.create(
7474
AwsBasicCredentials.create(
75-
dotenv["MINIO_ACCESS_KEY"], dotenv["MINIO_SECRET_KEY"]
75+
dotenv["RUSTFS_ACCESS_KEY"], dotenv["RUSTFS_SECRET_KEY"]
7676
)
7777
)
7878
)
@@ -338,7 +338,7 @@ class S3StorageTest {
338338

339339
val jpgObject = storage.get(bucketName, jpgFileName)
340340

341-
assertEquals(metadata, jpgObject?.response()?.metadata())
341+
assertTrue(jpgObject?.response()?.metadata()?.entries?.containsAll(metadata.entries) ?: false)
342342

343343
// copy testing
344344
val copyFileName = storage.generateFileKey()
@@ -349,7 +349,7 @@ class S3StorageTest {
349349

350350
val copyObject = storage.get(bucketName, copyFileName)
351351

352-
assertEquals(metadata, copyObject?.response()?.metadata())
352+
assertTrue(copyObject?.response()?.metadata()?.entries?.containsAll(metadata.entries) ?: false)
353353

354354
assertTrue {
355355
storage.deleteBucketWithObjects(bucketName)

0 commit comments

Comments
 (0)