Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

[#55] 외부에서 주입한 설정 값을 사용할 수 있도록 수정 #58

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src/main/java/me/liiot/snsserver/config/FirebaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import javax.annotation.PostConstruct;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

Expand All @@ -29,7 +29,7 @@ public class FirebaseConfig {
@PostConstruct
public void initialize() {
try {
InputStream serviceAccount = new ClassPathResource(apiKeyPath).getInputStream();
InputStream serviceAccount = new FileInputStream(apiKeyPath);

FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
Expand All @@ -39,7 +39,7 @@ public void initialize() {
FirebaseApp.initializeApp(options);
}
} catch (IOException e) {
log.error("Failed initializing FilebaseApp: {}", e.getMessage());
log.error("Failed initializing FilebaseApp: ", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.liiot.snsserver.enumeration.PushType;
import org.springframework.core.io.ClassPathResource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.io.FileInputStream;
import java.io.IOException;
import java.time.Duration;
import java.time.LocalDateTime;
Expand All @@ -20,6 +21,9 @@
@Slf4j
public class FirebasePushService implements PushService {

@Value("${firebase.account.key.path}")
private String apiKeyPath;

private final RedisTemplate<String, Object> redisTemplate;

public void setToken(String userId) {
Expand Down Expand Up @@ -57,13 +61,13 @@ public void sendPushMessage(String userId, String receiverId, PushType type, Str
private String getAccessToken() {
try {
GoogleCredential googleCredential = GoogleCredential
.fromStream(new ClassPathResource("sns-itda-firebase-adminsdk.json").getInputStream())
.fromStream(new FileInputStream(apiKeyPath))
.createScoped(Arrays.asList("https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/firebase.messaging"));
googleCredential.refreshToken();
return googleCredential.getAccessToken();
} catch (IOException e) {
log.error("Failed getting access token: {}", e.getMessage());
log.error("Failed getting access token: ", e);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@Service
@RequiredArgsConstructor
@Profile("dev")
@Profile("local")
public class LocalFileService implements FileService {

@Value("${itda.local.file.base.directory}")
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/application-dev.properties

This file was deleted.

13 changes: 13 additions & 0 deletions src/main/resources/application-local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Image Directory Path
itda.local.file.base.directory = C:\\Users\\cyj19\\Desktop\\Project\\sns-server\\images

# Redis Session Local Config
spring.redis.session.host=localhost
spring.redis.session.port=6379

# Redis Cache Local Config
spring.redis.cache.host=localhost
spring.redis.cache.port=6380

#Firebase Service Local Config
firebase.account.key.path=C:\\Users\\cyj19\\Desktop\\Project\\sns-server\\src\\main\\resources\\sns-itda-firebase-adminsdk.json
15 changes: 2 additions & 13 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
spring.profiles.active=dev
spring.profiles.active=local
spring.session.store-type=redis
spring.cache.type=redis

# Redis Session Config
spring.redis.session.host=localhost
spring.redis.session.port=6379

# Redis Cache Config
spring.redis.cache.host=localhost
spring.redis.cache.port=6380

#Firebase Service
firebase.account.key.path=sns-itda-firebase-adminsdk.json
spring.cache.type=redis