Skip to content

Commit

Permalink
Simplify API key loading
Browse files Browse the repository at this point in the history
  • Loading branch information
SailReal committed Oct 13, 2023
1 parent 6db3a72 commit 12311bf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
17 changes: 17 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,20 @@ allprojects {
task clean(type: Delete) {
delete rootProject.buildDir
}

def getApiKey(key) {
return !liteFlavor() ? System.getenv().getOrDefault(key, getApiKeyLocal(key)) : ""
}

def liteFlavor() {
gradle.startParameter.taskNames.stream().filter(t -> t.toLowerCase().contains("lite")).findAny().isPresent()
}

def getApiKeyLocal(key) {
if(!rootProject.file("local.properties").exists()) {
return ""
}
def localPropertyList = new Properties()
localPropertyList.load(new FileInputStream(rootProject.file("local.properties")))
return localPropertyList.getOrDefault(key, "")
}
8 changes: 0 additions & 8 deletions data/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,6 @@ configurations {
all*.exclude group: 'com.google.android', module: 'android'
}

def liteFlavor() {
gradle.startParameter.taskNames.stream().filter(t -> t.toLowerCase().contains("lite")).findAny().isPresent()
}

def getApiKey(key) {
return !liteFlavor() ? System.getenv().getOrDefault(key, "") : ""
}

tasks.withType(Test) {
testLogging {
events "failed"
Expand Down
13 changes: 0 additions & 13 deletions presentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -274,19 +274,6 @@ def liteFlavor() {
gradle.startParameter.taskNames.stream().filter(t -> t.toLowerCase().contains("lite")).findAny().isPresent()
}

def getApiKey(key) {
return !liteFlavor() ? System.getenv().getOrDefault(key, getApiKeyLocal(key)) : ""
}

def getApiKeyLocal(key) {
if(!rootProject.file("local.properties").exists()) {
return ""
}
def localPropertyList = new Properties()
localPropertyList.load(new FileInputStream(rootProject.file("local.properties")))
return localPropertyList.getOrDefault(key, "")
}

def getOnedriveApiKey() {
if (liteFlavor()) {
return ""
Expand Down
4 changes: 0 additions & 4 deletions presentation/prebuild.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,4 @@ task generateAppConfigurationFile() {
config_file.write(JsonOutput.prettyPrint(JsonOutput.toJson(jsonSlurper.parseText(jsonString))))
}

static def getApiKey(key) {
return System.getenv().getOrDefault(key, "")
}

build.dependsOn generateAppConfigurationFile

0 comments on commit 12311bf

Please sign in to comment.