Skip to content

Commit

Permalink
feat: Firebase config
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-chekyrta committed Feb 12, 2024
1 parent e6876be commit 04aeaf4
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 20 deletions.
21 changes: 13 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-parcelize'
id 'kotlin-kapt'
id 'com.google.firebase.crashlytics'
}

def config = configHelper.fetchConfig()
def appId = config.getOrDefault("APPLICATION_ID", "org.openedx.app")
def platformName = config.getOrDefault("PLATFORM_NAME", "OpenEdx").toLowerCase()
def firebaseConfig = config.get('FIREBASE')
def firebaseEnabled = firebaseConfig?.getOrDefault('ENABLED', false)

apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'kotlin-parcelize'
apply plugin: 'kotlin-kapt'
if (firebaseEnabled) {
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

configHelper.generateGoogleServicesJson(appId)
}

android {
compileSdk 34
Expand Down
11 changes: 2 additions & 9 deletions app/src/main/java/org/openedx/app/OpenEdXApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ class OpenEdXApp : Application() {
screenModule
)
}
val firebaseConfig = config.getFirebaseConfig()
if (firebaseConfig.enabled) {
val options = FirebaseOptions.Builder()
.setProjectId(firebaseConfig.projectId)
.setApplicationId(firebaseConfig.applicationId)
.setApiKey(firebaseConfig.apiKey)
.setGcmSenderId(firebaseConfig.gcmSenderId)
.build()
Firebase.initialize(this, options)
if (config.getFirebaseConfig().enabled) {
Firebase.initialize(this)
}
}

Expand Down
45 changes: 45 additions & 0 deletions buildSrc/src/main/groovy/org/edx/builder/ConfigHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,49 @@ class ConfigHelper {
it.write(new JsonBuilder(configJson).toPrettyString())
}
}

def generateGoogleServicesJson(applicationId) {
def config = fetchConfig()
def firebase = config.get("FIREBASE")
if (!firebase) {
return
}
if (!firebase.getOrDefault("ENABLED", false)) {
return
}

def googleServicesJsonPath = projectDir.path + "/app/"
new File(googleServicesJsonPath).mkdirs()

def projectInfo = [
project_number: firebase.getOrDefault("PROJECT_NUMBER", ""),
project_id : firebase.getOrDefault("PROJECT_ID", ""),
storage_bucket: "${firebase.getOrDefault("PROJECT_ID", "")}.appspot.com"
]
def clientInfo = [
mobilesdk_app_id : firebase.getOrDefault("APPLICATION_ID", ""),
android_client_info: [
package_name: applicationId
]
]
def client = [
client_info : clientInfo,
oauth_client: [],
api_key : [[current_key: firebase.getOrDefault("API_KEY", "")]],
services : [
appinvite_service: [
other_platform_oauth_client: []
]
]
]
def configJson = [
project_info : projectInfo,
client : [client],
configuration_version: "1"
]

new FileWriter(googleServicesJsonPath + "/google-services.json").withWriter {
it.write(new JsonBuilder(configJson).toPrettyString())
}
}
}
6 changes: 3 additions & 3 deletions core/src/main/java/org/openedx/core/config/FirebaseConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ data class FirebaseConfig(
@SerializedName("ENABLED")
val enabled: Boolean = false,

@SerializedName("PROJECT_NUMBER")
val gcmSenderId: String = "",

@SerializedName("PROJECT_ID")
val projectId: String = "",

Expand All @@ -14,7 +17,4 @@ data class FirebaseConfig(

@SerializedName("API_KEY")
val apiKey: String = "",

@SerializedName("GCM_SENDER_ID")
val gcmSenderId: String = "",
)
7 changes: 7 additions & 0 deletions default_config/dev/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ PROGRAM:
PROGRAM_URL: ''
PROGRAM_DETAIL_URL_TEMPLATE: ''

FIREBASE:
ENABLED: false
PROJECT_NUMBER: ''
PROJECT_ID: ''
APPLICATION_ID: ''
API_KEY: ''

GOOGLE:
ENABLED: false
CLIENT_ID: ''
Expand Down
7 changes: 7 additions & 0 deletions default_config/prod/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ PROGRAM:
PROGRAM_URL: ''
PROGRAM_DETAIL_URL_TEMPLATE: ''

FIREBASE:
ENABLED: false
PROJECT_NUMBER: ''
PROJECT_ID: ''
APPLICATION_ID: ''
API_KEY: ''

GOOGLE:
ENABLED: false
CLIENT_ID: ''
Expand Down
7 changes: 7 additions & 0 deletions default_config/stage/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ PROGRAM:
PROGRAM_URL: ''
PROGRAM_DETAIL_URL_TEMPLATE: ''

FIREBASE:
ENABLED: false
PROJECT_NUMBER: ''
PROJECT_ID: ''
APPLICATION_ID: ''
API_KEY: ''

GOOGLE:
ENABLED: false
CLIENT_ID: ''
Expand Down

0 comments on commit 04aeaf4

Please sign in to comment.