[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: fix AttributeKey usage
From: |
gnunet |
Subject: |
[libeufin] branch master updated: fix AttributeKey usage |
Date: |
Thu, 14 Oct 2021 17:08:11 +0200 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
The following commit(s) were added to refs/heads/master by this push:
new dcc1089 fix AttributeKey usage
dcc1089 is described below
commit dcc1089eb5857a368b544b8aff6360bef38b5ed6
Author: ms <ms@taler.net>
AuthorDate: Thu Oct 14 17:08:04 2021 +0200
fix AttributeKey usage
---
.../src/main/kotlin/tech/libeufin/sandbox/Main.kt | 20 +++++++------------
util/src/main/kotlin/Config.kt | 23 ++++++++++++++++++----
util/src/main/kotlin/HTTP.kt | 4 ++--
3 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 97789b0..803eaf9 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -454,20 +454,14 @@ val sandboxApp: Application.() -> Unit = {
}
}
intercept(ApplicationCallPipeline.Setup) {
- /**
- * Allows disabling authentication during tests.
- */
- call.application.apply {
- attributes.put(AttributeKey("withAuth"), WITH_AUTH)
- }
- call.application.apply {
- if (adminPassword != null) {
- call.attributes.put(AttributeKey("adminPassword"),
adminPassword)
- /**
- * When not given, the checker expects --no-auth to have been
specified on the CLI.
- */
- }
+ logger.info("Going Setup phase.")
+ val ac: ApplicationCall = call
+ ac.attributes.put(WITH_AUTH_ATTRIBUTE_KEY, WITH_AUTH)
+ if (adminPassword != null) {
+ ac.attributes.put(AttributeKey("adminPassword"), adminPassword)
}
+ logger.info("Finish Setup phase.")
+ return@intercept
}
intercept(ApplicationCallPipeline.Fallback) {
if (this.call.response.status() == null) {
diff --git a/util/src/main/kotlin/Config.kt b/util/src/main/kotlin/Config.kt
index ac4497d..c8af331 100644
--- a/util/src/main/kotlin/Config.kt
+++ b/util/src/main/kotlin/Config.kt
@@ -10,6 +10,17 @@ import org.slf4j.LoggerFactory
import printLnErr
import kotlin.system.exitProcess
+/**
+ * Putting those values into the 'attributes' container because they
+ * are needed by the util routines that do NOT have Sandbox and Nexus
+ * as dependencies, and therefore cannot access their global variables.
+ *
+ * Note: putting Sandbox and Nexus as Utils dependencies would result
+ * into circular dependency.
+ */
+val WITH_AUTH_ATTRIBUTE_KEY = AttributeKey<Boolean>("withAuth")
+val ADMIN_PASSWORD_ATTRIBUTE_KEY = AttributeKey<String>("adminPassword")
+
fun getVersion(): String {
return Loader.getResource(
"version.txt", ClassLoader.getSystemClassLoader()
@@ -58,10 +69,14 @@ internal fun <T : Any>ApplicationCall.maybeAttribute(name:
String): T? {
return this.attributes[key]
}
-internal fun <T : Any>ApplicationCall.ensureAttribute(name: String): T {
- val key = AttributeKey<T>("name")
- if (!this.attributes.contains(key))
- throw internalServerError("Attribute $name not found along the call.")
+/**
+ * Retun the attribute, or throw 500 Internal server error.
+ */
+fun <T : Any>ApplicationCall.ensureAttribute(key: AttributeKey<T>): T {
+ if (!this.attributes.contains(key)) {
+ println("Error: attribute $key not found along the call.")
+ throw internalServerError("Attribute $key not found along the call.")
+ }
return this.attributes[key]
}
diff --git a/util/src/main/kotlin/HTTP.kt b/util/src/main/kotlin/HTTP.kt
index b902a8e..b6d7ea6 100644
--- a/util/src/main/kotlin/HTTP.kt
+++ b/util/src/main/kotlin/HTTP.kt
@@ -89,7 +89,7 @@ fun ApplicationRequest.getBaseUrl(): String {
* environment.
*/
fun ApplicationRequest.basicAuth() {
- val withAuth = this.call.ensureAttribute<Boolean>("withAuth")
+ val withAuth = this.call.ensureAttribute(WITH_AUTH_ATTRIBUTE_KEY)
if (!withAuth) {
logger.info("Authentication is disabled - assuming tests currently
running.")
return
@@ -97,7 +97,7 @@ fun ApplicationRequest.basicAuth() {
val credentials = getHTTPBasicAuthCredentials(this)
if (credentials.first == "admin") {
// env must contain the admin password, because --with-auth is true.
- val adminPassword = this.call.ensureAttribute<String>("adminPassword")
+ val adminPassword =
this.call.ensureAttribute(ADMIN_PASSWORD_ATTRIBUTE_KEY)
if (credentials.second != adminPassword) throw unauthorized(
"Admin authentication failed"
)
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: fix AttributeKey usage,
gnunet <=