@devkong/cli-nx 0.0.8 → 0.0.10
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
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files.eol": "\n",
|
|
3
3
|
"python.languageServer": "Pylance",
|
|
4
|
-
"python.formatting.provider": "none",
|
|
5
4
|
"[python]": {
|
|
6
5
|
"editor.defaultFormatter": "ms-python.black-formatter",
|
|
7
6
|
"editor.formatOnSave": true,
|
|
@@ -10,14 +9,10 @@
|
|
|
10
9
|
}
|
|
11
10
|
},
|
|
12
11
|
"isort.args": ["--profile", "black"],
|
|
13
|
-
"explorer.fileNesting.enabled": true,
|
|
14
|
-
"explorer.fileNesting.patterns": {
|
|
15
|
-
"config.json": "config.*.json"
|
|
16
|
-
},
|
|
17
12
|
"json.schemas": [
|
|
18
13
|
{
|
|
19
14
|
"fileMatch": ["**/kong.json"],
|
|
20
|
-
"url": "
|
|
15
|
+
"url": "http://kong.dev.re.app-dfi.net/kong-cli-schema.json"
|
|
21
16
|
}
|
|
22
17
|
],
|
|
23
18
|
"cSpell.words": [
|
|
@@ -32,12 +27,14 @@
|
|
|
32
27
|
"conint",
|
|
33
28
|
"contextlib",
|
|
34
29
|
"contextmanager",
|
|
30
|
+
"devkong",
|
|
35
31
|
"docparams",
|
|
36
32
|
"docstrings",
|
|
37
33
|
"elif",
|
|
38
34
|
"fstring",
|
|
39
35
|
"inlinevar",
|
|
40
36
|
"isort",
|
|
37
|
+
"libpeerconnection",
|
|
41
38
|
"metaclass",
|
|
42
39
|
"msvs",
|
|
43
40
|
"mymodule",
|
|
@@ -48,6 +45,8 @@
|
|
|
48
45
|
"optparse",
|
|
49
46
|
"overgeneral",
|
|
50
47
|
"parseable",
|
|
48
|
+
"protoeditor",
|
|
49
|
+
"pycache",
|
|
51
50
|
"pyenchant",
|
|
52
51
|
"pylint",
|
|
53
52
|
"pytest",
|
|
@@ -55,6 +54,9 @@
|
|
|
55
54
|
"rexec",
|
|
56
55
|
"rgxs",
|
|
57
56
|
"TERMIOS",
|
|
58
|
-
"
|
|
57
|
+
"testem",
|
|
58
|
+
"typevar",
|
|
59
|
+
"unittests",
|
|
60
|
+
"venv"
|
|
59
61
|
]
|
|
60
62
|
}
|
|
@@ -6,15 +6,15 @@ Welcome to the Kong extension development workspace!
|
|
|
6
6
|
|
|
7
7
|
Before you start, make sure you have the following installed:
|
|
8
8
|
|
|
9
|
-
- [Node.js](https://nodejs.org/en/download), version >= 20.0
|
|
9
|
+
- [Node.js](https://nodejs.org/en/download/prebuilt-installer), version >= 20.0
|
|
10
10
|
- [Python](https://www.python.org/downloads/), version >= 3.9
|
|
11
|
-
- [Docker](https://docs.docker.com/
|
|
11
|
+
- [Docker](https://docs.docker.com/desktop/)
|
|
12
12
|
|
|
13
13
|
To verify the installation and check the versions, run the following commands:
|
|
14
14
|
|
|
15
15
|
```shell script
|
|
16
16
|
node --version
|
|
17
|
-
python --version
|
|
17
|
+
python --version # or python3 --version
|
|
18
18
|
docker info
|
|
19
19
|
```
|
|
20
20
|
|
|
@@ -32,7 +32,7 @@ kong configure
|
|
|
32
32
|
kong install --verbose
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
That's it! Now, modify
|
|
35
|
+
That's it! Now, modify [main.py](./src/main.py), tag it by publishing a new version, and assign aliases for use in the workflow.
|
|
36
36
|
|
|
37
37
|
### Publish a New Version
|
|
38
38
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import sys
|
|
2
2
|
from typing import Optional
|
|
3
|
-
from uuid import UUID
|
|
4
3
|
|
|
5
4
|
from kong.sdk.app import App
|
|
6
5
|
from kong.sdk.kong_function import KongFunction
|
|
7
|
-
from pydantic import BaseModel,
|
|
6
|
+
from pydantic import BaseModel, Field
|
|
8
7
|
|
|
9
8
|
# This script is for developing an extension for Kong.
|
|
10
9
|
# For more details, please refer to the README.md file.
|
|
@@ -16,49 +15,52 @@ class InputData(BaseModel):
|
|
|
16
15
|
# sample objects in the UI, making it easier to work with the models.
|
|
17
16
|
# For more standard types, refer to: https://docs.pydantic.dev/latest/concepts/types/
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
examples=["Hello"],
|
|
21
|
-
description="A string",
|
|
22
|
-
)
|
|
18
|
+
# REPLACE BELLOW WITH YOUR FIELDS
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
examples=[
|
|
20
|
+
a: int = Field(
|
|
21
|
+
examples=[1],
|
|
26
22
|
description="An integer number",
|
|
27
23
|
)
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
description="An optional UUID field",
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
email_list: list[EmailStr] = Field(
|
|
36
|
-
examples=["one@example.com", "two@example.com"],
|
|
37
|
-
description="A list of emails",
|
|
25
|
+
b: int = Field(
|
|
26
|
+
examples=[2],
|
|
27
|
+
description="An integer number",
|
|
38
28
|
)
|
|
39
29
|
|
|
40
30
|
|
|
41
31
|
class OutputData(BaseModel):
|
|
42
32
|
# Define the structure of the output data that your extension will return.
|
|
43
33
|
|
|
44
|
-
|
|
34
|
+
# REPLACE BELLOW WITH YOUR FIELDS
|
|
35
|
+
|
|
36
|
+
sum_of: int = Field(
|
|
37
|
+
examples=[3],
|
|
38
|
+
description="Result of a + b",
|
|
39
|
+
)
|
|
45
40
|
|
|
41
|
+
comment: Optional[str] = Field(
|
|
42
|
+
examples=["This example extension returns sum of a and b"],
|
|
43
|
+
description="A string field",
|
|
44
|
+
)
|
|
46
45
|
|
|
47
|
-
class ExtensionTemplate(KongFunction):
|
|
48
|
-
# This is where you implement the logic to handle the input data and produce the output.
|
|
49
|
-
# Override the `handle` method to customize the processing of input data.
|
|
50
46
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
class MyExtension(KongFunction):
|
|
48
|
+
# This is where you implement the logic to handle the input data
|
|
49
|
+
# and produce the output.
|
|
54
50
|
|
|
55
|
-
|
|
51
|
+
# OVERRIDE BELLOW TO CUSTOMIZE THE PROCESSING.
|
|
52
|
+
|
|
53
|
+
async def handle(self, data: InputData) -> OutputData:
|
|
54
|
+
return OutputData(
|
|
55
|
+
sum_of=data.a + data.b,
|
|
56
|
+
comment=f"sum of {data.a} and {data.b}",
|
|
57
|
+
)
|
|
56
58
|
|
|
57
59
|
|
|
58
60
|
app = App(
|
|
59
61
|
InputData,
|
|
60
62
|
OutputData,
|
|
61
|
-
|
|
63
|
+
MyExtension,
|
|
62
64
|
)
|
|
63
65
|
|
|
64
66
|
if __name__ == "__main__":
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
from kong.sdk.conftest import ExtensionFixture
|
|
2
|
-
|
|
3
|
-
from src.main import ExtensionTemplate, InputData
|
|
2
|
+
from src.main import InputData, MyExtension
|
|
4
3
|
|
|
5
4
|
|
|
6
5
|
# The test function to validate the behavior of the extension
|
|
7
6
|
async def test_should_return_value_from_string_field_when_input_is_provided(
|
|
8
7
|
create_extension: ExtensionFixture,
|
|
9
8
|
):
|
|
10
|
-
extension = create_extension(
|
|
9
|
+
extension = create_extension(MyExtension, InputData)
|
|
11
10
|
|
|
12
11
|
# Prepare the input data
|
|
13
12
|
input_data = InputData(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
optional_field=None,
|
|
17
|
-
email_list=["one@example.com", "two@example.com"],
|
|
13
|
+
a=1,
|
|
14
|
+
b=2,
|
|
18
15
|
)
|
|
19
16
|
|
|
20
17
|
output = await extension.handle(input_data)
|
|
21
|
-
assert output.
|
|
18
|
+
assert output.sum_of == 3
|