@devkong/cli-nx 0.0.67-alpha.2 → 0.0.67-alpha.20
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/.dockerignore +6 -0
- package/src/generators/preset/files/kotlin/.editorconfig +24 -0
- package/src/generators/preset/files/kotlin/.vscode/extensions.json +18 -0
- package/src/generators/preset/files/kotlin/.vscode/launch.json +16 -0
- package/src/generators/preset/files/kotlin/.vscode/settings.json +7 -0
- package/src/generators/preset/files/kotlin/.vscode/tasks.json +81 -0
- package/src/generators/preset/files/kotlin/Dockerfile +58 -0
- package/src/generators/preset/files/kotlin/README.md +165 -0
- package/src/generators/preset/files/kotlin/build.gradle.kts.template +64 -0
- package/src/generators/preset/files/kotlin/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/src/generators/preset/files/kotlin/gradle/wrapper/gradle-wrapper.properties +6 -0
- package/src/generators/preset/files/kotlin/gradle.properties +25 -0
- package/src/generators/preset/files/kotlin/gradlew +245 -0
- package/src/generators/preset/files/kotlin/gradlew.bat +92 -0
- package/src/generators/preset/files/kotlin/kong.json.template +6 -0
- package/src/generators/preset/files/kotlin/project.json.template +29 -0
- package/src/generators/preset/files/kotlin/settings.gradle.kts +14 -0
- package/src/generators/preset/files/kotlin/src/main/kotlin/io/kong/extension/InputData.kt +26 -0
- package/src/generators/preset/files/kotlin/src/main/kotlin/io/kong/extension/Main.kt +72 -0
- package/src/generators/preset/files/kotlin/src/main/kotlin/io/kong/extension/OutputData.kt +15 -0
- package/src/generators/preset/files/kotlin/src/main/kotlin/io/kong/extension/RegisterFrontend.kt +21 -0
- package/src/generators/preset/files/kotlin/src/main/resources/META-INF/resources/index.html +362 -0
- package/src/generators/preset/files/kotlin/src/main/resources/application.properties.template +3 -0
- package/src/generators/preset/files/kotlin/src/main/resources/reflect-config.json.template +1 -0
- package/src/generators/preset/files/kotlin/src/test/kotlin/io/kong/extension/Test.kt +40 -0
- package/src/generators/preset/files/python/.dockerignore +5 -0
- package/src/generators/preset/files/python/.editorconfig +16 -0
- package/src/generators/preset/files/python/.gitattributes +25 -0
- package/src/generators/preset/files/python/.gitignore.template +69 -0
- package/src/generators/preset/files/python/.idea/inspectionProfiles/Project_Default.xml +7 -0
- package/src/generators/preset/files/python/.idea/inspectionProfiles/profiles_settings.xml +6 -0
- package/src/generators/preset/files/python/.idea/kong-cli-python-template.iml +10 -0
- package/src/generators/preset/files/python/.pylintrc +543 -0
- package/src/generators/preset/files/python/.vscode/extensions.json +14 -0
- package/src/generators/preset/files/python/.vscode/launch.json +19 -0
- package/src/generators/preset/files/python/.vscode/settings.json +65 -0
- package/src/generators/preset/files/python/Dockerfile +30 -0
- package/src/generators/preset/files/python/README.md +255 -0
- package/src/generators/preset/files/python/kong.json.template +6 -0
- package/src/generators/preset/files/python/project.json.template +8 -0
- package/src/generators/preset/files/python/pyproject.toml +3 -0
- package/src/generators/preset/files/python/requirements-dev.txt +10 -0
- package/src/generators/preset/files/python/requirements.txt +2 -0
- package/src/generators/preset/files/python/src/__init__.py +0 -0
- package/src/generators/preset/files/python/src/frontend.py +3 -0
- package/src/generators/preset/files/python/src/input_data.py +13 -0
- package/src/generators/preset/files/python/src/main.py +28 -0
- package/src/generators/preset/files/python/src/main_test.py +19 -0
- package/src/generators/preset/files/python/src/output_data.py +15 -0
- package/src/generators/preset/files/python-advanced/src/frontend.py +9 -0
- package/src/generators/preset/files/python-advanced/src/input_data.py +47 -0
- package/src/generators/preset/files/python-advanced/src/main.py +51 -0
- package/src/generators/preset/files/python-advanced/src/main_test.py +46 -0
- package/src/generators/preset/files/python-advanced/src/output_data.py +16 -0
- package/src/generators/preset/generator.js +8 -0
- package/src/generators/preset/generator.js.map +1 -1
- package/src/generators/preset/schema.d.ts +7 -1
- package/src/generators/preset/schema.json +27 -2
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# Kong Extension
|
|
2
|
+
|
|
3
|
+
Welcome to the Kong extension development workspace!
|
|
4
|
+
|
|
5
|
+
To have a better experience, open this file in preview mode of your IDE.
|
|
6
|
+
|
|
7
|
+
### Prerequisites
|
|
8
|
+
|
|
9
|
+
Before you start, make sure you have the following installed depending on your OS:
|
|
10
|
+
|
|
11
|
+
[▶ Windows](#windows-setup)
|
|
12
|
+
|
|
13
|
+
[▶ Ubuntu](#ubuntu-setup)
|
|
14
|
+
|
|
15
|
+
[▶ macOS](#macos-setup)
|
|
16
|
+
|
|
17
|
+
To verify the installation and check the versions, run the following commands:
|
|
18
|
+
|
|
19
|
+
```shell script
|
|
20
|
+
node --version
|
|
21
|
+
docker info
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Getting Started
|
|
25
|
+
|
|
26
|
+
1. Make sure you're in the terminal and inside the extension folder you generated
|
|
27
|
+
2. Run the following commands in your terminal:
|
|
28
|
+
|
|
29
|
+
```shell script
|
|
30
|
+
# configure the base Kong URL (e.g., https://sandbox.kong.dev.app-dts.net)
|
|
31
|
+
kong configure
|
|
32
|
+
|
|
33
|
+
# install Python dependencies from requirements.txt
|
|
34
|
+
kong install --verbose
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Publish a New Version
|
|
38
|
+
|
|
39
|
+
To automatically tag your code with an incremented version number (e.g., 1, 2, 3), run:
|
|
40
|
+
|
|
41
|
+
```shell script
|
|
42
|
+
kong publish-version --verbose
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### List Available Versions
|
|
46
|
+
|
|
47
|
+
To see all available versions of your extension, run:
|
|
48
|
+
|
|
49
|
+
```shell script
|
|
50
|
+
kong list-versions
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Assign an Alias to a Version
|
|
54
|
+
|
|
55
|
+
You can assign an alias (e.g., stable, beta) to a specific version. This alias will appear in the UI as a separate step in the workflow. For example, to assign the alias stable to version 1, use:
|
|
56
|
+
|
|
57
|
+
```shell script
|
|
58
|
+
kong set-alias stable 1
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Using a Custom Profile
|
|
62
|
+
|
|
63
|
+
If you're developing an extension that will be used in different regions (or need to work with a specific profile), you can create a new profile using `kong configure`. Then, include the `--profile <name>` parameter when running the publish-version and set-alias commands to use the desired profile.
|
|
64
|
+
|
|
65
|
+
### Update CLI
|
|
66
|
+
|
|
67
|
+
To install the latest version of the CLI, run:
|
|
68
|
+
|
|
69
|
+
```shell script
|
|
70
|
+
npm i -g @devkong/cli@latest
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Setup
|
|
74
|
+
|
|
75
|
+
<details id="windows-setup">
|
|
76
|
+
<summary><strong>Windows</strong></summary>
|
|
77
|
+
|
|
78
|
+
### Install Windows Subsystem for Linux (WSL2)
|
|
79
|
+
|
|
80
|
+
1. Open PowerShell as Administrator.
|
|
81
|
+
2. Run the following command to install WSL and set WSL2 as the default version:
|
|
82
|
+
```powershell
|
|
83
|
+
wsl --install
|
|
84
|
+
```
|
|
85
|
+
3. Restart your computer if prompted.
|
|
86
|
+
4. After restarting, install a preferred Linux distribution (e.g., Ubuntu) by running:
|
|
87
|
+
```powershell
|
|
88
|
+
wsl --install -d Ubuntu
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Install Docker within WSL2
|
|
92
|
+
|
|
93
|
+
1. Download Docker Desktop for Windows from [Docker's official website](https://www.docker.com/products/docker-desktop).
|
|
94
|
+
2. Run the installer and follow the setup instructions.
|
|
95
|
+
3. During installation, ensure the "Use the WSL 2 based engine" option is selected.
|
|
96
|
+
4. Once installed, open Docker Desktop, go to Settings > General, and enable "Use WSL 2 based engine" if it isn't already enabled.
|
|
97
|
+
5. Confirm Docker is working in your WSL2 distribution (e.g., Ubuntu) by running:
|
|
98
|
+
```bash
|
|
99
|
+
docker --version
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Install Node.js and npm on Windows Host
|
|
103
|
+
|
|
104
|
+
1. Download the Node.js installer for Windows from the [official Node.js website](https://nodejs.org/).
|
|
105
|
+
2. Run the installer, making sure to include the npm package manager during installation.
|
|
106
|
+
3. Verify installation by opening a new Command Prompt and running:
|
|
107
|
+
```cmd
|
|
108
|
+
node -v
|
|
109
|
+
npm -v
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Install Python on Windows Host
|
|
113
|
+
|
|
114
|
+
1. Download the Python installer (version >= 3.10) for Windows from the [official Python website](https://www.python.org/downloads/windows/).
|
|
115
|
+
2. Run the installer, making sure to check "Add Python to PATH" during setup.
|
|
116
|
+
3. Verify installation by running:
|
|
117
|
+
```cmd
|
|
118
|
+
python --version
|
|
119
|
+
pip --version
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Install Poetry on Windows Host
|
|
123
|
+
|
|
124
|
+
1. Open Command Prompt or PowerShell.
|
|
125
|
+
2. Run the following command:
|
|
126
|
+
```powershell
|
|
127
|
+
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -
|
|
128
|
+
```
|
|
129
|
+
3. Add Poetry to your PATH:
|
|
130
|
+
```powershell
|
|
131
|
+
$env:Path += ";$env:USERPROFILE\.poetry\bin"
|
|
132
|
+
```
|
|
133
|
+
4. Verify installation:
|
|
134
|
+
```powershell
|
|
135
|
+
poetry --version
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
</details>
|
|
139
|
+
|
|
140
|
+
<details id="ubuntu-setup">
|
|
141
|
+
<summary><strong>Ubuntu</strong></summary>
|
|
142
|
+
|
|
143
|
+
### Install Docker
|
|
144
|
+
|
|
145
|
+
1. Follow the installation instructions on [Docker's official website](https://docs.docker.com/engine/install/ubuntu/).
|
|
146
|
+
2. Start Docker and enable it to start on boot:
|
|
147
|
+
```bash
|
|
148
|
+
sudo systemctl start docker
|
|
149
|
+
sudo systemctl enable docker
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Install Node.js and npm
|
|
153
|
+
|
|
154
|
+
1. Run the following commands:
|
|
155
|
+
```bash
|
|
156
|
+
sudo apt update
|
|
157
|
+
sudo apt install -y nodejs npm
|
|
158
|
+
```
|
|
159
|
+
2. Verify installation:
|
|
160
|
+
```bash
|
|
161
|
+
node -v
|
|
162
|
+
npm -v
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Install Python
|
|
166
|
+
|
|
167
|
+
1. Run the following commands:
|
|
168
|
+
```bash
|
|
169
|
+
sudo apt update
|
|
170
|
+
sudo apt install -y python3 python3-pip
|
|
171
|
+
```
|
|
172
|
+
2. Verify installation:
|
|
173
|
+
```bash
|
|
174
|
+
python3 --version
|
|
175
|
+
pip3 --version
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Install Poetry
|
|
179
|
+
|
|
180
|
+
1. Run the following command:
|
|
181
|
+
```bash
|
|
182
|
+
curl -sSL https://install.python-poetry.org | python3 -
|
|
183
|
+
```
|
|
184
|
+
2. Add Poetry to your PATH:
|
|
185
|
+
```bash
|
|
186
|
+
export PATH="$HOME/.local/bin:$PATH"
|
|
187
|
+
```
|
|
188
|
+
3. Reload the shell:
|
|
189
|
+
```bash
|
|
190
|
+
source ~/.bashrc
|
|
191
|
+
```
|
|
192
|
+
4. Verify installation:
|
|
193
|
+
```bash
|
|
194
|
+
poetry --version
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
</details>
|
|
198
|
+
|
|
199
|
+
<details id="macos-setup">
|
|
200
|
+
<summary><strong>macOS</strong></summary>
|
|
201
|
+
|
|
202
|
+
To emulate a Linux platform, you need to install Rosetta:
|
|
203
|
+
|
|
204
|
+
```shell script
|
|
205
|
+
softwareupdate --install-rosetta
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Install Docker
|
|
209
|
+
|
|
210
|
+
1. Download and install Docker Desktop for Mac from [Docker's official website](https://www.docker.com/products/docker-desktop).
|
|
211
|
+
|
|
212
|
+
### Install Node.js and npm
|
|
213
|
+
|
|
214
|
+
1. Use Homebrew to install:
|
|
215
|
+
```bash
|
|
216
|
+
brew install node
|
|
217
|
+
```
|
|
218
|
+
2. Verify installation:
|
|
219
|
+
```bash
|
|
220
|
+
node -v
|
|
221
|
+
npm -v
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Install Python
|
|
225
|
+
|
|
226
|
+
1. Use Homebrew to install:
|
|
227
|
+
```bash
|
|
228
|
+
brew install python
|
|
229
|
+
```
|
|
230
|
+
2. Verify installation:
|
|
231
|
+
```bash
|
|
232
|
+
python3 --version
|
|
233
|
+
pip3 --version
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Install Poetry
|
|
237
|
+
|
|
238
|
+
1. Run the following command:
|
|
239
|
+
```bash
|
|
240
|
+
curl -sSL https://install.python-poetry.org | python3 -
|
|
241
|
+
```
|
|
242
|
+
2. Add Poetry to your PATH:
|
|
243
|
+
```bash
|
|
244
|
+
export PATH="$HOME/.local/bin:$PATH"
|
|
245
|
+
```
|
|
246
|
+
3. Reload the shell:
|
|
247
|
+
```bash
|
|
248
|
+
source ~/.bashrc
|
|
249
|
+
```
|
|
250
|
+
4. Verify installation:
|
|
251
|
+
```bash
|
|
252
|
+
poetry --version
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
</details>
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
from kong.sdk.app import App
|
|
4
|
+
from kong.sdk.kong_function import KongFunction
|
|
5
|
+
from kong.sdk.kong_function_context import KongFunctionContext
|
|
6
|
+
|
|
7
|
+
from frontend import frontend
|
|
8
|
+
from input_data import InputData
|
|
9
|
+
from output_data import OutputData
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Main(KongFunction):
|
|
13
|
+
async def handle(self, data: InputData, context: KongFunctionContext) -> OutputData:
|
|
14
|
+
return OutputData(
|
|
15
|
+
sum_of=data.a + data.b,
|
|
16
|
+
comment=f"sum of {data.a} and {data.b}",
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
app = App(
|
|
21
|
+
InputData,
|
|
22
|
+
OutputData,
|
|
23
|
+
Main,
|
|
24
|
+
frontend,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
if __name__ == "__main__":
|
|
28
|
+
app.run(sys.argv)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from kong.sdk.conftest import ExtensionFixture, extension_test_context
|
|
2
|
+
|
|
3
|
+
from frontend import frontend
|
|
4
|
+
from input_data import InputData
|
|
5
|
+
from main import Main
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
async def test_should_return_value_from_string_field_when_input_is_provided(
|
|
9
|
+
create_extension: ExtensionFixture,
|
|
10
|
+
):
|
|
11
|
+
extension = create_extension(Main, InputData)
|
|
12
|
+
|
|
13
|
+
input_data = InputData(
|
|
14
|
+
a=1,
|
|
15
|
+
b=2,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
output = await extension.handle(input_data, extension_test_context(frontend))
|
|
19
|
+
assert output.sum_of == 3
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class OutputData(BaseModel):
|
|
7
|
+
sum_of: int = Field(
|
|
8
|
+
examples=[3],
|
|
9
|
+
description="Result of a + b",
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
comment: Optional[str] = Field(
|
|
13
|
+
examples=["This example extension returns sum of a and b"],
|
|
14
|
+
description="A string field",
|
|
15
|
+
)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from kong.sdk.kong_function_request import KongFunctionRequest
|
|
4
|
+
from pydantic import BaseModel, Field
|
|
5
|
+
|
|
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
|
+
class OperationData(BaseModel):
|
|
15
|
+
a: int = Field(
|
|
16
|
+
examples=[1],
|
|
17
|
+
description="An integer number",
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
b: int = Field(
|
|
21
|
+
examples=[2],
|
|
22
|
+
description="An integer number",
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class InputData(BaseModel):
|
|
27
|
+
request: KongFunctionRequest
|
|
28
|
+
|
|
29
|
+
sum: Optional[OperationData] = Field(
|
|
30
|
+
default=None,
|
|
31
|
+
description="Operands for the 'sum' operation",
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
sub: Optional[OperationData] = Field(
|
|
35
|
+
default=None,
|
|
36
|
+
description="Operands for the 'sub' operation",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
multiply: Optional[OperationData] = Field(
|
|
40
|
+
default=None,
|
|
41
|
+
description="Operands for the 'multiply' operation",
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
divide: Optional[OperationData] = Field(
|
|
45
|
+
default=None,
|
|
46
|
+
description="Operands for the 'divide' operation",
|
|
47
|
+
)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
from frontend import frontend
|
|
4
|
+
from input_data import InputData, OperationData
|
|
5
|
+
from kong.sdk.app import App
|
|
6
|
+
from kong.sdk.kong_function import KongFunction
|
|
7
|
+
from kong.sdk.kong_function_context import KongFunctionContext
|
|
8
|
+
from output_data import OutputData
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Main(KongFunction):
|
|
12
|
+
async def handle(self, data: InputData, context: KongFunctionContext) -> OutputData:
|
|
13
|
+
operation = data.request.operation
|
|
14
|
+
operands = getattr(data, operation, None)
|
|
15
|
+
if not isinstance(operands, OperationData):
|
|
16
|
+
raise ValueError(f"Missing or unsupported operation '{operation}'")
|
|
17
|
+
|
|
18
|
+
if operation == "sum":
|
|
19
|
+
result = operands.a + operands.b
|
|
20
|
+
elif operation == "sub":
|
|
21
|
+
result = operands.a - operands.b
|
|
22
|
+
elif operation == "multiply":
|
|
23
|
+
result = operands.a * operands.b
|
|
24
|
+
elif operation == "divide":
|
|
25
|
+
if operands.b == 0:
|
|
26
|
+
raise ValueError("Cannot divide by zero")
|
|
27
|
+
result = operands.a // operands.b
|
|
28
|
+
else:
|
|
29
|
+
raise ValueError(f"Unsupported operation '{operation}'")
|
|
30
|
+
|
|
31
|
+
comment = f"{operation} result is {result}"
|
|
32
|
+
|
|
33
|
+
secret = context.secret.find("primary")
|
|
34
|
+
if secret is not None:
|
|
35
|
+
comment += " (authenticated)"
|
|
36
|
+
|
|
37
|
+
return OutputData(
|
|
38
|
+
result=result,
|
|
39
|
+
comment=comment,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
app = App(
|
|
44
|
+
InputData,
|
|
45
|
+
OutputData,
|
|
46
|
+
Main,
|
|
47
|
+
frontend,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
app.run(sys.argv)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
from frontend import frontend
|
|
4
|
+
from input_data import InputData, OperationData
|
|
5
|
+
from kong.sdk.conftest import ExtensionFixture, extension_test_context
|
|
6
|
+
from kong.sdk.kong_function_request import KongFunctionRequest
|
|
7
|
+
from main import Main
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
async def test_should_add_operands_when_operation_is_sum(
|
|
11
|
+
create_extension: ExtensionFixture,
|
|
12
|
+
):
|
|
13
|
+
extension = create_extension(Main, InputData)
|
|
14
|
+
|
|
15
|
+
input_data = InputData(
|
|
16
|
+
request=KongFunctionRequest(operation="sum"),
|
|
17
|
+
sum=OperationData(a=1, b=2),
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
output = await extension.handle(input_data, extension_test_context(frontend))
|
|
21
|
+
assert output.result == 3
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
async def test_should_note_authentication_when_secret_is_provided(
|
|
25
|
+
create_extension: ExtensionFixture,
|
|
26
|
+
):
|
|
27
|
+
extension = create_extension(Main, InputData)
|
|
28
|
+
|
|
29
|
+
input_data = InputData(
|
|
30
|
+
request=KongFunctionRequest(operation="sum"),
|
|
31
|
+
sum=OperationData(a=1, b=2),
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
# Secrets arrive as a `{"type", "data"}` JSON envelope keyed by purpose, exactly
|
|
35
|
+
# as the executor materializes them at runtime.
|
|
36
|
+
secrets = {
|
|
37
|
+
"primary": json.dumps(
|
|
38
|
+
{"type": "my-secret", "data": {"my_key": "example-0123456789"}}
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
context = extension_test_context(frontend, secrets)
|
|
43
|
+
output = await extension.handle(input_data, context)
|
|
44
|
+
|
|
45
|
+
assert output.result == 3
|
|
46
|
+
assert output.comment == "sum result is 3 (authenticated)"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class OutputData(BaseModel):
|
|
7
|
+
result: int = Field(
|
|
8
|
+
examples=[3],
|
|
9
|
+
description="Result of applying the operation to a and b",
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
comment: Optional[str] = Field(
|
|
13
|
+
default=None,
|
|
14
|
+
examples=["sum result is 3"],
|
|
15
|
+
description="A string field",
|
|
16
|
+
)
|
|
@@ -6,6 +6,7 @@ const devkit_1 = require("@nx/devkit");
|
|
|
6
6
|
const path = tslib_1.__importStar(require("path"));
|
|
7
7
|
function presetGenerator(tree, options) {
|
|
8
8
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
9
|
+
var _a;
|
|
9
10
|
const projectRoot = ".";
|
|
10
11
|
const projectName = "";
|
|
11
12
|
(0, devkit_1.addProjectConfiguration)(tree, projectName, {
|
|
@@ -13,7 +14,14 @@ function presetGenerator(tree, options) {
|
|
|
13
14
|
projectType: "application",
|
|
14
15
|
});
|
|
15
16
|
options.os = process.platform;
|
|
17
|
+
options.variant = (_a = options.variant) !== null && _a !== void 0 ? _a : "basic";
|
|
16
18
|
(0, devkit_1.generateFiles)(tree, path.join(__dirname, `files/${options.platform}`), "", options);
|
|
19
|
+
// The python preset ships a "basic" (single sum) and an "advanced" (multi-operation
|
|
20
|
+
// + secret example) template. The advanced sources are layered on top of the shared
|
|
21
|
+
// base, overwriting the basic src/*.py files.
|
|
22
|
+
if (options.platform === "python" && options.variant === "advanced") {
|
|
23
|
+
(0, devkit_1.generateFiles)(tree, path.join(__dirname, "files/python-advanced"), "", options);
|
|
24
|
+
}
|
|
17
25
|
yield (0, devkit_1.formatFiles)(tree);
|
|
18
26
|
try {
|
|
19
27
|
const gradlewPath = (0, devkit_1.joinPathFragments)(projectRoot, "gradlew");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../src/generators/preset/generator.ts"],"names":[],"mappings":";;AAUA,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../src/generators/preset/generator.ts"],"names":[],"mappings":";;AAUA,0CA6BC;;AAvCD,uCAMoB;AACpB,mDAA6B;AAG7B,SAAsB,eAAe,CAAC,IAAU,EAAE,OAA8B;;;QAC9E,MAAM,WAAW,GAAG,GAAG,CAAC;QACxB,MAAM,WAAW,GAAG,EAAE,CAAC;QACvB,IAAA,gCAAuB,EAAC,IAAI,EAAE,WAAW,EAAE;YACzC,IAAI,EAAE,WAAW;YACjB,WAAW,EAAE,aAAa;SAC3B,CAAC,CAAC;QAEH,OAAO,CAAC,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;QAC9B,OAAO,CAAC,OAAO,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,OAAO,CAAC;QAC7C,IAAA,sBAAa,EAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QAEpF,oFAAoF;QACpF,oFAAoF;QACpF,8CAA8C;QAC9C,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,IAAI,OAAO,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;YACpE,IAAA,sBAAa,EAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,uBAAuB,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QAClF,CAAC;QAED,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;QAExB,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,IAAA,0BAAiB,EAAC,WAAW,EAAE,SAAS,CAAC,CAAC;YAC9D,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC7B,IAAI,CAAC,iBAAiB,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC,YAAY;YAC1D,CAAC;QACH,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,OAAO,CAAC,IAAI,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;CAAA;AAED,kBAAe,eAAe,CAAC"}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export interface PresetGeneratorSchema {
|
|
2
2
|
name: string;
|
|
3
|
-
|
|
3
|
+
// Extension id, forwarded by the CLI and rendered into kong.json.
|
|
4
|
+
id?: string;
|
|
5
|
+
// Set by the generator at runtime from `process.platform`.
|
|
6
|
+
os?: string;
|
|
4
7
|
platform: "python" | "kotlin";
|
|
8
|
+
// Which starter template to scaffold. Only the python preset currently ships more
|
|
9
|
+
// than "basic"; "advanced" adds the multi-operation + secret example variant.
|
|
10
|
+
variant?: "basic" | "advanced";
|
|
5
11
|
}
|
|
@@ -21,7 +21,32 @@
|
|
|
21
21
|
"index": 1
|
|
22
22
|
},
|
|
23
23
|
"x-prompt": "What platform would you like to use?"
|
|
24
|
+
},
|
|
25
|
+
"variant": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"description": "Which starter template to scaffold",
|
|
28
|
+
"enum": [
|
|
29
|
+
"basic",
|
|
30
|
+
"advanced"
|
|
31
|
+
],
|
|
32
|
+
"default": "basic",
|
|
33
|
+
"x-prompt": {
|
|
34
|
+
"message": "Which template would you like to use?",
|
|
35
|
+
"type": "list",
|
|
36
|
+
"items": [
|
|
37
|
+
{
|
|
38
|
+
"value": "basic",
|
|
39
|
+
"label": "basic - a single operation"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"value": "advanced",
|
|
43
|
+
"label": "advanced - multiple operations with a secret example"
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}
|
|
24
47
|
}
|
|
25
48
|
},
|
|
26
|
-
"required": [
|
|
27
|
-
|
|
49
|
+
"required": [
|
|
50
|
+
"name"
|
|
51
|
+
]
|
|
52
|
+
}
|