diff --git a/resources/docker/docker-compose-api.yml b/resources/docker/docker-compose-api.yml index dba02dae6..26a83e62b 100644 --- a/resources/docker/docker-compose-api.yml +++ b/resources/docker/docker-compose-api.yml @@ -12,9 +12,9 @@ services: DB_PASSWORD: ${DB_PASSWORD} EMAIL_USERNAME: ${EMAIL_USERNAME} EMAIL_PASSWORD: ${EMAIL_PASSWORD} - IMAGE_STORE_URL: ${IMAGE_STORE_URL} - IMAGE_STORE_ACCESS_KEY: ${IMAGE_STORE_ACCESS_KEY} - IMAGE_STORE_SECRET_KEY: ${IMAGE_STORE_SECRET_KEY} + STORAGE_URL: ${STORAGE_URL} + STORAGE_ACCESS_KEY: ${STORAGE_ACCESS_KEY} + STORAGE_SECRET_KEY: ${STORAGE_SECRET_KEY} + STORAGE_REGION: ${STORAGE_REGION} IMAGE_STORE_BUCKET_NAME: ${IMAGE_STORE_BUCKET_NAME} - IMAGE_STORE_REGION: ${IMAGE_STORE_REGION} CDN_URL: ${CDN_URL} diff --git a/storage/src/main/kotlin/com/few/storage/config/ClientConfig.kt b/storage/src/main/kotlin/com/few/storage/config/ClientConfig.kt new file mode 100644 index 000000000..eae4aff84 --- /dev/null +++ b/storage/src/main/kotlin/com/few/storage/config/ClientConfig.kt @@ -0,0 +1,42 @@ +package com.few.storage.config + +import com.amazonaws.auth.AWSStaticCredentialsProvider +import com.amazonaws.auth.BasicAWSCredentials +import com.amazonaws.client.builder.AwsClientBuilder +import com.amazonaws.services.s3.AmazonS3Client +import com.amazonaws.services.s3.AmazonS3ClientBuilder +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +class ClientConfig( + @Value("\${storage.url}") val url: String, + @Value("\${storage.access-key}") val accessKey: String, + @Value("\${storage.secret-key}") val secretKey: String, + @Value("\${storage.region}") val region: String +) { + + @Bean + fun s3StorageClient(): AmazonS3Client { + val builder = AmazonS3ClientBuilder.standard() + .withCredentials( + AWSStaticCredentialsProvider( + BasicAWSCredentials( + accessKey, + secretKey + ) + ) + ) + .withEndpointConfiguration( + AwsClientBuilder.EndpointConfiguration( + url, + region + ) + ) + + builder.build().let { client -> + return client as AmazonS3Client + } + } +} \ No newline at end of file diff --git a/storage/src/main/kotlin/com/few/storage/image/config/ImageStorageConfig.kt b/storage/src/main/kotlin/com/few/storage/image/config/ImageStorageConfig.kt index e42197f51..b4605d1d8 100644 --- a/storage/src/main/kotlin/com/few/storage/image/config/ImageStorageConfig.kt +++ b/storage/src/main/kotlin/com/few/storage/image/config/ImageStorageConfig.kt @@ -1,10 +1,13 @@ package com.few.storage.image.config +import com.few.storage.config.ClientConfig import org.springframework.context.annotation.ComponentScan import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Import @Configuration @ComponentScan(basePackages = [ImageStorageConfig.BASE_PACKAGE]) +@Import(ClientConfig::class) class ImageStorageConfig { companion object { const val BASE_PACKAGE = "com.few.storage.image" diff --git a/storage/src/main/kotlin/com/few/storage/image/config/S3ImageStoreConfig.kt b/storage/src/main/kotlin/com/few/storage/image/config/S3ImageStoreConfig.kt index 5be02cdb6..659ac7693 100644 --- a/storage/src/main/kotlin/com/few/storage/image/config/S3ImageStoreConfig.kt +++ b/storage/src/main/kotlin/com/few/storage/image/config/S3ImageStoreConfig.kt @@ -1,10 +1,6 @@ package com.few.storage.image.config -import com.amazonaws.auth.AWSStaticCredentialsProvider -import com.amazonaws.auth.BasicAWSCredentials -import com.amazonaws.client.builder.AwsClientBuilder import com.amazonaws.services.s3.AmazonS3Client -import com.amazonaws.services.s3.AmazonS3ClientBuilder import com.few.storage.image.client.ImageStoreClient import com.few.storage.image.client.S3ImageStoreClient import org.slf4j.Logger @@ -17,11 +13,8 @@ import org.springframework.context.event.ContextRefreshedEvent @Configuration class S3ImageStoreConfig( - @Value("\${image.store.url}") val url: String, - @Value("\${image.store.access-key}") val accessKey: String, - @Value("\${image.store.secret-key}") val secretKey: String, @Value("\${image.store.bucket-name}") val bucket: String, - @Value("\${image.store.region}") val region: String + @Value("\${storage.region}") val region: String ) : ApplicationListener { var log: Logger = LoggerFactory.getLogger(S3ImageStoreConfig::class.java) @@ -41,26 +34,8 @@ class S3ImageStoreConfig( } @Bean - fun s3ImageStoreClient(): ImageStoreClient { - val builder = AmazonS3ClientBuilder.standard() - .withCredentials( - AWSStaticCredentialsProvider( - BasicAWSCredentials( - accessKey, - secretKey - ) - ) - ) - .withEndpointConfiguration( - AwsClientBuilder.EndpointConfiguration( - url, - region - ) - ) - - builder.build().let { client -> - this.client = client as AmazonS3Client - return S3ImageStoreClient(client, region) - } + fun s3ImageStoreClient(s3StorageClient: AmazonS3Client): ImageStoreClient { + client = s3StorageClient + return S3ImageStoreClient(client!!, region) } } \ No newline at end of file diff --git a/storage/src/main/resources/application-storage-local.yml b/storage/src/main/resources/application-storage-local.yml index 39dfe4a8d..3024181e5 100644 --- a/storage/src/main/resources/application-storage-local.yml +++ b/storage/src/main/resources/application-storage-local.yml @@ -1,10 +1,12 @@ +storage: + url: http://127.0.0.1:9000 + access-key: thisisroot + secret-key: thisisroot + region: ap-northeast-2 + image: store: - url: http://127.0.0.1:9000 - access-key: thisisroot - secret-key: thisisroot bucket-name: picture - region: ap-northeast-2 cdn: url: http://127.0.0.1:9000 diff --git a/storage/src/main/resources/application-storage-prd.yml b/storage/src/main/resources/application-storage-prd.yml index 37dffaaab..3f5114b6c 100644 --- a/storage/src/main/resources/application-storage-prd.yml +++ b/storage/src/main/resources/application-storage-prd.yml @@ -1,10 +1,13 @@ +storage: + url: ${STORAGE_URL} + access-key: ${STORAGE_ACCESS_KEY} + secret-key: ${STORAGE_SECRET_KEY} + region: ${STORAGE_REGION} + image: store: - url: ${IMAGE_STORE_URL} - access-key: ${IMAGE_STORE_ACCESS_KEY} - secret-key: ${IMAGE_STORE_SECRET_KEY} bucket-name: ${IMAGE_STORE_BUCKET_NAME} - region: ${IMAGE_STORE_REGION} + region: ${STORAGE_REGION} cdn: url: ${CDN_URL}