From 2e092aa0351d2942069d1b7c48b313dac7d6862e Mon Sep 17 00:00:00 2001 From: Evgenii Kozlov Date: Mon, 26 Jul 2021 10:07:06 +0300 Subject: [PATCH] Analytics | Storing api keys (#1671) --- .github/workflows/check.yml | 4 +++- .github/workflows/workflow.yml | 4 +++- app/build.gradle | 6 +++++ .../anytype/app/AndroidApplication.kt | 6 +---- middleware2.sh | 22 ++++++++++++++++++- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 795ab9a0d7..cfec6b2894 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -13,6 +13,8 @@ jobs: env: token_secret: ${{ secrets.ANYTYPE_SECRET }} user_secret: ${{ secrets.ANYTYPE_USER_SECRET }} - run: ./middleware2.sh $token_secret $user_secret + amplitude_secret: ${{ secrets.ANYTYPE_AMPLITUDE_SECRET }} + amplitude_secret_debug: ${{ secrets.ANYTYPE_AMPLITUDE_DEBUG_SECRET }} + run: ./middleware2.sh $token_secret $user_secret $amplitude_secret $amplitude_secret_debug - name: Run unit tests run: ./gradlew assembleDebug test -Dpre-dex=false diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 883556be09..0edf221244 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -11,6 +11,8 @@ jobs: env: token_secret: ${{ secrets.ANYTYPE_SECRET }} user_secret: ${{ secrets.ANYTYPE_USER_SECRET }} - run: ./middleware2.sh $token_secret $user_secret + amplitude_secret: ${{ secrets.ANYTYPE_AMPLITUDE_SECRET }} + amplitude_secret_debug: ${{ secrets.ANYTYPE_AMPLITUDE_DEBUG_SECRET }} + run: ./middleware2.sh $token_secret $user_secret $amplitude_secret $amplitude_secret_debug - name: Run unit tests. Full mode. run: ./gradlew build test -Dpre-dex=false diff --git a/app/build.gradle b/app/build.gradle index 5a4bdb3663..013e7ed1eb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,6 +8,10 @@ apply plugin: 'com.google.firebase.crashlytics' apply from: "$rootDir/versioning.gradle" +def apikeyPropertiesFile = rootProject.file("apikeys.properties") +def apikeyProperties = new Properties() +apikeyProperties.load(new FileInputStream(apikeyPropertiesFile)) + android { def config = rootProject.extensions.getByName("ext") @@ -46,11 +50,13 @@ android { minifyEnabled false useProguard false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + buildConfigField("String", "AMPLITUDE_KEY", apikeyProperties['amplitude.release']) } debug { applicationIdSuffix ".debug" debuggable true + buildConfigField("String", "AMPLITUDE_KEY", apikeyProperties['amplitude.debug']) } } diff --git a/app/src/main/java/com/anytypeio/anytype/app/AndroidApplication.kt b/app/src/main/java/com/anytypeio/anytype/app/AndroidApplication.kt index 7a81ce8c0f..d5a9d8cec2 100644 --- a/app/src/main/java/com/anytypeio/anytype/app/AndroidApplication.kt +++ b/app/src/main/java/com/anytypeio/anytype/app/AndroidApplication.kt @@ -59,10 +59,6 @@ class AndroidApplication : Application() { } private fun setupAnalytics() { - if (BuildConfig.DEBUG) { - Amplitude.getInstance().initialize(this, getString(R.string.amplitude_api_key_debug)) - } else { - Amplitude.getInstance().initialize(this, getString(R.string.amplitude_api_key)) - } + Amplitude.getInstance().initialize(this, BuildConfig.AMPLITUDE_KEY) } } \ No newline at end of file diff --git a/middleware2.sh b/middleware2.sh index 844a227f3c..302ddfd594 100755 --- a/middleware2.sh +++ b/middleware2.sh @@ -2,9 +2,13 @@ TOKEN=$1 USER=$2 +AMPLITUDE_RELEASE_KEY=$3 +AMPLITUDE_DEBUG_KEY=$4 GITHUB_USER_PROPERTY="gpr.usr" GITHUB_KEY_PROPERTY="gpr.key" +AMPLITUDE_DEBUG_PROPERTY="amplitude.debug" +AMPLITUDE_RELEASE_PROPERTY="amplitude.release" if [ "$TOKEN" = "" ]; then echo "ERROR: token is empty" @@ -16,8 +20,24 @@ if [ "$USER" = "" ]; then exit 1 fi; +if [ "$AMPLITUDE_RELEASE_KEY" = "" ]; then + echo "ERROR: amplitude.release is empty" + exit 1 +fi; + +if [ "$AMPLITUDE_DEBUG_KEY" = "" ]; then + echo "ERROR: amplitude.debug is empty" + exit 1 +fi; + rm -rf github.properties touch github.properties echo "$GITHUB_USER_PROPERTY=$USER" >> github.properties -echo "$GITHUB_KEY_PROPERTY=$TOKEN" >> github.properties \ No newline at end of file +echo "$GITHUB_KEY_PROPERTY=$TOKEN" >> github.properties + +rm -rf apikeys.properties +touch apikeys.properties + +echo "$AMPLITUDE_DEBUG_PROPERTY=\"$AMPLITUDE_DEBUG_KEY\"" >> apikeys.properties +echo "$AMPLITUDE_RELEASE_PROPERTY=\"$AMPLITUDE_RELEASE_KEY\"" >> apikeys.properties \ No newline at end of file