diff --git a/bin/.act-0.2.57.pkg b/bin/.act-0.2.57.pkg new file mode 120000 index 000000000..383f4511d --- /dev/null +++ b/bin/.act-0.2.57.pkg @@ -0,0 +1 @@ +hermit \ No newline at end of file diff --git a/bin/act b/bin/act new file mode 120000 index 000000000..1dade306e --- /dev/null +++ b/bin/act @@ -0,0 +1 @@ +.act-0.2.57.pkg \ No newline at end of file diff --git a/go-runtime/sdk/secrets.go b/go-runtime/sdk/secrets.go index 5cf2b8562..b9b6a0d51 100644 --- a/go-runtime/sdk/secrets.go +++ b/go-runtime/sdk/secrets.go @@ -34,13 +34,13 @@ func (s *SecretValue[Type]) String() string { } // Get returns the value of the secret from FTL. -func (c *SecretValue[Type]) Get() (out Type) { - value, ok := os.LookupEnv(fmt.Sprintf("FTL_SECRET_%s_%s", strings.ToUpper(c.module), strings.ToUpper(c.name))) +func (s *SecretValue[Type]) Get() (out Type) { + value, ok := os.LookupEnv(fmt.Sprintf("FTL_SECRET_%s_%s", strings.ToUpper(s.module), strings.ToUpper(s.name))) if !ok { return out } if err := json.Unmarshal([]byte(value), &out); err != nil { - panic(fmt.Errorf("failed to parse %s: %w", c, err)) + panic(fmt.Errorf("failed to parse %s: %w", s, err)) } return } diff --git a/kotlin-runtime/ftl-runtime/pom.xml b/kotlin-runtime/ftl-runtime/pom.xml index 53ded133c..fae05e2ed 100644 --- a/kotlin-runtime/ftl-runtime/pom.xml +++ b/kotlin-runtime/ftl-runtime/pom.xml @@ -1,6 +1,6 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 @@ -108,14 +108,16 @@ test - + + org.junit.jupiter + junit-jupiter + org.junit-pioneer junit-pioneer - 2.1.0 - test + 2.2.0 + compile - diff --git a/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/config/Config.kt b/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/config/Config.kt index 5aa90467e..8a1b645c3 100644 --- a/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/config/Config.kt +++ b/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/config/Config.kt @@ -2,20 +2,31 @@ package xyz.block.ftl.config import xyz.block.ftl.serializer.makeGson -class Secret(val name: String) { - val _module: String - val _gson = makeGson() +class Config(private val cls: Class, val name: String) { + private val module: String + private val gson = makeGson() + + companion object { + /** + * A convenience method for creating a new Secret. + * + *
+     *   val secret = Config.new("test")
+     * 
+ * + */ + inline fun new(name: String): Config = Config(T::class.java, name) } init { val caller = Thread.currentThread().stackTrace[2].className require(caller.startsWith("ftl.") || caller.startsWith("xyz.block.ftl.config.")) { "Config must be defined in an FTL module not $caller" } val parts = caller.split(".") - _module = parts[parts.size - 2] + module = parts[parts.size - 2] } - inline fun get(): T { - val key = "FTL_CONFIG_${_module.uppercase()}_${name.uppercase()}" - val value = System.getenv(key) ?: throw Exception("Config key ${_module}.${name} not found") - return _gson.fromJson(value, T::class.java) + fun get(): T { + val key = "FTL_CONFIG_${module.uppercase()}_${name.uppercase()}" + val value = System.getenv(key) ?: throw Exception("Config key ${module}.${name} not found") + return gson.fromJson(value, cls) } } diff --git a/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/config/ConfigTest.kt b/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/config/ConfigTest.kt index 2faeb242e..627196b20 100644 --- a/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/config/ConfigTest.kt +++ b/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/config/ConfigTest.kt @@ -6,9 +6,9 @@ import org.junitpioneer.jupiter.SetEnvironmentVariable class ConfigTest { @Test - @SetEnvironmentVariable(key = "FTL_SECRET_SECRETS_TEST", value = "testingtesting") + @SetEnvironmentVariable(key = "FTL_CONFIG_CONFIG_TEST", value = "testingtesting") fun testSecret() { - val secret = Secret("test") - assertEquals("testingtesting", secret.get()) + val config = Config.new("test") + assertEquals("testingtesting", config.get()) } } diff --git a/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/secrets/Secrets.kt b/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/secrets/Secret.kt similarity index 54% rename from kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/secrets/Secrets.kt rename to kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/secrets/Secret.kt index bfe1baf24..f0061589a 100644 --- a/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/secrets/Secrets.kt +++ b/kotlin-runtime/ftl-runtime/src/main/kotlin/xyz/block/ftl/secrets/Secret.kt @@ -2,9 +2,20 @@ package xyz.block.ftl.secrets import xyz.block.ftl.serializer.makeGson -class Secret(val name: String) { - val module: String - val gson = makeGson() +class Secret(private val cls: Class, private val name: String) { + private val module: String + private val gson = makeGson() + + companion object { + /** + * A convenience method for creating a new Secret. + * + *
+     *   val secret = Secret.new("test")
+     * 
+ * + */ + inline fun new(name: String): Secret = Secret(T::class.java, name) } init { val caller = Thread.currentThread().getStackTrace()[2].className @@ -13,9 +24,9 @@ class Secret(val name: String) { module = parts[parts.size - 2] } - inline fun get(): T { + fun get(): T { val key = "FTL_SECRET_${module.uppercase()}_${name.uppercase()}" val value = System.getenv(key) ?: throw Exception("Secret ${module}.${name} not found") - return gson.fromJson(value, T::class.java) + return gson.fromJson(value, cls) } } diff --git a/kotlin-runtime/ftl-runtime/src/test/kotlin/xyz/block/ftl/secrets/SecretTest.kt b/kotlin-runtime/ftl-runtime/src/test/kotlin/xyz/block/ftl/secrets/SecretTest.kt index ba3a0fd44..7dcaa3961 100644 --- a/kotlin-runtime/ftl-runtime/src/test/kotlin/xyz/block/ftl/secrets/SecretTest.kt +++ b/kotlin-runtime/ftl-runtime/src/test/kotlin/xyz/block/ftl/secrets/SecretTest.kt @@ -8,7 +8,7 @@ class SecretTest { @Test @SetEnvironmentVariable(key = "FTL_SECRET_SECRETS_TEST", value = "testingtesting") fun testSecret() { - val secret = Secret("test") + val secret = Secret.new("test") assertEquals("testingtesting", secret.get()) } } diff --git a/pom.xml b/pom.xml index 576444a43..0057db879 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 @@ -150,6 +150,12 @@ junit-jupiter-params test + + org.junit-pioneer + junit-pioneer + 2.2.0 + test +