From 3009a43e11b6ba22aa4e33cc85395173d20fc4b1 Mon Sep 17 00:00:00 2001 From: Petr Rudichev Date: Wed, 19 Feb 2025 10:39:11 +0300 Subject: [PATCH] feat: add image properties, db.changelog and ObjectStorageConfig --- .../nto/config/ObjectStorageConfig.java | 42 +++++++++++++++++++ src/main/resources/application.properties | 7 ++++ .../db.changelog/db.changelog-master.xml | 4 ++ 3 files changed, 53 insertions(+) create mode 100644 src/main/java/com/example/nto/config/ObjectStorageConfig.java create mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/db.changelog/db.changelog-master.xml diff --git a/src/main/java/com/example/nto/config/ObjectStorageConfig.java b/src/main/java/com/example/nto/config/ObjectStorageConfig.java new file mode 100644 index 0000000..c37b694 --- /dev/null +++ b/src/main/java/com/example/nto/config/ObjectStorageConfig.java @@ -0,0 +1,42 @@ +package com.example.nto.config; + +import com.amazonaws.SdkClientException; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Getter +@Configuration +public class ObjectStorageConfig { + @Value("${yandex.cloud.region}") + private String region; + @Value("${yandex.cloud.s3_endpoint}") + private String s3Endpoint; + + @Value("${yandex.cloud.bucket}") + private String bucketName; + @Value("${yandex.cloud.key_id}") + private String accessKeyId; + @Value("${yandex.cloud.secret_key}") + private String secretAccessKey; + + + public AmazonS3 createAmazonS3() { + // Создание клиента AmazonS3 с подключением к Object Storage + try { + return AmazonS3ClientBuilder.standard() + .withEndpointConfiguration(new com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration(s3Endpoint, region)) + .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKeyId, secretAccessKey))) + .build(); + } catch (SdkClientException e) { + log.error("Ошибка при создании клиента для хранения объектов с помощью AWS SDK. Причина: {}", e.getMessage()); + throw new SdkClientException(e.getMessage()); + } + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..05a1f51 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,7 @@ +spring.servlet.multipart.max-file-size=10MB +spring.servlet.multipart.max-request-size=10MB +yandex.cloud.region=ru-central1 +yandex.cloud.s3_endpoint=https://storage.yandexcloud.net +yandex.cloud.key_id=YCAJEIOy-pmwxonO9XLqdhAVI +yandex.cloud.secret_key=YCNJMJf9VGP9OmFiPs5XbnfKzzarBl1B1ymGz1uu +yandex.cloud.bucket=spring-boot-final-nto-bacet \ No newline at end of file diff --git a/src/main/resources/db.changelog/db.changelog-master.xml b/src/main/resources/db.changelog/db.changelog-master.xml new file mode 100644 index 0000000..ece04a5 --- /dev/null +++ b/src/main/resources/db.changelog/db.changelog-master.xml @@ -0,0 +1,4 @@ + + \ No newline at end of file