This repository has been archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add submodules * setting(build.gradle.kts): Firebase 의존성 추가 * feat(FirebaseConfig): FirebaseConfig 설정 완료 * refactor(gitmodules): 서브모듈 path 상대경로로 수정
- Loading branch information
1 parent
21feb7d
commit d2f9622
Showing
5 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "src/main/resources/config"] | ||
path = src/main/resources/config | ||
url = https://github.com/gdsc-konkuk/Plantory-Server-Config.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/kotlin/gdsc/plantory/common/config/FirebaseConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package gdsc.plantory.common.config | ||
|
||
import com.google.auth.oauth2.GoogleCredentials | ||
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.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.core.io.ClassPathResource | ||
import java.util.Optional | ||
|
||
@Configuration | ||
class FirebaseConfig( | ||
@Value("\${fcm.key.path}") | ||
private val fcmPrivateKeyPath: String | ||
) { | ||
|
||
@Bean | ||
fun firebaseMessaging(): FirebaseMessaging { | ||
val defaultFirebaseApp = defaultFirebaseApp() | ||
|
||
if (defaultFirebaseApp.isPresent) { | ||
return FirebaseMessaging.getInstance(defaultFirebaseApp.get()) | ||
} | ||
|
||
return FirebaseMessaging.getInstance(FirebaseApp.initializeApp(createFirebaseOption())) | ||
} | ||
|
||
private fun defaultFirebaseApp(): Optional<FirebaseApp> { | ||
val firebaseAppList = FirebaseApp.getApps() | ||
|
||
if (firebaseAppList == null || firebaseAppList.isEmpty()) { | ||
return Optional.empty() | ||
} | ||
|
||
return firebaseAppList.stream() | ||
.filter { firebaseApp: FirebaseApp -> firebaseApp.name == FirebaseApp.DEFAULT_APP_NAME } | ||
.findAny() | ||
} | ||
|
||
private fun createFirebaseOption(): FirebaseOptions { | ||
return FirebaseOptions.builder() | ||
.setCredentials(createGoogleCredentials()) | ||
.build() | ||
} | ||
|
||
private fun createGoogleCredentials(): GoogleCredentials { | ||
return GoogleCredentials | ||
.fromStream(ClassPathResource(fcmPrivateKeyPath).inputStream) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters