From 32110b2f11dfaddd57395eaca5fa6927e80e1a26 Mon Sep 17 00:00:00 2001 From: thguss Date: Mon, 9 Sep 2024 21:51:37 +0900 Subject: [PATCH 1/7] fix: updated secret manager --- .../bootstrap/secret/SecretProcessor.java | 91 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 1 + .../src/main/resources/application-dev.yml | 24 +++-- .../src/main/resources/application-local.yml | 24 +++-- .../src/main/resources/application-prod.yml | 24 +++-- .../src/main/resources/application.yml | 12 +++ .../smeem/common/exception/ExceptionCode.java | 1 + 7 files changed, 138 insertions(+), 39 deletions(-) create mode 100644 smeem-bootstrap/src/main/java/com/smeem/bootstrap/secret/SecretProcessor.java create mode 100644 smeem-bootstrap/src/main/resources/META-INF/spring.factories create mode 100644 smeem-bootstrap/src/main/resources/application.yml diff --git a/smeem-bootstrap/src/main/java/com/smeem/bootstrap/secret/SecretProcessor.java b/smeem-bootstrap/src/main/java/com/smeem/bootstrap/secret/SecretProcessor.java new file mode 100644 index 00000000..c7bc4cbc --- /dev/null +++ b/smeem-bootstrap/src/main/java/com/smeem/bootstrap/secret/SecretProcessor.java @@ -0,0 +1,91 @@ +package com.smeem.bootstrap.secret; + +import com.smeem.common.exception.ExceptionCode; +import com.smeem.common.exception.SmeemException; +import lombok.extern.slf4j.Slf4j; +import lombok.val; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.http.HttpHeaders; +import org.springframework.web.client.RestClient; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +@Slf4j +public class SecretProcessor implements EnvironmentPostProcessor { + private static final String PROFILE_SEPARATOR = ","; + private static final String SMEEM_SECRET_PROPERTY_NAME = "smeemApplicationSecretProperty"; + private static final String PROPERTY_SECRET_MANAGER_TOKEN_NAME = "SECRET_MANAGER_TOKEN"; + private static final String PROPERTY_SECRET_MANAGER_WORKSPACE_ID = "SECRET_MANAGER_WORKSPACE_ID"; + private static final String BEARER_TOKEN_PREFIX = "Bearer"; + private static final String SECRET_MANAGER_URL = "https://app.infisical.com/api/v3"; + private static final Set SUPPORT_PROFILES = Set.of("local", "dev", "prod"); + + @Override + public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { + val secrets = getSecrets(environment); + val smeemSecretProperties = new MapPropertySource( + SMEEM_SECRET_PROPERTY_NAME, + secrets.stream().collect(Collectors.toMap(Secret::secretKey, Secret::secretValue))); + environment.getPropertySources().addLast(smeemSecretProperties); + } + + private List getSecrets(ConfigurableEnvironment environment) { + val activeProfiles = Arrays.stream(environment.getActiveProfiles()).toList(); + log.info("### ACTIVE PROFILES: {} ###", String.join(PROFILE_SEPARATOR, activeProfiles)); + + val secretToken = getPropertyOrThrow(environment, PROPERTY_SECRET_MANAGER_TOKEN_NAME); + val workspaceId = getPropertyOrThrow(environment, PROPERTY_SECRET_MANAGER_WORKSPACE_ID); + val currentEnvironment = activeProfiles.stream() + .filter(SUPPORT_PROFILES::contains) + .findFirst() + .orElseThrow(() -> new SmeemException(ExceptionCode.INTERNAL_SERVER_ERROR, "No active profile found")); + + val response = secretManagerRestClient(secretToken).get() + .uri(uriBuilder -> uriBuilder + .path("/secrets/raw") + .queryParam("workspaceId", workspaceId) + .queryParam("environment", currentEnvironment) + .build()) + .retrieve() + .body(SecretResponse.class); + + return response != null ? response.secrets : List.of(); + } + + private String getPropertyOrThrow(ConfigurableEnvironment environment, String propertyName) { + String property = environment.getProperty(propertyName, String.class); + if (property == null) { + throw new SmeemException(ExceptionCode.INTERNAL_SERVER_ERROR, "Secret manager config not set"); + } + return property; + } + + private RestClient secretManagerRestClient(String secretToken) { + return RestClient.builder() + .defaultHeaders(headers -> + headers.add(HttpHeaders.AUTHORIZATION, BEARER_TOKEN_PREFIX + " " + secretToken)) + .baseUrl(SECRET_MANAGER_URL) + .build(); + } + + private record SecretResponse( + List secrets + ) { + } + + private record Secret( + String id, + String workspace, + String environment, + Long version, + String secretKey, + String secretValue + ) { + } +} diff --git a/smeem-bootstrap/src/main/resources/META-INF/spring.factories b/smeem-bootstrap/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..5abf6dd9 --- /dev/null +++ b/smeem-bootstrap/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.env.EnvironmentPostProcessor=com.smeem.bootstrap.secret.SecretProcessor diff --git a/smeem-bootstrap/src/main/resources/application-dev.yml b/smeem-bootstrap/src/main/resources/application-dev.yml index a7fceba8..96e46d39 100644 --- a/smeem-bootstrap/src/main/resources/application-dev.yml +++ b/smeem-bootstrap/src/main/resources/application-dev.yml @@ -1,13 +1,12 @@ spring: config: - import: application-secret.yml activate: on-profile: dev datasource: driver-class-name: org.postgresql.Driver - url: jdbc:postgresql://${DATABASE.ENDPOINT_URL.dev}:5432/postgres?currentSchema=${DATABASE.NAME.dev} - username: ${DATABASE.USERNAME.dev} - password: ${DATABASE.PASSWORD.dev} + url: jdbc:postgresql://${DB_URL}:5432/postgres?currentSchema=${DB_NAME} + username: ${DB_USERNAME} + password: ${DB_PASSWORD} jpa: hibernate: ddl-auto: none @@ -24,10 +23,10 @@ logging.level: ### smeem smeem: secret: - key: ${SMEEM.SECRET.KEY} + key: ${SMEEM_SECRET_KEY} duration: - expired: ${SMEEM.DURATION.EXPIRED} - remind: ${SMEEM.DURATION.REMIND} + expired: ${SMEEM_DURATION_EXPIRED} + remind: ${SMEEM_DURATION_REMIND} client: version: title: "업데이트 알림" @@ -58,13 +57,12 @@ oauth: discord: webhook: url: - sign-in: ${DISCORD.WEBHOOK.URL.TEST} - withdraw: ${DISCORD.WEBHOOK.URL.TEST} - error: ${DISCORD.WEBHOOK.URL.TEST} + sign-in: ${DISCORD_WEBHOOK_SIGN_IN_URL} + withdraw: ${DISCORD_WEBHOOK_WITHDRAW_URL} + error: ${DISCORD_WEBHOOK_ERROR_URL} ### notification fcm: file_path: firebase-config/smeem_fcm_dev.json - project_id: ${FCM.PROJECT_ID.dev} - url: ${FCM.URL} - google_api: https://www.googleapis.com/auth/cloud-platform + project_id: ${FCM_PROJECT_ID} +# google_api: https://www.googleapis.com/auth/cloud-platform diff --git a/smeem-bootstrap/src/main/resources/application-local.yml b/smeem-bootstrap/src/main/resources/application-local.yml index 9f19c5ed..f40f23f0 100644 --- a/smeem-bootstrap/src/main/resources/application-local.yml +++ b/smeem-bootstrap/src/main/resources/application-local.yml @@ -1,13 +1,12 @@ spring: config: - import: application-secret.yml activate: on-profile: local datasource: driver-class-name: org.postgresql.Driver - url: jdbc:postgresql://localhost:5432/postgres?currentSchema=smeem - username: postgres - password: postgres + url: jdbc:postgresql://${DB_URL}:5432/postgres?currentSchema=${DB_NAME} + username: ${DB_USERNAME} + password: ${DB_PASSWORD} jpa: hibernate: ddl-auto: none @@ -24,10 +23,10 @@ logging.level: ### smeem smeem: secret: - key: ${SMEEM.SECRET.KEY} + key: ${SMEEM_SECRET_KEY} duration: - expired: ${SMEEM.DURATION.EXPIRED} - remind: ${SMEEM.DURATION.REMIND} + expired: ${SMEEM_DURATION_EXPIRED} + remind: ${SMEEM_DURATION_REMIND} client: version: title: "업데이트 알림" @@ -58,13 +57,12 @@ oauth: discord: webhook: url: - sign-in: ${DISCORD.WEBHOOK.URL.TEST} - withdraw: ${DISCORD.WEBHOOK.URL.TEST} - error: ${DISCORD.WEBHOOK.URL.TEST} + sign-in: ${DISCORD_WEBHOOK_SIGN_IN_URL} + withdraw: ${DISCORD_WEBHOOK_WITHDRAW_URL} + error: ${DISCORD_WEBHOOK_ERROR_URL} ### notification fcm: file_path: firebase-config/smeem_fcm_dev.json - project_id: ${FCM.PROJECT_ID.dev} - url: ${FCM.URL} - google_api: https://www.googleapis.com/auth/cloud-platform + project_id: ${FCM_PROJECT_ID} +# google_api: https://www.googleapis.com/auth/cloud-platform diff --git a/smeem-bootstrap/src/main/resources/application-prod.yml b/smeem-bootstrap/src/main/resources/application-prod.yml index 4cf7d9b4..11ca8164 100644 --- a/smeem-bootstrap/src/main/resources/application-prod.yml +++ b/smeem-bootstrap/src/main/resources/application-prod.yml @@ -1,13 +1,12 @@ spring: config: - import: application-secret.yml activate: on-profile: prod datasource: driver-class-name: org.postgresql.Driver - url: jdbc:postgresql://${DATABASE.ENDPOINT_URL.prod}:5432/postgres?currentSchema=${DATABASE.NAME.prod} - username: ${DATABASE.USERNAME.prod} - password: ${DATABASE.PASSWORD.prod} + url: jdbc:postgresql://${DB_URL}:5432/postgres?currentSchema=${DB_NAME} + username: ${DB_USERNAME} + password: ${DB_PASSWORD} jpa: hibernate: ddl-auto: none @@ -24,10 +23,10 @@ logging.level: ### smeem smeem: secret: - key: ${SMEEM.SECRET.KEY} + key: ${SMEEM_SECRET_KEY} duration: - expired: ${SMEEM.DURATION.EXPIRED} - remind: ${SMEEM.DURATION.REMIND} + expired: ${SMEEM_DURATION_EXPIRED} + remind: ${SMEEM_DURATION_REMIND} client: version: title: "업데이트 알림" @@ -58,13 +57,12 @@ oauth: discord: webhook: url: - sign-in: ${DISCORD.WEBHOOK.URL.PROD.SIGN_IN} - withdraw: ${DISCORD.WEBHOOK.URL.PROD.WITHDRAW} - error: ${DISCORD.WEBHOOK.URL.PROD.ERROR} + sign-in: ${DISCORD_WEBHOOK_SIGN_IN_URL} + withdraw: ${DISCORD_WEBHOOK_WITHDRAW_URL} + error: ${DISCORD_WEBHOOK_ERROR_URL} ### notification fcm: file_path: firebase-config/smeem_fcm_prod.json - project_id: ${FCM.PROJECT_ID.prod} - url: ${FCM.URL} - google_api: https://www.googleapis.com/auth/cloud-platform + project_id: ${FCM_PROJECT_ID} +# google_api: https://www.googleapis.com/auth/cloud-platform diff --git a/smeem-bootstrap/src/main/resources/application.yml b/smeem-bootstrap/src/main/resources/application.yml new file mode 100644 index 00000000..c1a22ebe --- /dev/null +++ b/smeem-bootstrap/src/main/resources/application.yml @@ -0,0 +1,12 @@ +spring: +# config: +# import: +# - classpath:application-actuator.yml + application: + name: "smeem" + messages: + encoding: UTF-8 + +secret: + token: ${SECRET_MANAGER_TOKEN} + workspace-id: ${SECRET_MANAGER_WORKSPACE_ID} diff --git a/smeem-common/src/main/java/com/smeem/common/exception/ExceptionCode.java b/smeem-common/src/main/java/com/smeem/common/exception/ExceptionCode.java index 588ba958..66e728bf 100644 --- a/smeem-common/src/main/java/com/smeem/common/exception/ExceptionCode.java +++ b/smeem-common/src/main/java/com/smeem/common/exception/ExceptionCode.java @@ -12,6 +12,7 @@ public enum ExceptionCode { // 5xx SERVICE_AVAILABLE(503, "서비스에 접근할 수 없음 "), + INTERNAL_SERVER_ERROR(500, "서버 내부 오류"), ; private final int statusCode; From 3222c924c80b8aa3c543fd1efabbcbbad0df297b Mon Sep 17 00:00:00 2001 From: thguss Date: Mon, 9 Sep 2024 23:28:12 +0900 Subject: [PATCH 2/7] fix: separated application yaml --- smeem-bootstrap/src/main/resources/application.yml | 7 ++++--- .../src/main/resources/oauth-apple-config/application.yml | 2 ++ .../src/main/resources/oauth-kakao-config/application.yml | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 smeem-output-oauth/apple/src/main/resources/oauth-apple-config/application.yml create mode 100644 smeem-output-oauth/kakao/src/main/resources/oauth-kakao-config/application.yml diff --git a/smeem-bootstrap/src/main/resources/application.yml b/smeem-bootstrap/src/main/resources/application.yml index c1a22ebe..3d60f036 100644 --- a/smeem-bootstrap/src/main/resources/application.yml +++ b/smeem-bootstrap/src/main/resources/application.yml @@ -1,7 +1,8 @@ spring: -# config: -# import: -# - classpath:application-actuator.yml + config: + import: + - classpath:oauth-apple-config/application.yml + - classpath:oauth-kakao-config/application.yml application: name: "smeem" messages: diff --git a/smeem-output-oauth/apple/src/main/resources/oauth-apple-config/application.yml b/smeem-output-oauth/apple/src/main/resources/oauth-apple-config/application.yml new file mode 100644 index 00000000..31109c31 --- /dev/null +++ b/smeem-output-oauth/apple/src/main/resources/oauth-apple-config/application.yml @@ -0,0 +1,2 @@ +apple: + url: https://appleid.apple.com/auth/keys diff --git a/smeem-output-oauth/kakao/src/main/resources/oauth-kakao-config/application.yml b/smeem-output-oauth/kakao/src/main/resources/oauth-kakao-config/application.yml new file mode 100644 index 00000000..62e589e5 --- /dev/null +++ b/smeem-output-oauth/kakao/src/main/resources/oauth-kakao-config/application.yml @@ -0,0 +1,2 @@ +kakao: + url: https://kapi.kakao.com/v2/user/me From 9f1443a312ee8c332d95355a7573d3b85b51cefa Mon Sep 17 00:00:00 2001 From: thguss Date: Mon, 9 Sep 2024 23:30:51 +0900 Subject: [PATCH 3/7] fix: separated application-profile yaml --- .../smeem-config/application-dev.yml | 15 +++++ .../smeem-config/application-local.yml | 15 +++++ .../smeem-config/application-prod.yml | 15 +++++ .../src/main/resources/application-dev.yml | 66 ++----------------- .../src/main/resources/application-local.yml | 66 ++----------------- .../src/main/resources/application-prod.yml | 66 ++----------------- .../common-config/application-dev.yml | 6 ++ .../common-config/application-local.yml | 6 ++ .../common-config/application-prod.yml | 6 ++ .../notification-config/application-dev.yml | 6 ++ .../notification-config/application-local.yml | 6 ++ .../notification-config/application-prod.yml | 6 ++ .../postgres-config/application-dev.yml | 19 ++++++ .../postgres-config/application-local.yml | 19 ++++++ .../postgres-config/application-prod.yml | 19 ++++++ 15 files changed, 153 insertions(+), 183 deletions(-) create mode 100644 smeem-application/src/main/resources/smeem-config/application-dev.yml create mode 100644 smeem-application/src/main/resources/smeem-config/application-local.yml create mode 100644 smeem-application/src/main/resources/smeem-config/application-prod.yml create mode 100644 smeem-common/src/main/resources/common-config/application-dev.yml create mode 100644 smeem-common/src/main/resources/common-config/application-local.yml create mode 100644 smeem-common/src/main/resources/common-config/application-prod.yml create mode 100644 smeem-output-notification/firebase/src/main/resources/notification-config/application-dev.yml create mode 100644 smeem-output-notification/firebase/src/main/resources/notification-config/application-local.yml create mode 100644 smeem-output-notification/firebase/src/main/resources/notification-config/application-prod.yml create mode 100644 smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-dev.yml create mode 100644 smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-local.yml create mode 100644 smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-prod.yml diff --git a/smeem-application/src/main/resources/smeem-config/application-dev.yml b/smeem-application/src/main/resources/smeem-config/application-dev.yml new file mode 100644 index 00000000..f9bf4824 --- /dev/null +++ b/smeem-application/src/main/resources/smeem-config/application-dev.yml @@ -0,0 +1,15 @@ +smeem: + secret: + key: ${SMEEM_SECRET_KEY} + duration: + remind: ${SMEEM_DURATION_REMIND} + client: + version: + title: ${CLIENT_VERSION_TITLE} + content: ${CLIENT_VERSION_CONTENT} + ios: + app: ${CLIENT_VERSION_IOS_APP} + force: ${CLIENT_VERSION_IOS_FORCE} + android: + app: ${CLIENT_VERSION_ANDROID_APP} + force: ${CLIENT_VERSION_ANDROID_FORCE} diff --git a/smeem-application/src/main/resources/smeem-config/application-local.yml b/smeem-application/src/main/resources/smeem-config/application-local.yml new file mode 100644 index 00000000..f9bf4824 --- /dev/null +++ b/smeem-application/src/main/resources/smeem-config/application-local.yml @@ -0,0 +1,15 @@ +smeem: + secret: + key: ${SMEEM_SECRET_KEY} + duration: + remind: ${SMEEM_DURATION_REMIND} + client: + version: + title: ${CLIENT_VERSION_TITLE} + content: ${CLIENT_VERSION_CONTENT} + ios: + app: ${CLIENT_VERSION_IOS_APP} + force: ${CLIENT_VERSION_IOS_FORCE} + android: + app: ${CLIENT_VERSION_ANDROID_APP} + force: ${CLIENT_VERSION_ANDROID_FORCE} diff --git a/smeem-application/src/main/resources/smeem-config/application-prod.yml b/smeem-application/src/main/resources/smeem-config/application-prod.yml new file mode 100644 index 00000000..f9bf4824 --- /dev/null +++ b/smeem-application/src/main/resources/smeem-config/application-prod.yml @@ -0,0 +1,15 @@ +smeem: + secret: + key: ${SMEEM_SECRET_KEY} + duration: + remind: ${SMEEM_DURATION_REMIND} + client: + version: + title: ${CLIENT_VERSION_TITLE} + content: ${CLIENT_VERSION_CONTENT} + ios: + app: ${CLIENT_VERSION_IOS_APP} + force: ${CLIENT_VERSION_IOS_FORCE} + android: + app: ${CLIENT_VERSION_ANDROID_APP} + force: ${CLIENT_VERSION_ANDROID_FORCE} diff --git a/smeem-bootstrap/src/main/resources/application-dev.yml b/smeem-bootstrap/src/main/resources/application-dev.yml index 96e46d39..76834bf1 100644 --- a/smeem-bootstrap/src/main/resources/application-dev.yml +++ b/smeem-bootstrap/src/main/resources/application-dev.yml @@ -2,67 +2,11 @@ spring: config: activate: on-profile: dev - datasource: - driver-class-name: org.postgresql.Driver - url: jdbc:postgresql://${DB_URL}:5432/postgres?currentSchema=${DB_NAME} - username: ${DB_USERNAME} - password: ${DB_PASSWORD} - jpa: - hibernate: - ddl-auto: none - properties: - hibernate: - format_sql: true - default_batch_fetch_size: 1000 - auto_quote_keyword: true - show-sql: true + import: + - classpath:postgres-config/application-dev.yml + - classpath:smeem-config/application-dev.yml + - classpath:notification-config/application-dev.yml + - classpath:common-config/application-dev.yml logging.level: org.hibernate.SQL: debug - -### smeem -smeem: - secret: - key: ${SMEEM_SECRET_KEY} - duration: - expired: ${SMEEM_DURATION_EXPIRED} - remind: ${SMEEM_DURATION_REMIND} - client: - version: - title: "업데이트 알림" - content: "보다 나아진 스밈의 최신 버전을 준비했어요! 새로운 버전으로 업데이트 후 이용해주세요." - ios: - app: 2.0.3 - force: 3.0.0 - android: - app: 2.0.0 - force: 2.0.0 - notification: - title: "오늘의 영어 훈련, 딱 5분 걸려요!" - body: "지금 눌러서 일기 쓰기 ✍️" - cron_expression: "-" - -### auth -jwt: - ACCESS_TOKEN_EXPIRED: 7200000 - REFRESH_TOKEN_EXPIRED: 1209600000 - -### oauth -oauth: - url: - apple: https://appleid.apple.com/auth/keys - kakao: https://kapi.kakao.com/v2/user/me - -### notice -discord: - webhook: - url: - sign-in: ${DISCORD_WEBHOOK_SIGN_IN_URL} - withdraw: ${DISCORD_WEBHOOK_WITHDRAW_URL} - error: ${DISCORD_WEBHOOK_ERROR_URL} - -### notification -fcm: - file_path: firebase-config/smeem_fcm_dev.json - project_id: ${FCM_PROJECT_ID} -# google_api: https://www.googleapis.com/auth/cloud-platform diff --git a/smeem-bootstrap/src/main/resources/application-local.yml b/smeem-bootstrap/src/main/resources/application-local.yml index f40f23f0..d85a1e7b 100644 --- a/smeem-bootstrap/src/main/resources/application-local.yml +++ b/smeem-bootstrap/src/main/resources/application-local.yml @@ -2,67 +2,11 @@ spring: config: activate: on-profile: local - datasource: - driver-class-name: org.postgresql.Driver - url: jdbc:postgresql://${DB_URL}:5432/postgres?currentSchema=${DB_NAME} - username: ${DB_USERNAME} - password: ${DB_PASSWORD} - jpa: - hibernate: - ddl-auto: none - properties: - hibernate: - format_sql: true - default_batch_fetch_size: 1000 - auto_quote_keyword: true - show-sql: true + import: + - classpath:postgres-config/application-local.yml + - classpath:smeem-config/application-local.yml + - classpath:notification-config/application-local.yml + - classpath:common-config/application-local.yml logging.level: org.hibernate.SQL: debug - -### smeem -smeem: - secret: - key: ${SMEEM_SECRET_KEY} - duration: - expired: ${SMEEM_DURATION_EXPIRED} - remind: ${SMEEM_DURATION_REMIND} - client: - version: - title: "업데이트 알림" - content: "보다 나아진 스밈의 최신 버전을 준비했어요! 새로운 버전으로 업데이트 후 이용해주세요." - ios: - app: 2.0.2 - force: 3.0.0 - android: - app: 2.0.0 - force: 2.0.0 - notification: - title: "오늘의 영어 훈련, 딱 5분 걸려요!" - body: "지금 눌러서 일기 쓰기 ✍️" - cron_expression: "-" - -### auth -jwt: - ACCESS_TOKEN_EXPIRED: 7200000 - REFRESH_TOKEN_EXPIRED: 1209600000 - -### oauth -oauth: - url: - apple: https://appleid.apple.com/auth/keys - kakao: https://kapi.kakao.com/v2/user/me - -### notice -discord: - webhook: - url: - sign-in: ${DISCORD_WEBHOOK_SIGN_IN_URL} - withdraw: ${DISCORD_WEBHOOK_WITHDRAW_URL} - error: ${DISCORD_WEBHOOK_ERROR_URL} - -### notification -fcm: - file_path: firebase-config/smeem_fcm_dev.json - project_id: ${FCM_PROJECT_ID} -# google_api: https://www.googleapis.com/auth/cloud-platform diff --git a/smeem-bootstrap/src/main/resources/application-prod.yml b/smeem-bootstrap/src/main/resources/application-prod.yml index 11ca8164..6a718839 100644 --- a/smeem-bootstrap/src/main/resources/application-prod.yml +++ b/smeem-bootstrap/src/main/resources/application-prod.yml @@ -2,67 +2,11 @@ spring: config: activate: on-profile: prod - datasource: - driver-class-name: org.postgresql.Driver - url: jdbc:postgresql://${DB_URL}:5432/postgres?currentSchema=${DB_NAME} - username: ${DB_USERNAME} - password: ${DB_PASSWORD} - jpa: - hibernate: - ddl-auto: none - properties: - hibernate: - format_sql: true - default_batch_fetch_size: 1000 - auto_quote_keyword: true - show-sql: true + import: + - classpath:postgres-config/application-prod.yml + - classpath:smeem-config/application-prod.yml + - classpath:notification-config/application-prod.yml + - classpath:common-config/application-prod.yml logging.level: org.hibernate.SQL: debug - -### smeem -smeem: - secret: - key: ${SMEEM_SECRET_KEY} - duration: - expired: ${SMEEM_DURATION_EXPIRED} - remind: ${SMEEM_DURATION_REMIND} - client: - version: - title: "업데이트 알림" - content: "보다 나아진 스밈의 최신 버전을 준비했어요! 새로운 버전으로 업데이트 후 이용해주세요." - ios: - app: 2.0.2 - force: 2.0.0 - android: - app: 2.0.0 - force: 2.0.0 - notification: - title: "오늘의 영어 훈련, 딱 5분 걸려요!" - body: "지금 눌러서 일기 쓰기 ✍️" - cron_expression: "0 0/30 * * * *" - -### auth -jwt: - ACCESS_TOKEN_EXPIRED: 7200000 - REFRESH_TOKEN_EXPIRED: 1209600000 - -### oauth -oauth: - url: - apple: https://appleid.apple.com/auth/keys - kakao: https://kapi.kakao.com/v2/user/me - -### notice -discord: - webhook: - url: - sign-in: ${DISCORD_WEBHOOK_SIGN_IN_URL} - withdraw: ${DISCORD_WEBHOOK_WITHDRAW_URL} - error: ${DISCORD_WEBHOOK_ERROR_URL} - -### notification -fcm: - file_path: firebase-config/smeem_fcm_prod.json - project_id: ${FCM_PROJECT_ID} -# google_api: https://www.googleapis.com/auth/cloud-platform diff --git a/smeem-common/src/main/resources/common-config/application-dev.yml b/smeem-common/src/main/resources/common-config/application-dev.yml new file mode 100644 index 00000000..1c02ed47 --- /dev/null +++ b/smeem-common/src/main/resources/common-config/application-dev.yml @@ -0,0 +1,6 @@ +discord: + webhook: + url: + sign_in: ${DISCORD_WEBHOOK_SIGN_IN_URL} + withdraw: ${DISCORD_WEBHOOK_WITHDRAW_URL} + error: ${DISCORD_WEBHOOK_ERROR_URL} diff --git a/smeem-common/src/main/resources/common-config/application-local.yml b/smeem-common/src/main/resources/common-config/application-local.yml new file mode 100644 index 00000000..1c02ed47 --- /dev/null +++ b/smeem-common/src/main/resources/common-config/application-local.yml @@ -0,0 +1,6 @@ +discord: + webhook: + url: + sign_in: ${DISCORD_WEBHOOK_SIGN_IN_URL} + withdraw: ${DISCORD_WEBHOOK_WITHDRAW_URL} + error: ${DISCORD_WEBHOOK_ERROR_URL} diff --git a/smeem-common/src/main/resources/common-config/application-prod.yml b/smeem-common/src/main/resources/common-config/application-prod.yml new file mode 100644 index 00000000..1c02ed47 --- /dev/null +++ b/smeem-common/src/main/resources/common-config/application-prod.yml @@ -0,0 +1,6 @@ +discord: + webhook: + url: + sign_in: ${DISCORD_WEBHOOK_SIGN_IN_URL} + withdraw: ${DISCORD_WEBHOOK_WITHDRAW_URL} + error: ${DISCORD_WEBHOOK_ERROR_URL} diff --git a/smeem-output-notification/firebase/src/main/resources/notification-config/application-dev.yml b/smeem-output-notification/firebase/src/main/resources/notification-config/application-dev.yml new file mode 100644 index 00000000..78a28b29 --- /dev/null +++ b/smeem-output-notification/firebase/src/main/resources/notification-config/application-dev.yml @@ -0,0 +1,6 @@ +notification: + title: ${NOTIFICATION_TITLE} + body: ${NOTIFICATION_BODY} + fcm: + file_path: firebase-config/smeem_fcm_dev.json + project_id: ${FCM_PROJECT_ID} diff --git a/smeem-output-notification/firebase/src/main/resources/notification-config/application-local.yml b/smeem-output-notification/firebase/src/main/resources/notification-config/application-local.yml new file mode 100644 index 00000000..78a28b29 --- /dev/null +++ b/smeem-output-notification/firebase/src/main/resources/notification-config/application-local.yml @@ -0,0 +1,6 @@ +notification: + title: ${NOTIFICATION_TITLE} + body: ${NOTIFICATION_BODY} + fcm: + file_path: firebase-config/smeem_fcm_dev.json + project_id: ${FCM_PROJECT_ID} diff --git a/smeem-output-notification/firebase/src/main/resources/notification-config/application-prod.yml b/smeem-output-notification/firebase/src/main/resources/notification-config/application-prod.yml new file mode 100644 index 00000000..60f08bf4 --- /dev/null +++ b/smeem-output-notification/firebase/src/main/resources/notification-config/application-prod.yml @@ -0,0 +1,6 @@ +notification: + title: ${NOTIFICATION_TITLE} + body: ${NOTIFICATION_BODY} + fcm: + file_path: firebase-config/smeem_fcm_prod.json + project_id: ${FCM_PROJECT_ID} diff --git a/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-dev.yml b/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-dev.yml new file mode 100644 index 00000000..c438bec7 --- /dev/null +++ b/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-dev.yml @@ -0,0 +1,19 @@ +spring: + config: + activate: + on-profile: dev + + datasource: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://${DB_URL}:5432/postgres?currentSchema=${DB_NAME} + username: ${DB_USERNAME} + password: ${DB_PASSWORD} + jpa: + hibernate: + ddl-auto: validate + properties: + hibernate: + format_sql: true + default_batch_fetch_size: 1000 + auto_quote_keyword: true + show-sql: true diff --git a/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-local.yml b/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-local.yml new file mode 100644 index 00000000..77e42305 --- /dev/null +++ b/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-local.yml @@ -0,0 +1,19 @@ +spring: + config: + activate: + on-profile: local + + datasource: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://${DB_URL}:5432/postgres?currentSchema=${DB_NAME} + username: ${DB_USERNAME} + password: ${DB_PASSWORD} + jpa: + hibernate: + ddl-auto: validate + properties: + hibernate: + format_sql: true + default_batch_fetch_size: 1000 + auto_quote_keyword: true + show-sql: true diff --git a/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-prod.yml b/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-prod.yml new file mode 100644 index 00000000..f9148cb4 --- /dev/null +++ b/smeem-output-persistence/postgresql/src/main/resources/postgres-config/application-prod.yml @@ -0,0 +1,19 @@ +spring: + config: + activate: + on-profile: prod + + datasource: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://${DB_URL}:5432/postgres?currentSchema=${DB_NAME} + username: ${DB_USERNAME} + password: ${DB_PASSWORD} + jpa: + hibernate: + ddl-auto: validate + properties: + hibernate: + format_sql: true + default_batch_fetch_size: 1000 + auto_quote_keyword: true + show-sql: true From a018af95a0552f6f86ec6a3d34be0dc40f1fe91a Mon Sep 17 00:00:00 2001 From: thguss Date: Mon, 9 Sep 2024 23:32:00 +0900 Subject: [PATCH 4/7] add: added properties --- .../smeem/application/config/SmeemConfig.java | 9 +++ .../application/config/SmeemProperties.java | 61 +++++++++++++++++++ .../smeem/common/config/DiscordConfig.java | 9 +++ .../common/config/DiscordProperties.java | 21 +++++++ .../firebase/config/FcmConfig.java | 12 ++-- .../firebase/config/FcmProperties.java | 17 ++++++ .../smeem/oauth/apple/config/AppleConfig.java | 9 +++ .../oauth/apple/config/AppleProperties.java | 9 +++ .../smeem/oauth/kakao/config/KakaoConfig.java | 9 +++ .../oauth/kakao/config/KakaoProperties.java | 9 +++ 10 files changed, 158 insertions(+), 7 deletions(-) create mode 100644 smeem-application/src/main/java/com/smeem/application/config/SmeemConfig.java create mode 100644 smeem-application/src/main/java/com/smeem/application/config/SmeemProperties.java create mode 100644 smeem-common/src/main/java/com/smeem/common/config/DiscordConfig.java create mode 100644 smeem-common/src/main/java/com/smeem/common/config/DiscordProperties.java create mode 100644 smeem-output-notification/firebase/src/main/java/com/smeem/notification/firebase/config/FcmProperties.java create mode 100644 smeem-output-oauth/apple/src/main/java/com/smeem/oauth/apple/config/AppleConfig.java create mode 100644 smeem-output-oauth/apple/src/main/java/com/smeem/oauth/apple/config/AppleProperties.java create mode 100644 smeem-output-oauth/kakao/src/main/java/com/smeem/oauth/kakao/config/KakaoConfig.java create mode 100644 smeem-output-oauth/kakao/src/main/java/com/smeem/oauth/kakao/config/KakaoProperties.java diff --git a/smeem-application/src/main/java/com/smeem/application/config/SmeemConfig.java b/smeem-application/src/main/java/com/smeem/application/config/SmeemConfig.java new file mode 100644 index 00000000..874dc561 --- /dev/null +++ b/smeem-application/src/main/java/com/smeem/application/config/SmeemConfig.java @@ -0,0 +1,9 @@ +package com.smeem.application.config; + +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableConfigurationProperties(SmeemProperties.class) +public class SmeemConfig { +} diff --git a/smeem-application/src/main/java/com/smeem/application/config/SmeemProperties.java b/smeem-application/src/main/java/com/smeem/application/config/SmeemProperties.java new file mode 100644 index 00000000..992990b4 --- /dev/null +++ b/smeem-application/src/main/java/com/smeem/application/config/SmeemProperties.java @@ -0,0 +1,61 @@ +package com.smeem.application.config; + +import jakarta.annotation.PostConstruct; +import lombok.Getter; +import org.springframework.boot.context.properties.ConfigurationProperties; + +import java.nio.charset.StandardCharsets; +import java.util.Base64; + +@Getter +@ConfigurationProperties(prefix = "smeem") +public class SmeemProperties { + private final Secret secret; + private final Duration duration; + private final Client client; + + public SmeemProperties(Secret secret, Duration duration, Client client) { + this.secret = secret; + this.duration = duration; + this.client = client; + } + + @Getter + public static class Secret { + private String key; + + public Secret(String key) { + this.key = key; + } + + @PostConstruct + private void init() { + this.key = Base64.getEncoder().encodeToString(key.getBytes(StandardCharsets.UTF_8)); + } + } + + public record Duration( + int remind, + int expired + ) { + } + + public record Client( + Version version + ) { + + public record Version( + String title, + String content, + APP ios, + APP android + ) { + + public record APP( + String app, + String force + ) { + } + } + } +} diff --git a/smeem-common/src/main/java/com/smeem/common/config/DiscordConfig.java b/smeem-common/src/main/java/com/smeem/common/config/DiscordConfig.java new file mode 100644 index 00000000..d513894f --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/config/DiscordConfig.java @@ -0,0 +1,9 @@ +package com.smeem.common.config; + +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableConfigurationProperties(DiscordProperties.class) +public class DiscordConfig { +} diff --git a/smeem-common/src/main/java/com/smeem/common/config/DiscordProperties.java b/smeem-common/src/main/java/com/smeem/common/config/DiscordProperties.java new file mode 100644 index 00000000..ab3b1154 --- /dev/null +++ b/smeem-common/src/main/java/com/smeem/common/config/DiscordProperties.java @@ -0,0 +1,21 @@ +package com.smeem.common.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "discord") +public record DiscordProperties( + Webhook webhook +) { + + public record Webhook( + Url url + ) { + + public record Url( + String sign_in, + String withdraw, + String error + ) { + } + } +} diff --git a/smeem-output-notification/firebase/src/main/java/com/smeem/notification/firebase/config/FcmConfig.java b/smeem-output-notification/firebase/src/main/java/com/smeem/notification/firebase/config/FcmConfig.java index 7080fc9f..050b5e50 100644 --- a/smeem-output-notification/firebase/src/main/java/com/smeem/notification/firebase/config/FcmConfig.java +++ b/smeem-output-notification/firebase/src/main/java/com/smeem/notification/firebase/config/FcmConfig.java @@ -4,7 +4,7 @@ import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; import com.google.firebase.messaging.FirebaseMessaging; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; @@ -15,16 +15,14 @@ import lombok.*; @Configuration +@EnableConfigurationProperties(FcmProperties.class) public class FcmConfig { private final ClassPathResource firebaseResource; private final String projectId; - public FcmConfig( - @Value("${fcm.file_path}") String firebaseFilePath, - @Value("${fcm.project_id}") String projectId - ) { - this.firebaseResource = new ClassPathResource(firebaseFilePath); - this.projectId = projectId; + public FcmConfig(FcmProperties fcmProperties) { + this.firebaseResource = new ClassPathResource(fcmProperties.fcm().file_path()); + this.projectId = fcmProperties.fcm().project_id(); } @PostConstruct diff --git a/smeem-output-notification/firebase/src/main/java/com/smeem/notification/firebase/config/FcmProperties.java b/smeem-output-notification/firebase/src/main/java/com/smeem/notification/firebase/config/FcmProperties.java new file mode 100644 index 00000000..f9935128 --- /dev/null +++ b/smeem-output-notification/firebase/src/main/java/com/smeem/notification/firebase/config/FcmProperties.java @@ -0,0 +1,17 @@ +package com.smeem.notification.firebase.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "notification") +public record FcmProperties( + String title, + String body, + Fcm fcm +) { + + public record Fcm( + String file_path, + String project_id + ) { + } +} diff --git a/smeem-output-oauth/apple/src/main/java/com/smeem/oauth/apple/config/AppleConfig.java b/smeem-output-oauth/apple/src/main/java/com/smeem/oauth/apple/config/AppleConfig.java new file mode 100644 index 00000000..4dd30568 --- /dev/null +++ b/smeem-output-oauth/apple/src/main/java/com/smeem/oauth/apple/config/AppleConfig.java @@ -0,0 +1,9 @@ +package com.smeem.oauth.apple.config; + +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableConfigurationProperties(AppleProperties.class) +public class AppleConfig { +} diff --git a/smeem-output-oauth/apple/src/main/java/com/smeem/oauth/apple/config/AppleProperties.java b/smeem-output-oauth/apple/src/main/java/com/smeem/oauth/apple/config/AppleProperties.java new file mode 100644 index 00000000..93adf21a --- /dev/null +++ b/smeem-output-oauth/apple/src/main/java/com/smeem/oauth/apple/config/AppleProperties.java @@ -0,0 +1,9 @@ +package com.smeem.oauth.apple.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "apple") +public record AppleProperties( + String url +) { +} diff --git a/smeem-output-oauth/kakao/src/main/java/com/smeem/oauth/kakao/config/KakaoConfig.java b/smeem-output-oauth/kakao/src/main/java/com/smeem/oauth/kakao/config/KakaoConfig.java new file mode 100644 index 00000000..f4af9534 --- /dev/null +++ b/smeem-output-oauth/kakao/src/main/java/com/smeem/oauth/kakao/config/KakaoConfig.java @@ -0,0 +1,9 @@ +package com.smeem.oauth.kakao.config; + +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableConfigurationProperties(KakaoProperties.class) +public class KakaoConfig { +} diff --git a/smeem-output-oauth/kakao/src/main/java/com/smeem/oauth/kakao/config/KakaoProperties.java b/smeem-output-oauth/kakao/src/main/java/com/smeem/oauth/kakao/config/KakaoProperties.java new file mode 100644 index 00000000..7ac64af6 --- /dev/null +++ b/smeem-output-oauth/kakao/src/main/java/com/smeem/oauth/kakao/config/KakaoProperties.java @@ -0,0 +1,9 @@ +package com.smeem.oauth.kakao.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "kakao") +public record KakaoProperties( + String url +) { +} From ff9bb9817c765d64c8dc7ce1bc255bb8ee67f27e Mon Sep 17 00:00:00 2001 From: thguss Date: Mon, 9 Sep 2024 23:32:41 +0900 Subject: [PATCH 5/7] delete: deleted unused class --- .../application/domain/version/Property.java | 22 ------------- .../logger/discord/DiscordHookLink.java | 21 ------------ .../com/smeem/common/util/SmeemProperty.java | 33 ------------------- 3 files changed, 76 deletions(-) delete mode 100644 smeem-application/src/main/java/com/smeem/application/domain/version/Property.java delete mode 100644 smeem-common/src/main/java/com/smeem/common/logger/discord/DiscordHookLink.java delete mode 100644 smeem-common/src/main/java/com/smeem/common/util/SmeemProperty.java diff --git a/smeem-application/src/main/java/com/smeem/application/domain/version/Property.java b/smeem-application/src/main/java/com/smeem/application/domain/version/Property.java deleted file mode 100644 index af671990..00000000 --- a/smeem-application/src/main/java/com/smeem/application/domain/version/Property.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.smeem.application.domain.version; - -import lombok.Getter; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -@Getter -public class Property { - @Value("${smeem.client.version.title}") - private String CLIENT_VERSION_UPDATE_TITLE; - @Value("${smeem.client.version.content}") - private String CLIENT_VERSION_UPDATE_CONTENT; - @Value("${smeem.client.version.ios.app}") - private String CLIENT_VERSION_IOS_VERSION; - @Value("${smeem.client.version.ios.force}") - private String CLIENT_VERSION_IOS_FORCE_VERSION; - @Value("${smeem.client.version.android.app}") - private String CLIENT_VERSION_ANDROID_VERSION; - @Value("${smeem.client.version.android.force}") - private String CLIENT_VERSION_ANDROID_FORCE_VERSION; -} diff --git a/smeem-common/src/main/java/com/smeem/common/logger/discord/DiscordHookLink.java b/smeem-common/src/main/java/com/smeem/common/logger/discord/DiscordHookLink.java deleted file mode 100644 index 86bb8223..00000000 --- a/smeem-common/src/main/java/com/smeem/common/logger/discord/DiscordHookLink.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.smeem.common.logger.discord; - -import lombok.Getter; -import org.springframework.beans.factory.annotation.Value; - -@Getter -public class DiscordHookLink { - public final String signInUrl; - public final String withdrawUrl; - public final String errorUrl; - - DiscordHookLink( - @Value("${discord.webhook.url.sign-in}") String signInUrl, - @Value("${discord.webhook.url.withdraw}") String withdrawUrl, - @Value("${discord.webhook.url.error}") String errorUrl - ) { - this.signInUrl = signInUrl; - this.withdrawUrl = withdrawUrl; - this.errorUrl = errorUrl; - } -} diff --git a/smeem-common/src/main/java/com/smeem/common/util/SmeemProperty.java b/smeem-common/src/main/java/com/smeem/common/util/SmeemProperty.java deleted file mode 100644 index f5827332..00000000 --- a/smeem-common/src/main/java/com/smeem/common/util/SmeemProperty.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.smeem.common.util; - -import jakarta.annotation.PostConstruct; -import lombok.Getter; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -import java.nio.charset.StandardCharsets; -import java.util.Base64; - -@Component -@Getter -public class SmeemProperty { - /** - * http - */ - @Value("${smeem.secret.key}") - private String SMEEM_SECRET_KEY; - - /** - * oauth-module - */ - @Value("${oauth.url.apple}") - private String APPLE_URL; - - @Value("${oauth.url.kakao}") - private String KAKAO_URL; - - @PostConstruct - protected void init() { - SMEEM_SECRET_KEY = Base64.getEncoder().encodeToString(SMEEM_SECRET_KEY.getBytes(StandardCharsets.UTF_8)); - } -} From 38bb61012b7dff484ae468b68bc6f60b0753ad5e Mon Sep 17 00:00:00 2001 From: thguss Date: Mon, 9 Sep 2024 23:33:34 +0900 Subject: [PATCH 6/7] fix: updated property --- .../domain/auth/SecretKeyFactory.java | 9 +++---- .../domain/diary/DiaryService.java | 5 +++- .../domain/version/VersionService.java | 15 +++++------ .../smeem/batch/scheduler/DiaryScheduler.java | 10 ++++---- .../scheduler/NotificationScheduler.java | 2 +- .../logger/discord/DiscordHookLogger.java | 25 ++++++------------- .../notification/NotificationAdapter.java | 12 +++------ .../smeem/oauth/apple/AppleOauthService.java | 6 ++--- .../smeem/oauth/kakao/KakaoOauthService.java | 6 ++--- 9 files changed, 40 insertions(+), 50 deletions(-) diff --git a/smeem-application/src/main/java/com/smeem/application/domain/auth/SecretKeyFactory.java b/smeem-application/src/main/java/com/smeem/application/domain/auth/SecretKeyFactory.java index a9c55a4a..7c4c9c53 100644 --- a/smeem-application/src/main/java/com/smeem/application/domain/auth/SecretKeyFactory.java +++ b/smeem-application/src/main/java/com/smeem/application/domain/auth/SecretKeyFactory.java @@ -1,22 +1,21 @@ package com.smeem.application.domain.auth; -import com.smeem.common.util.SmeemProperty; +import com.smeem.application.config.SmeemProperties; import io.jsonwebtoken.security.Keys; import lombok.RequiredArgsConstructor; import lombok.val; import org.springframework.stereotype.Component; import javax.crypto.SecretKey; - -import static java.util.Base64.getEncoder; +import java.util.Base64; @Component @RequiredArgsConstructor public class SecretKeyFactory { - private final SmeemProperty smeemProperty; + private final SmeemProperties smeemProperties; public SecretKey create() { - val encodedKey = getEncoder().encodeToString(smeemProperty.getSMEEM_SECRET_KEY().getBytes()); + val encodedKey = Base64.getEncoder().encodeToString(smeemProperties.getSecret().getKey().getBytes()); return Keys.hmacShaKeyFor(encodedKey.getBytes()); } } diff --git a/smeem-application/src/main/java/com/smeem/application/domain/diary/DiaryService.java b/smeem-application/src/main/java/com/smeem/application/domain/diary/DiaryService.java index d6812e09..e59340d2 100644 --- a/smeem-application/src/main/java/com/smeem/application/domain/diary/DiaryService.java +++ b/smeem-application/src/main/java/com/smeem/application/domain/diary/DiaryService.java @@ -1,5 +1,6 @@ package com.smeem.application.domain.diary; +import com.smeem.application.config.SmeemProperties; import com.smeem.application.domain.badge.Badge; import com.smeem.application.domain.badge.BadgeType; import com.smeem.application.domain.member.Member; @@ -27,6 +28,7 @@ public class DiaryService implements DiaryUseCase { private final BadgePort badgePort; private final MemberBadgePort memberBadgePort; private final TopicPort topicPort; + private final SmeemProperties smeemProperties; @Transactional public WriteDiaryResponse writeDiary(long memberId, WriteDiaryRequest request) { @@ -73,9 +75,10 @@ public void deleteDiary(long diary) { } public RetrieveDiariesResponse retrieveDiariesByTerm(long memberId, LocalDate startDate, LocalDate endDate) { + val remindDuration = smeemProperties.getDuration().remind(); return RetrieveDiariesResponse.of( diaryPort.findByMemberAndTerm(memberId, startDate, endDate), - diaryPort.isExistByMemberAndPastAgo(memberId, 30)); + diaryPort.isExistByMemberAndPastAgo(memberId, remindDuration)); } @Transactional diff --git a/smeem-application/src/main/java/com/smeem/application/domain/version/VersionService.java b/smeem-application/src/main/java/com/smeem/application/domain/version/VersionService.java index 945c99a0..adfe0920 100644 --- a/smeem-application/src/main/java/com/smeem/application/domain/version/VersionService.java +++ b/smeem-application/src/main/java/com/smeem/application/domain/version/VersionService.java @@ -1,5 +1,6 @@ package com.smeem.application.domain.version; +import com.smeem.application.config.SmeemProperties; import com.smeem.application.port.input.VersionUseCase; import com.smeem.application.port.input.dto.response.version.RetrieveAppVersionResponse; import lombok.RequiredArgsConstructor; @@ -10,16 +11,16 @@ @RequiredArgsConstructor @Transactional(readOnly = true) public class VersionService implements VersionUseCase { - private final Property property; + private final SmeemProperties smeemProperties; @Override public RetrieveAppVersionResponse retrieveAppVersion() { return RetrieveAppVersionResponse.of( - property.getCLIENT_VERSION_UPDATE_TITLE(), - property.getCLIENT_VERSION_UPDATE_CONTENT(), - property.getCLIENT_VERSION_ANDROID_VERSION(), - property.getCLIENT_VERSION_ANDROID_FORCE_VERSION(), - property.getCLIENT_VERSION_IOS_VERSION(), - property.getCLIENT_VERSION_IOS_FORCE_VERSION()); + smeemProperties.getClient().version().title(), + smeemProperties.getClient().version().content(), + smeemProperties.getClient().version().android().app(), + smeemProperties.getClient().version().android().force(), + smeemProperties.getClient().version().ios().app(), + smeemProperties.getClient().version().ios().force()); } } diff --git a/smeem-batch/src/main/java/com/smeem/batch/scheduler/DiaryScheduler.java b/smeem-batch/src/main/java/com/smeem/batch/scheduler/DiaryScheduler.java index 45a0319d..03850820 100644 --- a/smeem-batch/src/main/java/com/smeem/batch/scheduler/DiaryScheduler.java +++ b/smeem-batch/src/main/java/com/smeem/batch/scheduler/DiaryScheduler.java @@ -1,8 +1,9 @@ package com.smeem.batch.scheduler; +import com.smeem.application.config.SmeemProperties; import com.smeem.application.port.input.DiaryUseCase; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; +import lombok.val; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -10,12 +11,11 @@ @RequiredArgsConstructor public class DiaryScheduler { private final DiaryUseCase diaryUseCase; - - @Value("${smeem.duration.expired}") - private int DURATION_EXPIRED; + private final SmeemProperties smeemProperties; @Scheduled(cron = "0 0 0 * * *") public void deleteExpiredDiaries() { - diaryUseCase.deleteExpiredDiaries(DURATION_EXPIRED); + val expiredDuration = smeemProperties.getDuration().expired(); + diaryUseCase.deleteExpiredDiaries(expiredDuration); } } diff --git a/smeem-batch/src/main/java/com/smeem/batch/scheduler/NotificationScheduler.java b/smeem-batch/src/main/java/com/smeem/batch/scheduler/NotificationScheduler.java index e08055ff..8df40fee 100644 --- a/smeem-batch/src/main/java/com/smeem/batch/scheduler/NotificationScheduler.java +++ b/smeem-batch/src/main/java/com/smeem/batch/scheduler/NotificationScheduler.java @@ -16,7 +16,7 @@ public class NotificationScheduler { private final MemberPort memberPort; private final NotificationPort notificationPort; - @Scheduled(cron = "${smeem.notification.cron_expression}") + @Scheduled(cron = "0 0/30 * * * *") public void pushAlarmByTrainingTime() throws InterruptedException { Thread.sleep(1000); val members = memberPort.findByTrainingTime(LocalDateTime.now()); diff --git a/smeem-common/src/main/java/com/smeem/common/logger/discord/DiscordHookLogger.java b/smeem-common/src/main/java/com/smeem/common/logger/discord/DiscordHookLogger.java index 59a79eda..0d4e6209 100644 --- a/smeem-common/src/main/java/com/smeem/common/logger/discord/DiscordHookLogger.java +++ b/smeem-common/src/main/java/com/smeem/common/logger/discord/DiscordHookLogger.java @@ -1,31 +1,22 @@ package com.smeem.common.logger.discord; +import com.smeem.common.config.DiscordProperties; import com.smeem.common.logger.HookLogger; import com.smeem.common.logger.LoggerType; import com.smeem.common.logger.LoggingMessage; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Component; import org.springframework.web.client.RestClient; @Component @Slf4j +@RequiredArgsConstructor public class DiscordHookLogger implements HookLogger { - private final String signInUrl; - private final String withdrawUrl; - private final String errorUrl; - private final static String APPLICATION_JSON_UTF8_VALUE = "application/json; UTF-8"; + private final DiscordProperties discordProperties; - DiscordHookLogger( - @Value("${discord.webhook.url.sign-in}") String signInUrl, - @Value("${discord.webhook.url.withdraw}") String withdrawUrl, - @Value("${discord.webhook.url.error}") String errorUrl - ) { - this.signInUrl = signInUrl; - this.withdrawUrl = withdrawUrl; - this.errorUrl = errorUrl; - } + private final static String APPLICATION_JSON_UTF8_VALUE = "application/json; UTF-8"; @Override public void send(LoggingMessage loggingMessage) { @@ -44,9 +35,9 @@ public void send(LoggingMessage loggingMessage) { private String getWebhookUrl(LoggerType loggerType) { return switch (loggerType) { - case SIGN_IN -> signInUrl; - case WITHDRAW -> withdrawUrl; - case ERROR -> errorUrl; + case SIGN_IN -> discordProperties.webhook().url().sign_in(); + case WITHDRAW -> discordProperties.webhook().url().withdraw(); + case ERROR -> discordProperties.webhook().url().error(); }; } } diff --git a/smeem-output-notification/src/main/java/com/smeem/notification/NotificationAdapter.java b/smeem-output-notification/src/main/java/com/smeem/notification/NotificationAdapter.java index ebc81d05..07f37ee4 100644 --- a/smeem-output-notification/src/main/java/com/smeem/notification/NotificationAdapter.java +++ b/smeem-output-notification/src/main/java/com/smeem/notification/NotificationAdapter.java @@ -3,11 +3,11 @@ import com.smeem.application.port.output.notification.NotificationPort; import com.smeem.application.port.output.persistence.MemberPort; import com.smeem.notification.firebase.FcmNotificationService; +import com.smeem.notification.firebase.config.FcmProperties; import com.smeem.notification.firebase.dto.request.NotificationMulticastRequest; import com.smeem.notification.firebase.dto.request.NotificationSingleRequest; import lombok.RequiredArgsConstructor; import lombok.val; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.util.List; @@ -17,11 +17,7 @@ public class NotificationAdapter implements NotificationPort { private final FcmNotificationService notificationService; private final MemberPort memberPort; - - @Value("${smeem.notification.title}") - private String NOTIFICATION_TITLE; - @Value("${smeem.notification.body}") - private String NOTIFICATION_BODY; + private final FcmProperties fcmProperties; @Override public void test(long memberId) { @@ -36,7 +32,7 @@ public void test(long memberId) { public void sendNotificationForTrainingTime(List fcmTokens) { notificationService.sendMessages(NotificationMulticastRequest.of( fcmTokens, - NOTIFICATION_TITLE, - NOTIFICATION_BODY)); + fcmProperties.title(), + fcmProperties.body())); } } diff --git a/smeem-output-oauth/apple/src/main/java/com/smeem/oauth/apple/AppleOauthService.java b/smeem-output-oauth/apple/src/main/java/com/smeem/oauth/apple/AppleOauthService.java index f5d37db0..cf700041 100644 --- a/smeem-output-oauth/apple/src/main/java/com/smeem/oauth/apple/AppleOauthService.java +++ b/smeem-output-oauth/apple/src/main/java/com/smeem/oauth/apple/AppleOauthService.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.smeem.common.exception.ExceptionCode; import com.smeem.common.exception.SmeemException; -import com.smeem.common.util.SmeemProperty; +import com.smeem.oauth.apple.config.AppleProperties; import com.smeem.oauth.apple.dto.response.AppleKey; import com.smeem.oauth.apple.dto.response.AppleKeysResponse; import com.smeem.oauth.apple.dto.response.DecodedAppleKey; @@ -29,7 +29,7 @@ @RequiredArgsConstructor public class AppleOauthService { private final ObjectMapper objectMapper; - private final SmeemProperty smeemProperty; + private final AppleProperties appleProperties; public String getAppleData(String appleAccessToken) { val publicAppleKeys = getApplePublicKeys(); @@ -51,7 +51,7 @@ private AppleKeysResponse getApplePublicKeys() { try { val restClient = RestClient.create(); return restClient.get() - .uri(smeemProperty.getAPPLE_URL()) + .uri(appleProperties.url()) .retrieve() .onStatus(HttpStatusCode::is4xxClientError, (appleRequest, appleResponse) -> { throw new SmeemException(ExceptionCode.SERVICE_AVAILABLE); diff --git a/smeem-output-oauth/kakao/src/main/java/com/smeem/oauth/kakao/KakaoOauthService.java b/smeem-output-oauth/kakao/src/main/java/com/smeem/oauth/kakao/KakaoOauthService.java index 642fd17e..3eee8c1b 100644 --- a/smeem-output-oauth/kakao/src/main/java/com/smeem/oauth/kakao/KakaoOauthService.java +++ b/smeem-output-oauth/kakao/src/main/java/com/smeem/oauth/kakao/KakaoOauthService.java @@ -2,7 +2,7 @@ import com.smeem.common.exception.ExceptionCode; import com.smeem.common.exception.SmeemException; -import com.smeem.common.util.SmeemProperty; +import com.smeem.oauth.kakao.config.KakaoProperties; import com.smeem.oauth.kakao.dto.KakaoResponse; import lombok.RequiredArgsConstructor; import lombok.val; @@ -15,13 +15,13 @@ @Service @RequiredArgsConstructor public class KakaoOauthService { - private final SmeemProperty smeemProperty; + private final KakaoProperties kakaoProperties; public String getKakaoData(final String accessToken) { try { val restClient = RestClient.create(); val response = restClient.get() - .uri(smeemProperty.getKAKAO_URL()) + .uri(kakaoProperties.url()) .header(AUTHORIZATION, accessToken) .retrieve() .onStatus(HttpStatusCode::is4xxClientError, From 438fa16ecb2ac5d6cc408cc87815562947f24b2f Mon Sep 17 00:00:00 2001 From: thguss Date: Mon, 9 Sep 2024 23:40:26 +0900 Subject: [PATCH 7/7] add: added env value --- .github/workflows/deploy-dev.yml | 6 ++++++ .github/workflows/deploy-prod.yml | 6 ++++++ script/deploy.sh | 6 +++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index c14dd5aa..2401ceae 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -85,6 +85,12 @@ jobs: if ! grep -q "IMAGE_NAME=" .env; then echo "IMAGE_NAME=${{ secrets.IMAGE_NAME_DEV }}" >> .env fi + if ! grep -q "SECRET_MANAGER_TOKEN=" .env; then + echo "SECRET_MANAGER_TOKEN=${{ secrets.SECRET_MANAGER_TOKEN }}" >> .env + fi + if ! grep -q "SECRET_MANAGER_WORKSPACE_ID=" .env; then + echo "SECRET_MANAGER_WORKSPACE_ID=${{ secrets.SECRET_MANAGER_WORKSPACE_ID }}" >> .env + fi # 배포 스크립트 실행 sudo ./deploy.sh diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml index b21a60c2..17dfe276 100644 --- a/.github/workflows/deploy-prod.yml +++ b/.github/workflows/deploy-prod.yml @@ -85,6 +85,12 @@ jobs: if ! grep -q "IMAGE_NAME=" .env; then echo "IMAGE_NAME=${{ secrets.IMAGE_NAME_PROD }}" >> .env fi + if ! grep -q "SECRET_MANAGER_TOKEN=" .env; then + echo "SECRET_MANAGER_TOKEN=${{ secrets.SECRET_MANAGER_TOKEN }}" >> .env + fi + if ! grep -q "SECRET_MANAGER_WORKSPACE_ID=" .env; then + echo "SECRET_MANAGER_WORKSPACE_ID=${{ secrets.SECRET_MANAGER_WORKSPACE_ID }}" >> .env + fi # 배포 스크립트 실행 sudo ./deploy.sh diff --git a/script/deploy.sh b/script/deploy.sh index 28f409cf..67e08e52 100644 --- a/script/deploy.sh +++ b/script/deploy.sh @@ -3,6 +3,8 @@ source .env REGISTRY_URL=${REGISTRY_URL} IMAGE_NAME=${IMAGE_NAME} +SECRET_MANAGER_TOKEN=${SECRET_MANAGER_TOKEN} +SECRET_MANAGER_WORKSPACE_ID=${SECRET_MANAGER_WORKSPACE_ID} TAG="latest" CONTAINER_NAME="smeem" HEALTH_CHECK_URI="/actuator/health" @@ -17,7 +19,9 @@ if [ "$(sudo docker ps -a -q -f name=${CONTAINER_NAME})" ]; then fi echo "> Run docker" -sudo docker run -d --name ${CONTAINER_NAME} -p 80:8080 "${REGISTRY_URL}"/"${IMAGE_NAME}":${TAG} +sudo docker run -d --name ${CONTAINER_NAME} -p 80:8080 "${REGISTRY_URL}"/"${IMAGE_NAME}":${TAG} \ + -e SECRET_MANAGER_TOKEN="${SECRET_MANAGER_TOKEN}" \ + -e SECRET_MANAGER_WORKSPACE_ID="${SECRET_MANAGER_WORKSPACE_ID}" echo "----------------------------------------------------------------------"