@devkong/cli-nx 0.0.67-alpha.11 → 0.0.67-alpha.12
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 +54 -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 +12 -0
- package/src/generators/preset/files/kotlin/src/main/kotlin/io/kong/extension/InputData.kt +34 -0
- package/src/generators/preset/files/kotlin/src/main/kotlin/io/kong/extension/Main.kt +77 -0
- package/src/generators/preset/files/kotlin/src/main/kotlin/io/kong/extension/OutputData.kt +17 -0
- package/src/generators/preset/files/kotlin/src/main/kotlin/io/kong/extension/RegisterKongFrontend.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 +55 -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 +547 -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 +62 -0
- package/src/generators/preset/files/python/Dockerfile +13 -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 +20 -0
- package/src/generators/preset/files/python/src/main.py +37 -0
- package/src/generators/preset/files/python/src/main_test.py +21 -0
- package/src/generators/preset/files/python/src/output_data.py +19 -0
- package/src/generators/preset/generator.js +7 -0
- package/src/generators/preset/generator.js.map +1 -1
|
@@ -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,20 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class InputData(BaseModel):
|
|
5
|
+
# Define the structure of the input data that your extension will accept.
|
|
6
|
+
# Be sure to include example values for each field. These examples help generate
|
|
7
|
+
# sample objects in the UI, making it easier to work with the models.
|
|
8
|
+
# For more standard types, refer to: https://docs.pydantic.dev/latest/concepts/types/
|
|
9
|
+
|
|
10
|
+
# REPLACE BELLOW WITH YOUR FIELDS
|
|
11
|
+
|
|
12
|
+
a: int = Field(
|
|
13
|
+
examples=[1],
|
|
14
|
+
description="An integer number",
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
b: int = Field(
|
|
18
|
+
examples=[2],
|
|
19
|
+
description="An integer number",
|
|
20
|
+
)
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
# This script is for developing an extension for Kong.
|
|
12
|
+
# For more details, please refer to the README.md file.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Main(KongFunction):
|
|
16
|
+
# This is where you implement the logic to handle the input data
|
|
17
|
+
# and produce the output.
|
|
18
|
+
|
|
19
|
+
# OVERRIDE BELLOW TO CUSTOMIZE THE PROCESSING.
|
|
20
|
+
|
|
21
|
+
async def handle(self, data: InputData, context: KongFunctionContext) -> OutputData:
|
|
22
|
+
# `context.secret.get("<purpose>")` resolves secrets declared in frontend.py.
|
|
23
|
+
return OutputData(
|
|
24
|
+
sum_of=data.a + data.b,
|
|
25
|
+
comment=f"sum of {data.a} and {data.b}",
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
app = App(
|
|
30
|
+
InputData,
|
|
31
|
+
OutputData,
|
|
32
|
+
Main,
|
|
33
|
+
frontend,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
app.run(sys.argv)
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
# The test function to validate the behavior of the extension
|
|
9
|
+
async def test_should_return_value_from_string_field_when_input_is_provided(
|
|
10
|
+
create_extension: ExtensionFixture,
|
|
11
|
+
):
|
|
12
|
+
extension = create_extension(Main, InputData)
|
|
13
|
+
|
|
14
|
+
# Prepare the input data
|
|
15
|
+
input_data = InputData(
|
|
16
|
+
a=1,
|
|
17
|
+
b=2,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
output = await extension.handle(input_data, extension_test_context(frontend))
|
|
21
|
+
assert output.sum_of == 3
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class OutputData(BaseModel):
|
|
7
|
+
# Define the structure of the output data that your extension will return.
|
|
8
|
+
|
|
9
|
+
# REPLACE BELLOW WITH YOUR FIELDS
|
|
10
|
+
|
|
11
|
+
sum_of: int = Field(
|
|
12
|
+
examples=[3],
|
|
13
|
+
description="Result of a + b",
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
comment: Optional[str] = Field(
|
|
17
|
+
examples=["This example extension returns sum of a and b"],
|
|
18
|
+
description="A string field",
|
|
19
|
+
)
|
|
@@ -12,6 +12,13 @@ function presetGenerator(tree, options) {
|
|
|
12
12
|
root: projectRoot,
|
|
13
13
|
projectType: "application",
|
|
14
14
|
});
|
|
15
|
+
// Disable Nx usage analytics by default so `kong generate` never prompts the
|
|
16
|
+
// user. They can opt back in later via "analytics" in the generated nx.json.
|
|
17
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
18
|
+
if (nxJson) {
|
|
19
|
+
nxJson.analytics = false;
|
|
20
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
21
|
+
}
|
|
15
22
|
options.os = process.platform;
|
|
16
23
|
(0, devkit_1.generateFiles)(tree, path.join(__dirname, `files/${options.platform}`), "", options);
|
|
17
24
|
yield (0, devkit_1.formatFiles)(tree);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../src/generators/preset/generator.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../src/generators/preset/generator.ts"],"names":[],"mappings":";;AAYA,0CA4BC;;AAxCD,uCAQoB;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,6EAA6E;QAC7E,6EAA6E;QAC7E,MAAM,MAAM,GAAG,IAAA,mBAAU,EAAC,IAAI,CAAC,CAAC;QAChC,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC;YACzB,IAAA,qBAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC7B,CAAC;QAED,OAAO,CAAC,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;QAC9B,IAAA,sBAAa,EAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QACpF,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"}
|