Skip to content

Commit

Permalink
YEL-109 [deploy] staging 1.0.7 배포
Browse files Browse the repository at this point in the history
YEL-109 [deploy] staging 1.0.7 배포
  • Loading branch information
euije authored Aug 17, 2023
2 parents 0f57993 + 144239f commit 5546b8d
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
echo "$APPLICATION" > ./application.yml
touch ./firebase_key.json
echo "$FIREBASE_JSON" > ./firebase_key.json
touch ./google_client_secret.json
echo "$GOOGLE_CLIENT_SECRET" > ./google_client_secret.json
sed -i 's/#/"/g' ./firebase_key.json
env:
APPLICATION: ${{ secrets.APPLICATION }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
SLACK_CHANNEL: general
SLACK_COLOR: ${{ job.status }}
SLACK_ICON: https://github.com/rtCamp.png?size=48
SLACK_MESSAGE: 빌드에 ${{ job.status }} 했습니다.
SLACK_MESSAGE: 테스트에 ${{ job.status }} 했습니다.
SLACK_TITLE: 📊 YELL:O 테스트 결과 📊
SLACK_USERNAME: Notification-Bot
SLACK_WEBHOOK: ${{ secrets.SLACK_URL }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ application.yml
application-dev.yml
application-apple.yml
firebase*.json
*client_secret*.json

### monitoring ###
monitoring/prometheus/volume
Expand Down
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ dependencies {

// slack-webhook
implementation "net.gpedro.integrations.slack:slack-webhook:1.4.0"

// google play android developer api
implementation 'com.google.apis:google-api-services-androidpublisher:v3-rev20211125-1.32.1'
implementation "com.google.api-client:google-api-client:1.33.0"

// gson
implementation 'com.google.code.gson:gson:2.10.1'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public BaseResponse<VoteAvailableResponse> checkVoteAvailable(
@Operation(summary = "투표 생성 API", responses = {
@ApiResponse(
responseCode = "201",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = VoteAvailableResponse.class))),
content = @Content(mediaType = "application/json", schema = @Schema(implementation = VoteCreateResponse.class))),
})
@PostMapping
public BaseResponse<VoteCreateResponse> createVote(
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/yello/server/global/HealthCheckController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.yello.server.global;

import com.yello.server.global.common.util.ConstantUtil;
import com.yello.server.global.common.util.RestUtil;
import io.swagger.v3.oas.annotations.Hidden;
import java.io.IOException;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -14,4 +17,28 @@ public class HealthCheckController {
public String healthCheck() {
return "Yell:o world!";
}

@GetMapping("/check1")
public String check1() {
return RestUtil.getSubscribeCheck(
"omfefngneagfjbbiilkfklma.AO-J1OzpoLwvaghTYTf3fmdWnGshzvmO7tWgLS1csfUH4t9jALlrkS4mdO0xnUaKLiFg8GDwB65WjY_P3Kgl7KMs0o5gP7aRPA",
"ya29.a0AfB_byCNJouXhS9xk2xBRG6GOFecUVBpVI0-7ro1pziHD7LhmGGinDm4nOnHbuKyjN_fJnlPRsSv7AzchF4dy4QxF0s9_KUQtKBaaagrpcoscBd6WaTgKxc28V6gvbzHK_NkR_0hVu2kXlRqdBUgU-l4u9JKkSnZYmZqXHvb0gaCgYKAaMSARISFQHsvYlsIAie_CKHJcpEqFfWmG6DjA0177"
).toString();
}

@GetMapping("/check2")
public String check2() {
return RestUtil.getTicketCheck(
ConstantUtil.GOOGLE_FIVE_TICKET_ID,
"iokechedcfehajgklkmhooil.AO-J1Owu16cgCtqfJeVim7uG6WDeJ7hkmmeq7fbzU05PdwzZx9lMK473z1BJOGvrVynngJHhGTQDqLCPFCze9LvpDV0TmT21PQ",
"ya29.a0AfB_byCNJouXhS9xk2xBRG6GOFecUVBpVI0-7ro1pziHD7LhmGGinDm4nOnHbuKyjN_fJnlPRsSv7AzchF4dy4QxF0s9_KUQtKBaaagrpcoscBd6WaTgKxc28V6gvbzHK_NkR_0hVu2kXlRqdBUgU-l4u9JKkSnZYmZqXHvb0gaCgYKAaMSARISFQHsvYlsIAie_CKHJcpEqFfWmG6DjA0177"
).toString();
}

@GetMapping("/check3")
public String check3() throws IOException {
return RestUtil.postGoogleTokenReissue(
"1//0eyLATSiDsTNjCgYIARAAGA4SNwF-L9Ir1pNWYBG1lS2i0Bl6kapR9_NQzhwuXd1NpYRZBuFKVMHbXlqHZyo1kybr_sPw0ijeO20"
).toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.yello.server.global.common.dto.response;

public record GoogleInAppGetResponse(
String purchaseTimeMillis,
Integer purchaseState,
Integer consumptionState,
String developerPayload,
String orderId,
Integer purchaseType,
Integer acknowledgementState,
String kind,
String regionCode
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.yello.server.global.common.dto.response;

import lombok.Builder;

@Builder
public record GoogleTokenIssueResponse(
String access_token,
Integer expires_in,
String scope,
String token_type
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.yello.server.global.common.entity;

import com.yello.server.global.common.dto.AuditingTimeEntity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class GoogleToken extends AuditingTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;

String accessToken;

String refreshToken;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.yello.server.global.common.repository;

import com.yello.server.global.common.entity.GoogleToken;
import org.springframework.data.jpa.repository.JpaRepository;

public interface GoogleTokenJpaRepository extends JpaRepository<GoogleToken, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.yello.server.global.common.repository;

public interface GoogleTokenRepository {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.yello.server.global.common.repository;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class GoogleTokenRepositoryImpl implements GoogleTokenRepository {

private final GoogleTokenJpaRepository googleTokenJpaRepository;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public class ConstantUtil {
public static final String ONE_TICKET_ID = "YELLO.iOS.nameKey.one";
public static final String TWO_TICKET_ID = "YELLO.iOS.nameKey.two";
public static final String FIVE_TICKET_ID = "YELLO.iOS.nameKey.five";
public static final String GOOGLE_YELLO_PLUS_ID = "yello_plus_subscribe";
public static final String GOOGLE_ONE_TICKET_ID = "yello_ticket_one";
public static final String GOOGLE_TWO_TICKET_ID = "yello_ticket_two";
public static final String GOOGLE_FIVE_TICKET_ID = "yello_ticket_five";
public static final int ONE_TICKET = 1400;
public static final int TWO_TICKET = 2800;
public static final int FIVE_TICKET = 5900;
Expand Down
118 changes: 118 additions & 0 deletions src/main/java/com/yello/server/global/common/util/RestUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package com.yello.server.global.common.util;

import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED_VALUE;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.yello.server.domain.authorization.dto.kakao.KakaoTokenInfo;
import com.yello.server.global.common.dto.response.GoogleInAppGetResponse;
import com.yello.server.global.common.dto.response.GoogleTokenIssueResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.client.WebClient;

@Component
public class RestUtil {

private static final String KAKAO_TOKEN_INFO_URL =
"https://kapi.kakao.com/v1/user/access_token_info";
private static final String KAKAO_FRIEND_LIST_URL =
"https://kapi.kakao.com/v1/api/talk/friends";
private static final String GOOGLE_TOKEN_ISSUE_URL = "https://oauth2.googleapis.com/token";
private static String GOOGLE_CLIENT_SECRET_PATH;
private static String ANDROID_PACKAGE_NAME;

private static String GOOGLE_PLAY_SUBSCRIPTIONS_GET_PATH(String packageName, String purchaseToken) {
return "https://androidpublisher.googleapis.com/androidpublisher/v3/applications/"
+ packageName + "/purchases/subscriptionsv2/tokens/"
+ purchaseToken;
}

private static String GOOGLE_PLAY_INAPP_GET_PATH(String packageName, String ticketType, String purchaseToken) {
return "https://androidpublisher.googleapis.com/androidpublisher/v3/applications/"
+ packageName + "/purchases/products/"
+ ticketType + "/tokens/"
+ purchaseToken;
}

public static ResponseEntity<KakaoTokenInfo> getKakaoTokenInfo(String kakaoAccessToken) {
WebClient webClient = WebClient.builder()
.baseUrl(KAKAO_TOKEN_INFO_URL)
.defaultHeader(HttpHeaders.AUTHORIZATION, "Bearer " + kakaoAccessToken)
.defaultHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON_VALUE)
.build();

return webClient.get()
.exchangeToMono(clientResponse -> clientResponse.toEntity(KakaoTokenInfo.class))
.block();
}

public static ResponseEntity<GoogleTokenIssueResponse> postGoogleTokenReissue(String refreshToken)
throws IOException {
Gson gson = new Gson();
ClassPathResource resource = new ClassPathResource(GOOGLE_CLIENT_SECRET_PATH);
JsonObject object = gson.fromJson(new InputStreamReader(resource.getInputStream()), JsonObject.class);
object = (JsonObject) object.get("web");

MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
String clientSecret = String.valueOf(object.get("client_secret"));
String clientId = String.valueOf(object.get("client_id"));

formData.add("client_secret", clientSecret.replaceAll("\"", ""));
formData.add("client_id", clientId.replaceAll("\"", ""));
formData.add("grant_type", "refresh_token");
formData.add("refresh_token", refreshToken);
System.out.println("formData = " + formData);
WebClient webClient = WebClient.builder()
.baseUrl(GOOGLE_TOKEN_ISSUE_URL)
.defaultHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_FORM_URLENCODED_VALUE)
.build();

return webClient.post()
.bodyValue(formData)
.exchangeToMono(clientResponse -> clientResponse.toEntity(GoogleTokenIssueResponse.class))
.block();
}

public static ResponseEntity<String> getSubscribeCheck(String purchaseToken,
String accessToken) {
WebClient webClient = WebClient.builder()
.baseUrl(GOOGLE_PLAY_SUBSCRIPTIONS_GET_PATH(ANDROID_PACKAGE_NAME, purchaseToken))
.defaultHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken)
.build();

return webClient.get()
.exchangeToMono(clientResponse -> clientResponse.toEntity(String.class))
.block();
}

public static ResponseEntity<GoogleInAppGetResponse> getTicketCheck(String ticketType, String purchaseToken,
String accessToken) {
WebClient webClient = WebClient.builder()
.baseUrl(GOOGLE_PLAY_INAPP_GET_PATH(ANDROID_PACKAGE_NAME, ticketType, purchaseToken))
.defaultHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken)
.build();

return webClient.get()
.exchangeToMono(clientResponse -> clientResponse.toEntity(GoogleInAppGetResponse.class))
.block();
}

@Value("${google.developer.key}")
public void setGoogleClientSecretPath(String value) {
GOOGLE_CLIENT_SECRET_PATH = value;
}

@Value("${google.android.package-name}")
public void setAndroidPackageName(String value) {
ANDROID_PACKAGE_NAME = value;
}
}

0 comments on commit 5546b8d

Please sign in to comment.