Skip to content

Commit

Permalink
Merge pull request #3 from Liftric/feature/lazy
Browse files Browse the repository at this point in the history
feat: restore configure time project extension function and adapt test
  • Loading branch information
benjohnde committed Jul 13, 2020
2 parents 3b4ab42 + 4d5b17d commit 0bdb90c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
10 changes: 9 additions & 1 deletion integration-token/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ vault {
maxRetries.set(2)
retryIntervalMilliseconds.set(200)
}
val configTimeSecrets: Map<String, String> = vault("secret/example")
tasks {
val needsSecretsConfigTime by creating {
doLast {
if (configTimeSecrets["examplestring"] != "helloworld") throw kotlin.IllegalStateException("examplestring couldn't be read")
if (configTimeSecrets["exampleint"]?.toInt() != 1337) throw kotlin.IllegalStateException("exampleint couldn't be read")
println("getting secrets succeeded!")
}
}
val needsSecrets by creating(GetVaultSecretTask::class) {
secretPath.set("secret/example")
doLast {
Expand All @@ -27,6 +35,6 @@ tasks {
}
}
val build by existing {
dependsOn(needsSecrets, fromBuildSrc)
dependsOn(needsSecretsConfigTime, needsSecrets, fromBuildSrc)
}
}
19 changes: 19 additions & 0 deletions src/main/kotlin/com/liftric/vault/VaultClientPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,22 @@ fun Project.vault(): VaultClientExtension {
return extensions.getByName(extensionName) as? VaultClientExtension
?: throw IllegalStateException("$extensionName is not of the correct type")
}

fun Project.vault(secretPath: String): Map<String, String> {
val extension: VaultClientExtension = vault()
val token = GetVaultSecretTask.determineToken(
vaultToken = extension.vaultToken.orNull,
vaultTokenFilePath = extension.vaultTokenFilePath.orNull
)
val address = GetVaultSecretTask.determinAddress(vaultAddress = extension.vaultAddress.orNull)
val maxRetries = extension.maxRetries.getOrElse(Defaults.MAX_RETRIES)
val retryIntervalMilliseconds = extension.retryIntervalMilliseconds.getOrElse(Defaults.RETRY_INTERVAL_MILLI)
println("[vault] getting `$secretPath` from $address")

return VaultClient(
token = token,
vaultAddress = address,
maxRetries = maxRetries,
retryIntervalMilliseconds = retryIntervalMilliseconds
).get(secretPath)
}

0 comments on commit 0bdb90c

Please sign in to comment.