Skip to content
Merged
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
4 changes: 3 additions & 1 deletion .github/workflows/checkstyle-validation.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: 👮Checkstyle validation

on:
push:
branches: [ 1151-feature-42api-모니터링스레드에작업 ]
pull_request:
branches: [ main, dev , recruit-dev]
branches: [ main, dev ]

jobs:
checkstyle:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/http-client.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dev": {
"name": "value"
}
}
4 changes: 3 additions & 1 deletion .github/workflows/test-code-validation.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: 💻 Test code validation

on:
push:
branches: [ 1151-feature-42api-모니터링스레드에작업 ]
pull_request:
branches: [main, dev]
branches: [ main, dev ]

jobs:
test:
Expand Down
58 changes: 1 addition & 57 deletions .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: test-deploy

on:
push:
branches: [ dev ]
branches: [ dev, 1151-feature-42api-모니터링스레드에작업 ]
workflow_dispatch:

env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
IMAGE_NAME: wken5577/test-migrate-server

permissions:
contents: read

Expand All @@ -41,52 +29,8 @@ jobs:
echo "${{ secrets.MIGRATE_APPLICATION_YML }}" | base64 -d > application.yml
shell: bash

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ env.DOCKER_USER }}
password: ${{ env.DOCKER_PASSWORD }}

- name: Test with Gradle
run: ./gradlew clean test

- name: Build with Gradle
run: ./gradlew clean build -x test

- name: build new docker image as latest tag
run: |
docker build -t ${{ env.IMAGE_NAME }}:latest .
docker push ${{ env.IMAGE_NAME }}:latest

- name: Create the configuration file
run: |
cat << EOF > config.json
{
"AutoScalingGroupName": "gg-dev",
"DesiredConfiguration": {
"LaunchTemplate": {
"LaunchTemplateId": "${{ secrets.DEV_LAUNCH_TEMPLATE_ID }}",
"Version": "\$Latest"
}
},
"Preferences": {
"MinHealthyPercentage": 100,
"MaxHealthyPercentage": 110,
"InstanceWarmup": 300,
"ScaleInProtectedInstances": "Ignore",
"StandbyInstances": "Ignore"
}
}
EOF
cat config.json

- name: Configure AWS CLI
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_TEST_MIGRATE_SECURITY_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_TEST_MIGRATE_SECURITY_SECRET_KEY }}
aws-region: ap-northeast-2

- name: Trigger Instance Refresh
run: |
aws autoscaling start-instance-refresh --cli-input-json file://config.json
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ plugins {
id 'checkstyle'
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

editorconfig {
excludes = ['build']
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages = {"gg.recruit.api", "gg.utils", "gg.data", "gg.repo",
"gg.admin.repo", "gg.auth", "gg.pingpong.api"})
"gg.admin.repo", "gg.auth", "gg.pingpong.api", "gg.calendar.api"})
public class TestSpringBootApplication {
}
30 changes: 30 additions & 0 deletions gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import gg.auth.config.ScheduleConfig;
import gg.utils.exception.ErrorCode;
import gg.utils.exception.custom.NotExistException;
import gg.utils.exception.user.TokenNotValidException;
import gg.utils.external.ApiUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
@RequiredArgsConstructor
public class FortyTwoAuthUtil {
private final ApiUtil apiUtil;
private final OAuth2AuthorizedClientService authorizedClientService;
private final ScheduleConfig scheduleConfig;

public String getAccessToken() {
Authentication authentication = getAuthenticationFromContext();
Expand Down Expand Up @@ -62,6 +66,32 @@
return newClient.getAccessToken().getTokenValue();
}

/* 42event client credential token */
public String getClientCredentialToken() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

Check warning on line 72 in gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java

View check run for this annotation

Codecov / codecov/patch

gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java#L71-L72

Added lines #L71 - L72 were not covered by tests

MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("grant_type", "client_credentials");
params.add("client_id", scheduleConfig.getClientId());
params.add("client_secret", scheduleConfig.getClientSecret());

Check warning on line 77 in gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java

View check run for this annotation

Codecov / codecov/patch

gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java#L74-L77

Added lines #L74 - L77 were not covered by tests

try {
Map<String, Object> response = apiUtil.apiCall(
scheduleConfig.getTokenUri(),

Check warning on line 81 in gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java

View check run for this annotation

Codecov / codecov/patch

gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java#L80-L81

Added lines #L80 - L81 were not covered by tests
Map.class,
headers,
params,
HttpMethod.POST
);
log.info("Raw Api Response : {}", response);

Check warning on line 87 in gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java

View check run for this annotation

Codecov / codecov/patch

gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java#L87

Added line #L87 was not covered by tests
// System.out.println("Response : " + response);
return (String)response.get("access_token");
} catch (Exception e) {
throw new TokenNotValidException();

Check warning on line 91 in gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java

View check run for this annotation

Codecov / codecov/patch

gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java#L89-L91

Added lines #L89 - L91 were not covered by tests
}
}

private Authentication getAuthenticationFromContext() {
SecurityContext context = SecurityContextHolder.getContext();
return context.getAuthentication();
Expand Down
17 changes: 17 additions & 0 deletions gg-auth/src/main/java/gg/auth/config/ScheduleConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gg.auth.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import lombok.Getter;

@Configuration
@Getter
public class ScheduleConfig {
@Value("${spring.security.oauth2.client.registration.42.client-id}")
private String clientId;
@Value("${spring.security.oauth2.client.registration.42.client-secret}")
private String clientSecret;
@Value("${spring.security.oauth2.client.provider.42.token-uri}")
private String tokenUri;
}
78 changes: 0 additions & 78 deletions gg-calendar-api/src/main/java/gg/api42/ApiClient.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,5 @@ public ResponseEntity<Void> publicScheduleDelete(@PathVariable Long id) {
public ResponseEntity<PublicScheduleAdminResDto> publicScheduleDetail(@PathVariable Long id) {
PublicScheduleAdminResDto publicScheduleAdminResDto = publicScheduleAdminService.detailPublicSchedule(id);
return ResponseEntity.ok(publicScheduleAdminResDto);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public PublicSchedule getPublicScheduleDetailRetrieve(Long scheduleId, Long user
User user = userRepository.getById(userId);
PublicSchedule publicRetrieveSchedule = publicScheduleRepository.findById(scheduleId)
.orElseThrow(() -> new NotExistException(ErrorCode.PUBLIC_SCHEDULE_NOT_FOUND));
checkAuthor(publicRetrieveSchedule.getAuthor(), user);
// checkAuthor(publicRetrieveSchedule.getAuthor(), user);
return publicRetrieveSchedule;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package gg.calendar.api.user.utils.controller.response;

import java.time.LocalDateTime;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class FortyTwoEventResponse {
@JsonProperty("id")
private Long id;

@JsonProperty("name")
private String name;

@JsonProperty("description")
private String description;

@JsonProperty("location")
private String location;

@JsonProperty("kind")
private String kind;

@JsonProperty("begin_at")
private LocalDateTime beginAt;

@JsonProperty("end_at")
private LocalDateTime endAt;

@JsonProperty("created_at")
private LocalDateTime createdAt;

@JsonProperty("updated_at")
private LocalDateTime updatedAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package gg.calendar.api.user.utils.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.client.HttpClientErrorException;

import gg.auth.FortyTwoAuthUtil;
import gg.calendar.api.user.utils.controller.response.FortyTwoEventResponse;
import gg.utils.external.ApiUtil;
import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
public class FortyTwoEventApiClient {
private final ApiUtil apiUtil;
private final FortyTwoAuthUtil fortyTwoAuthUtil;

@Value("https://api.intra.42.fr/v2/campus/29/events")
private String eventUrl;

public List<FortyTwoEventResponse> getEvents() {
ParameterizedTypeReference<List<FortyTwoEventResponse>> responseType = new ParameterizedTypeReference<>() {

Check warning on line 26 in gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClient.java

View check run for this annotation

Codecov / codecov/patch

gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClient.java#L26

Added line #L26 was not covered by tests
};

try {
String accessToken = fortyTwoAuthUtil.getClientCredentialToken();
return apiUtil.callApiWithAccessTokenEvent(eventUrl, accessToken, responseType);
} catch (HttpClientErrorException e) {

Check warning on line 32 in gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClient.java

View check run for this annotation

Codecov / codecov/patch

gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClient.java#L30-L32

Added lines #L30 - L32 were not covered by tests
if (e.getStatusCode() == HttpStatus.UNAUTHORIZED) {
String refreshToken = fortyTwoAuthUtil.getClientCredentialToken();
return apiUtil.callApiWithAccessTokenEvent(eventUrl, refreshToken, responseType);

Check warning on line 35 in gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClient.java

View check run for this annotation

Codecov / codecov/patch

gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClient.java#L34-L35

Added lines #L34 - L35 were not covered by tests
}
throw e;

Check warning on line 37 in gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClient.java

View check run for this annotation

Codecov / codecov/patch

gg-calendar-api/src/main/java/gg/calendar/api/user/utils/service/FortyTwoEventApiClient.java#L37

Added line #L37 was not covered by tests
}
}
}
Loading
Loading