Skip to content

Commit

Permalink
Merge pull request #48 from spotify/local-properties-client
Browse files Browse the repository at this point in the history
move the client secret to the local.properties file
  • Loading branch information
vahidlazio authored Jul 27, 2023
2 parents 5c17335 + d70fe4c commit 862400f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
14 changes: 14 additions & 0 deletions ConfidenceDemoApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import java.io.File
import java.util.Properties

plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
Expand All @@ -20,11 +23,22 @@ object Versions {
const val uiTestManifest = "1.2.0"
}

val localPropertiesFile = File(rootProject.projectDir, "local.properties")
val localProperties = Properties()

// Load the properties from local.properties file
if (localPropertiesFile.exists()) {
localProperties.load(localPropertiesFile.inputStream())
}

val clientSecret: String = localProperties.getProperty("CLIENT_SECRET")?: "CLIENT_SECRET"

android {
namespace = "com.example.confidencedemoapp"
compileSdk = 33

defaultConfig {
buildConfigField("String","CLIENT_SECRET", "\"$clientSecret\"")
applicationId = "com.example.confidencedemoapp"
minSdk = 21
targetSdk = 33
Expand Down
3 changes: 0 additions & 3 deletions ConfidenceDemoApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.example.confidencedemoapp.clientSecret"
android:value="@string/client_secret" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.confidencedemoapp

object ClientSecretProvider {
fun clientSecret(): String = BuildConfig.CLIENT_SECRET
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package com.example.confidencedemoapp

import android.app.Application
import android.content.pm.PackageManager
import android.util.Log
import androidx.compose.ui.graphics.Color
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import dev.openfeature.contrib.providers.ConfidenceFeatureProvider
import dev.openfeature.sdk.*
import dev.openfeature.sdk.Client
import dev.openfeature.sdk.EvaluationContext
import dev.openfeature.sdk.FlagEvaluationDetails
import dev.openfeature.sdk.ImmutableContext
import dev.openfeature.sdk.OpenFeatureAPI
import dev.openfeature.sdk.Value
import kotlinx.coroutines.launch
import java.util.*
import java.util.UUID

class MainVm(app: Application) : AndroidViewModel(app) {

Expand All @@ -28,12 +32,7 @@ class MainVm(app: Application) : AndroidViewModel(app) {

init {
val start = System.currentTimeMillis()
val applicationContext = app.applicationContext
val metadataBundle = applicationContext.packageManager.getApplicationInfo(
applicationContext.packageName,
PackageManager.GET_META_DATA
).metaData
val clientSecret = metadataBundle.getString("com.example.confidencedemoapp.clientSecret")!!
val clientSecret = ClientSecretProvider.clientSecret()
viewModelScope.launch {
OpenFeatureAPI.setProvider(
ConfidenceFeatureProvider.create(
Expand All @@ -52,10 +51,10 @@ class MainVm(app: Application) : AndroidViewModel(app) {

fun refreshUi() {
Log.d(TAG, "refreshing UI")
val flagMessageKey = "myFlag.message"
val flagMessageKey = "hawkflag.message"
val flagMessageDefault = "default"
val messageValue = client.getStringValue(flagMessageKey, flagMessageDefault)
val flagColorKey = "myFlag.color"
val flagColorKey = "hawkflag.color"
val flagColorDefault = "Gray"
val colorFlag = client.getStringDetails(flagColorKey, flagColorDefault).apply {
Log.d(TAG, "reason=$reason")
Expand Down
1 change: 0 additions & 1 deletion ConfidenceDemoApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<resources>
<string name="app_name">ConfidenceDemoApp</string>
<string name="client_secret">Some client secret</string>
</resources>

0 comments on commit 862400f

Please sign in to comment.