@devkong/cli-nx 0.0.67-alpha.20 → 0.0.67-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/generators/preset/files/kotlin/src/main/kotlin/io/kong/extension/Main.kt +12 -1
- package/src/generators/preset/files/kotlin/src/main/kotlin/io/kong/extension/RegisterFrontend.kt +7 -0
- package/src/generators/preset/files/kotlin/src/test/kotlin/io/kong/extension/Test.kt +18 -0
- package/src/generators/preset/files/python-advanced/src/frontend.py +9 -1
- package/src/generators/preset/files/python-advanced/src/input_data.py +0 -7
- package/src/generators/preset/files/python-advanced/src/main_test.py +5 -12
package/package.json
CHANGED
|
@@ -62,10 +62,21 @@ class Main : KongFunction<InputData>(InputData::class.java) {
|
|
|
62
62
|
else -> throw IllegalArgumentException("Unsupported operation '$operation'")
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
var comment = "$operation result is $result"
|
|
66
|
+
|
|
67
|
+
// Example: resolve the credential the user selected for this step. It is optional here,
|
|
68
|
+
// so we use `find` (returns null when unset) instead of `get` (which throws). Cast
|
|
69
|
+
// `secret.data` to the type registered for "my-secret" in RegisterFrontend and use
|
|
70
|
+
// `(secret.data as MySecret).myKey` to authenticate outbound calls (never return it).
|
|
71
|
+
val secret = context.secret.find("primary")
|
|
72
|
+
if (secret != null) {
|
|
73
|
+
comment += " (authenticated)"
|
|
74
|
+
}
|
|
75
|
+
|
|
65
76
|
return jsonMapper.writeValueAsBytes(
|
|
66
77
|
OutputData(
|
|
67
78
|
result = result,
|
|
68
|
-
comment =
|
|
79
|
+
comment = comment,
|
|
69
80
|
),
|
|
70
81
|
)
|
|
71
82
|
}
|
package/src/generators/preset/files/kotlin/src/main/kotlin/io/kong/extension/RegisterFrontend.kt
CHANGED
|
@@ -3,10 +3,16 @@ package io.kong.extension
|
|
|
3
3
|
import com.fasterxml.jackson.databind.ObjectMapper
|
|
4
4
|
import io.kong.sdk.KongFrontend
|
|
5
5
|
import io.kong.sdk.KongFrontendBuilder
|
|
6
|
+
import io.quarkus.runtime.annotations.RegisterForReflection
|
|
6
7
|
import jakarta.enterprise.inject.Produces
|
|
7
8
|
import jakarta.inject.Inject
|
|
8
9
|
import jakarta.inject.Singleton
|
|
9
10
|
|
|
11
|
+
@RegisterForReflection
|
|
12
|
+
data class MySecret(
|
|
13
|
+
val myKey: String,
|
|
14
|
+
)
|
|
15
|
+
|
|
10
16
|
@Singleton
|
|
11
17
|
class RegisterFrontend {
|
|
12
18
|
@Inject
|
|
@@ -16,6 +22,7 @@ class RegisterFrontend {
|
|
|
16
22
|
@Produces
|
|
17
23
|
fun create(): KongFrontend =
|
|
18
24
|
KongFrontendBuilder()
|
|
25
|
+
.withSecretTypes("primary", "my-secret" to MySecret::class.java)
|
|
19
26
|
.withForm()
|
|
20
27
|
.build(jsonMapper)
|
|
21
28
|
}
|
|
@@ -37,4 +37,22 @@ class Test {
|
|
|
37
37
|
|
|
38
38
|
assertEquals(3, output.result)
|
|
39
39
|
}
|
|
40
|
+
|
|
41
|
+
@Test
|
|
42
|
+
fun `when a secret is provided then notes authentication`() =
|
|
43
|
+
runTest {
|
|
44
|
+
val input =
|
|
45
|
+
InputData(
|
|
46
|
+
request = KongFunctionRequest(operation = "sum"),
|
|
47
|
+
sum = OperationData(a = 1, b = 2),
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
val context =
|
|
51
|
+
testContext.create(secrets = mapOf("primary" to MySecret(myKey = "example-0123456789")))
|
|
52
|
+
val bytes = extension.handle(input, context)
|
|
53
|
+
val output = jsonMapper.readValue(bytes, OutputData::class.java)
|
|
54
|
+
|
|
55
|
+
assertEquals(3, output.result)
|
|
56
|
+
assertEquals("sum result is 3 (authenticated)", output.comment)
|
|
57
|
+
}
|
|
40
58
|
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
from input_data import MySecret
|
|
2
1
|
from kong.sdk.kong_frontend import KongFrontend, KongFrontendBuilder
|
|
2
|
+
from pydantic import BaseModel, Field
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class MySecret(BaseModel):
|
|
6
|
+
my_key: str = Field(
|
|
7
|
+
examples=["example-0123456789"],
|
|
8
|
+
description="An example of secret field",
|
|
9
|
+
)
|
|
10
|
+
|
|
3
11
|
|
|
4
12
|
frontend: KongFrontend = (
|
|
5
13
|
KongFrontendBuilder()
|
|
@@ -4,13 +4,6 @@ from kong.sdk.kong_function_request import KongFunctionRequest
|
|
|
4
4
|
from pydantic import BaseModel, Field
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
class MySecret(BaseModel):
|
|
8
|
-
my_key: str = Field(
|
|
9
|
-
examples=["example-0123456789"],
|
|
10
|
-
description="An example of secret field",
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
|
|
14
7
|
class OperationData(BaseModel):
|
|
15
8
|
a: int = Field(
|
|
16
9
|
examples=[1],
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
from frontend import frontend
|
|
1
|
+
from frontend import MySecret, frontend
|
|
4
2
|
from input_data import InputData, OperationData
|
|
5
3
|
from kong.sdk.conftest import ExtensionFixture, extension_test_context
|
|
6
4
|
from kong.sdk.kong_function_request import KongFunctionRequest
|
|
@@ -31,15 +29,10 @@ async def test_should_note_authentication_when_secret_is_provided(
|
|
|
31
29
|
sum=OperationData(a=1, b=2),
|
|
32
30
|
)
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
{"type": "my-secret", "data": {"my_key": "example-0123456789"}}
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
context = extension_test_context(frontend, secrets)
|
|
32
|
+
context = extension_test_context(
|
|
33
|
+
frontend,
|
|
34
|
+
{"primary": MySecret(my_key="example-0123456789")},
|
|
35
|
+
)
|
|
43
36
|
output = await extension.handle(input_data, context)
|
|
44
37
|
|
|
45
38
|
assert output.result == 3
|