Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .env
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
APP_HOST=127.0.0.30
APP_HOST=localhost
APP_PORT=8080
S3_ENDPOINT=http://127.0.0.30:9000
S3_ENDPOINT=http://localhost:9001
S3_REGION=us-east-1
S3_BUCKET=test-bucket
MINIO_ACCESS_KEY=my_access_key
MINIO_SECRET_KEY=my_secret_key
RUSTFS_ACCESS_KEY=my_access_key
RUSTFS_SECRET_KEY=my_secret_key
JPG_TEST_OBJECT=100.jpg
PNG_TEST_OBJECT=100.png
GIF_TEST_OBJECT=100.gif
Expand Down
13 changes: 6 additions & 7 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
version: '3'
services:
minio:
image: minio/minio
rustfs:
image: rustfs/rustfs
restart: always
logging:
driver: "json-file"
options:
max-size: "20m"
max-file: "5"
environment:
MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY}
MINIO_SECRET_KEY: ${MINIO_SECRET_KEY}
ports:
- ${APP_HOST}:9000:9000
- 9001:9000
environment:
RUSTFS_ACCESS_KEY: ${RUSTFS_ACCESS_KEY}
RUSTFS_SECRET_KEY: ${RUSTFS_SECRET_KEY}
volumes:
- ./data:/data
command: 'server /data'
4 changes: 2 additions & 2 deletions sample/src/main/kotlin/com/icerockdev/sample/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object Main {
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create(
dotenv["MINIO_ACCESS_KEY"], dotenv["MINIO_SECRET_KEY"]
dotenv["RUSTFS_ACCESS_KEY"], dotenv["RUSTFS_SECRET_KEY"]
)
)
)
Expand All @@ -48,7 +48,7 @@ object Main {
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create(
dotenv["MINIO_ACCESS_KEY"], dotenv["MINIO_SECRET_KEY"]
dotenv["RUSTFS_ACCESS_KEY"], dotenv["RUSTFS_SECRET_KEY"]
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ package com.icerockdev.service.storage.s3.policy.dto

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JsonDeserializer
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.annotation.JsonDeserialize

@JsonInclude(JsonInclude.Include.NON_EMPTY)
data class Principal(
@JsonProperty("AWS")
@JsonDeserialize(using = PrincipalAwsDeserializer::class)
val aws: List<String>,
@JsonProperty("CanonicalUser")
val canonicalUser: String?,
Expand All @@ -14,3 +21,20 @@ data class Principal(
@JsonProperty("Service")
val service: List<String> = emptyList(),
)

class PrincipalAwsDeserializer : JsonDeserializer<List<String>>() {
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): List<String> {
try {
val path = p?.parsingContext?.pathAsPointer()
val node = p?.codec?.readTree<JsonNode>(p)
return when {
node?.isNull == true -> emptyList()
node?.isArray == true -> p.codec?.treeToValue(node, Array<String>::class.java)?.toList() ?: emptyList()
node?.isTextual == true -> p.codec?.treeToValue(node, String::class.java)?.let { listOf(it) } ?: emptyList()
else -> throw IllegalArgumentException("Principal deserialization error. Unexpected value: $node at path: $path")
}
} catch (e: JsonProcessingException) {
throw RuntimeException("Principal deserialization error happened at: ${e.location}", e)
}
}
}
4 changes: 2 additions & 2 deletions storage-service/src/test/kotlin/S3GeneratePreviewTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class S3GeneratePreviewTest {
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create(
dotenv["MINIO_ACCESS_KEY"], dotenv["MINIO_SECRET_KEY"]
dotenv["RUSTFS_ACCESS_KEY"], dotenv["RUSTFS_SECRET_KEY"]
)
)
)
Expand All @@ -55,7 +55,7 @@ class S3GeneratePreviewTest {
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create(
dotenv["MINIO_ACCESS_KEY"], dotenv["MINIO_SECRET_KEY"]
dotenv["RUSTFS_ACCESS_KEY"], dotenv["RUSTFS_SECRET_KEY"]
)
)
)
Expand Down
8 changes: 4 additions & 4 deletions storage-service/src/test/kotlin/S3StorageTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class S3StorageTest {
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create(
dotenv["MINIO_ACCESS_KEY"], dotenv["MINIO_SECRET_KEY"]
dotenv["RUSTFS_ACCESS_KEY"], dotenv["RUSTFS_SECRET_KEY"]
)
)
)
Expand All @@ -72,7 +72,7 @@ class S3StorageTest {
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create(
dotenv["MINIO_ACCESS_KEY"], dotenv["MINIO_SECRET_KEY"]
dotenv["RUSTFS_ACCESS_KEY"], dotenv["RUSTFS_SECRET_KEY"]
)
)
)
Expand Down Expand Up @@ -338,7 +338,7 @@ class S3StorageTest {

val jpgObject = storage.get(bucketName, jpgFileName)

assertEquals(metadata, jpgObject?.response()?.metadata())
assertTrue(jpgObject?.response()?.metadata()?.entries?.containsAll(metadata.entries) ?: false)

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

val copyObject = storage.get(bucketName, copyFileName)

assertEquals(metadata, copyObject?.response()?.metadata())
assertTrue(copyObject?.response()?.metadata()?.entries?.containsAll(metadata.entries) ?: false)

assertTrue {
storage.deleteBucketWithObjects(bucketName)
Expand Down
Loading