Skip to content

Commit 8c4a0a6

Browse files
committed
Add AWS AppConfig API Data Source
Add an AWS AppConfig API Data Source with several query options. Not all are implemented, but most of the main ones are.
1 parent ffa595a commit 8c4a0a6

File tree

9 files changed

+2058
-1
lines changed

9 files changed

+2058
-1
lines changed

server/api-service/api-examples.http

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
### login?
2+
POST http://localhost:8080/api/auth/form/login
3+
Content-Type: application/json
4+
5+
{
6+
"register": false,
7+
"loginId": "[email protected]",
8+
"password": "test1234",
9+
"source": "EMAIL"
10+
}
11+
12+
### get apps
13+
GET http://localhost:8080/api/applications/list
14+
15+
### Send POST request with json body
16+
POST http://localhost:8080/api/applications
17+
Content-Type: application/json
18+
19+
{
20+
"orgId": "65ea883d248b9d61b5ec8eaf",
21+
"name": "testingapi2",
22+
"appUrlName": "thisIsASlug"
23+
}

server/node-service/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
},
3030
"dependencies": {
3131
"@apidevtools/swagger-parser": "^10.1.0",
32+
"@aws-sdk/client-appconfig": "^3.533.0",
33+
"@aws-sdk/client-appconfigdata": "^3.533.0",
3234
"@aws-sdk/client-athena": "^3.333.0",
3335
"@aws-sdk/client-dynamodb": "^3.332.0",
3436
"@aws-sdk/client-lambda": "^3.332.0",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { ConfigToType } from "lowcoder-sdk/dataSource";
2+
3+
const dataSourceConfig = {
4+
type: "dataSource",
5+
params: [
6+
{
7+
key: "region",
8+
type: "textInput",
9+
label: "Region",
10+
rules: [{ required: true, message: "Please input the AWS Region" }],
11+
defaultValue: "us-west-1",
12+
},
13+
{
14+
key: "accessKey",
15+
label: "Access key ID",
16+
type: "textInput",
17+
placeholder: "<Your Access key ID>",
18+
rules: [{ required: true, message: "Please input the Access Key ID" }],
19+
},
20+
{
21+
key: "secretKey",
22+
label: "Secret key",
23+
type: "password",
24+
rules: [{ required: true, message: "Please input the Secret Key" }],
25+
},
26+
],
27+
} as const;
28+
29+
export default dataSourceConfig;
30+
31+
export type DataSourceDataType = ConfigToType<typeof dataSourceConfig>;
Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
import {DataSourcePlugin} from "lowcoder-sdk/dataSource";
2+
import dataSourceConfig, {DataSourceDataType} from "./dataSourceConfig";
3+
import queryConfig, {ActionDataType} from "./queryConfig";
4+
import {
5+
AppConfigClient,
6+
CreateApplicationCommand,
7+
CreateConfigurationProfileCommand, CreateDeploymentStrategyCommand, CreateEnvironmentCommand,
8+
CreateHostedConfigurationVersionCommand,
9+
DeleteApplicationCommand,
10+
GetApplicationCommand,
11+
GetEnvironmentCommand, GrowthType,
12+
ListApplicationsCommand,
13+
ListConfigurationProfilesCommand,
14+
ListEnvironmentsCommand, ReplicateTo, StartDeploymentCommand,
15+
UpdateApplicationCommand,
16+
UpdateConfigurationProfileCommand
17+
} from "@aws-sdk/client-appconfig";
18+
import {
19+
AppConfigDataClient,
20+
GetLatestConfigurationCommand,
21+
StartConfigurationSessionCommand
22+
} from "@aws-sdk/client-appconfigdata";
23+
24+
25+
function getClient(dataSourceConfig: DataSourceDataType) {
26+
const {accessKey, secretKey, region} = dataSourceConfig;
27+
return new AppConfigClient({
28+
credentials: {
29+
accessKeyId: accessKey,
30+
secretAccessKey: secretKey,
31+
},
32+
region: region
33+
})
34+
}
35+
36+
function getAppConfigDataClient(dataSourceConfig: DataSourceDataType) {
37+
const {accessKey, secretKey, region} = dataSourceConfig;
38+
return new AppConfigDataClient({
39+
credentials: {
40+
accessKeyId: accessKey,
41+
secretAccessKey: secretKey,
42+
},
43+
region: region
44+
})
45+
}
46+
47+
const appConfigPlugin: DataSourcePlugin<ActionDataType, DataSourceDataType> = {
48+
id: "appconfig",
49+
name: "AppConfig",
50+
category: "api",
51+
icon: "appconfig.svg",
52+
dataSourceConfig,
53+
queryConfig,
54+
validateDataSourceConfig: async function (dataSourceConfig) {
55+
const client = getClient(dataSourceConfig);
56+
const ret = await client.send(new ListApplicationsCommand({}))
57+
return {
58+
success: Array.isArray(ret.Items),
59+
};
60+
},
61+
run: async function (actionData, dataSourceConfig): Promise<any> {
62+
const client = getClient(dataSourceConfig);
63+
const appConfigDataClient = getAppConfigDataClient(dataSourceConfig);
64+
let input;
65+
switch (actionData.actionName) {
66+
case "ListApplications":
67+
logger.info("AppConfig ListApplications")
68+
return await client.send(
69+
new ListApplicationsCommand({
70+
MaxResults: actionData.MaxResults || undefined,
71+
NextToken: actionData.NextToken || undefined,
72+
})
73+
);
74+
case "GetApplicationCommand":
75+
logger.info("AppConfig GetApplicationCommand")
76+
return await client.send(
77+
new GetApplicationCommand({
78+
ApplicationId: actionData.applicationId
79+
})
80+
)
81+
case "GetConfigurationCommand (Deprecated)":
82+
// input = { // GetConfigurationRequest
83+
// Application: "STRING_VALUE", // required
84+
// Environment: "STRING_VALUE", // required
85+
// Configuration: "STRING_VALUE", // required
86+
// ClientId: "STRING_VALUE", // required
87+
// ClientConfigurationVersion: "STRING_VALUE",
88+
// };
89+
// return await client.send(
90+
// new GetConfigurationCommand(input)
91+
// )
92+
break;
93+
case "GetLatestConfiguration":
94+
logger.info("AppConfig GetLatestConfiguration")
95+
let startConfigurationSessionInput = {
96+
ApplicationIdentifier: actionData.ApplicationIdentifier,
97+
EnvironmentIdentifier: actionData.EnvironmentIdentifier,
98+
ConfigurationProfileIdentifier: actionData.ConfigurationProfileIdentifier,
99+
RequiredMinimumPollIntervalInSeconds: actionData.RequiredMinimumPollIntervalInSeconds || undefined,
100+
};
101+
let session = await appConfigDataClient.send(new StartConfigurationSessionCommand(startConfigurationSessionInput))
102+
103+
input = {ConfigurationToken: session.InitialConfigurationToken,};
104+
let output = await appConfigDataClient.send(new GetLatestConfigurationCommand(input))
105+
var decodedConfiguration = new TextDecoder().decode(output.Configuration);
106+
return JSON.parse(decodedConfiguration)
107+
case "CreateApplicationCommand":
108+
logger.info("AppConfig CreateApplicationCommand")
109+
return await client.send(new CreateApplicationCommand({
110+
Description: actionData.Description,
111+
Name: actionData.Name,
112+
Tags: actionData.Tags
113+
}))
114+
case "StartConfigurationSession":
115+
logger.info("AppConfig StartConfigurationSession")
116+
{
117+
let startConfigurationSessionInput = {
118+
ApplicationIdentifier: actionData.ApplicationIdentifier,
119+
EnvironmentIdentifier: actionData.EnvironmentIdentifier,
120+
ConfigurationProfileIdentifier: actionData.ConfigurationProfileIdentifier,
121+
RequiredMinimumPollIntervalInSeconds: actionData.RequiredMinimumPollIntervalInSeconds || undefined,
122+
};
123+
return await appConfigDataClient.send(new StartConfigurationSessionCommand(startConfigurationSessionInput))
124+
}
125+
case "CreateConfigurationProfileCommand":
126+
logger.info("AppConfig CreateConfigurationProfileCommand")
127+
return await client.send(new CreateConfigurationProfileCommand({
128+
ApplicationId: actionData.ApplicationID,
129+
Description: actionData.Description,
130+
KmsKeyIdentifier: actionData.KmsKeyIdentifier || undefined,
131+
LocationUri: actionData.LocationUri,
132+
Name: actionData.Name,
133+
RetrievalRoleArn: actionData.RetrievalRoleArn || undefined,
134+
Tags: actionData.Tags,
135+
Type: actionData.Type,
136+
Validators: actionData.Validators
137+
}))
138+
case "CreateDeploymentStrategyCommand":
139+
logger.info("AppConfig CreateDeploymentStrategyCommand")
140+
return await client.send(new CreateDeploymentStrategyCommand({
141+
DeploymentDurationInMinutes: actionData.DeploymentDurationInMinutes,
142+
Description: actionData.Description,
143+
FinalBakeTimeInMinutes: actionData.FinalBakeTimeInMinutes,
144+
GrowthFactor: actionData.GrowthFactor,
145+
GrowthType: GrowthType[actionData.GrowthType as keyof typeof GrowthType],
146+
Name: actionData.Name,
147+
ReplicateTo: ReplicateTo[actionData.ReplicateTo as keyof typeof ReplicateTo],
148+
Tags: actionData.Tags,
149+
}))
150+
case "CreateEnvironmentCommand":
151+
logger.info("AppConfig CreateEnvironmentCommand")
152+
return await client.send(new CreateEnvironmentCommand({
153+
ApplicationId: actionData.ApplicationId,
154+
Description: actionData.Description,
155+
Monitors: actionData.Monitors,
156+
Name: actionData.Name,
157+
Tags: actionData.Tags,
158+
}))
159+
case "CreateExtensionAssociationCommand":
160+
logger.info("AppConfig CreateExtensionAssociationCommand")
161+
break;
162+
case "CreateExtensionCommand":
163+
logger.info("AppConfig CreateExtensionCommand")
164+
break;
165+
case "CreateHostedConfigurationVersionCommand":
166+
logger.info("AppConfig CreateHostedConfigurationVersionCommand")
167+
let content = new TextEncoder().encode(actionData.Content)
168+
return await client.send(new CreateHostedConfigurationVersionCommand({
169+
ApplicationId: actionData.ApplicationId,
170+
ConfigurationProfileId: actionData.ConfigurationProfileId,
171+
Content: content,
172+
ContentType: actionData.ContentType,
173+
Description: actionData.Description,
174+
LatestVersionNumber: actionData.LatestVersionNumber || undefined,
175+
VersionLabel: actionData.VersionLabel,
176+
}))
177+
case "DeleteApplicationCommand":
178+
logger.info("AppConfig DeleteApplicationCommand")
179+
return await client.send(new DeleteApplicationCommand({ApplicationId: actionData.applicationId}))
180+
case "DeleteConfigurationProfileCommand":
181+
logger.info("AppConfig DeleteConfigurationProfileCommand")
182+
break;
183+
case "DeleteDeploymentStrategyCommand":
184+
logger.info("AppConfig DeleteDeploymentStrategyCommand")
185+
break;
186+
case "DeleteEnvironmentCommand":
187+
logger.info("AppConfig DeleteEnvironmentCommand")
188+
break;
189+
case "DeleteExtensionAssociationCommand":
190+
logger.info("AppConfig DeleteExtensionAssociationCommand")
191+
break;
192+
case "DeleteExtensionCommand":
193+
logger.info("AppConfig DeleteExtensionCommand")
194+
break;
195+
case "DeleteHostedConfigurationVersionCommand":
196+
logger.info("AppConfig DeleteHostedConfigurationVersionCommand")
197+
break;
198+
case "GetConfigurationProfileCommand":
199+
logger.info("AppConfig GetConfigurationProfileCommand")
200+
break;
201+
case "GetDeploymentCommand":
202+
logger.info("AppConfig GetDeploymentCommand")
203+
break;
204+
case "GetDeploymentStrategyCommand":
205+
logger.info("AppConfig GetDeploymentStrategyCommand")
206+
break;
207+
case "GetEnvironmentCommand":
208+
logger.info("AppConfig GetEnvironmentCommand")
209+
return await client.send(new GetEnvironmentCommand({
210+
ApplicationId: actionData.ApplicationId,
211+
EnvironmentId: actionData.EnvironmentId,
212+
}))
213+
case "GetExtensionAssociationCommand":
214+
logger.info("AppConfig GetExtensionAssociationCommand")
215+
break;
216+
case "GetExtensionCommand":
217+
logger.info("AppConfig GetExtensionCommand")
218+
break;
219+
case "GetHostedConfigurationVersionCommand":
220+
logger.info("AppConfig GetHostedConfigurationVersionCommand")
221+
break;
222+
case "ListApplicationsCommand":
223+
logger.info("AppConfig ListApplicationsCommand")
224+
break;
225+
case "ListConfigurationProfilesCommand":
226+
logger.info("AppConfig ListConfigurationProfilesCommand")
227+
return await client.send(new ListConfigurationProfilesCommand({
228+
ApplicationId: actionData.ApplicationId,
229+
}))
230+
case "ListDeploymentStrategiesCommand":
231+
logger.info("AppConfig ListDeploymentStrategiesCommand")
232+
break;
233+
case "ListDeploymentsCommand":
234+
logger.info("AppConfig ListDeploymentsCommand")
235+
break;
236+
case "ListEnvironmentsCommand":
237+
logger.info("AppConfig ListEnvironmentsCommand")
238+
return await client.send(new ListEnvironmentsCommand({
239+
ApplicationId: actionData.ApplicationId
240+
}))
241+
case "ListExtensionAssociationsCommand":
242+
logger.info("AppConfig ListExtensionAssociationsCommand")
243+
break;
244+
case "ListExtensionsCommand":
245+
logger.info("AppConfig ListExtensionsCommand")
246+
break;
247+
case "ListHostedConfigurationVersionsCommand":
248+
logger.info("AppConfig ListHostedConfigurationVersionsCommand")
249+
break;
250+
case "ListTagsForResourceCommand":
251+
logger.info("AppConfig ListTagsForResourceCommand")
252+
break;
253+
case "StartDeploymentCommand":
254+
logger.info("AppConfig StartDeploymentCommand")
255+
return await client.send(new StartDeploymentCommand({
256+
ApplicationId: actionData.ApplicationId,
257+
ConfigurationProfileId: actionData.ConfigurationProfileId,
258+
ConfigurationVersion: actionData.ConfigurationVersion || undefined,
259+
DeploymentStrategyId: actionData.DeploymentStrategyId,
260+
Description: actionData.Description,
261+
DynamicExtensionParameters: actionData.DynamicExtensionParameters,
262+
EnvironmentId: actionData.EnvironmentId,
263+
KmsKeyIdentifier: actionData.KmsKeyIdentifier || undefined,
264+
Tags: actionData.Tags,
265+
}))
266+
case "StopDeploymentCommand":
267+
logger.info("AppConfig StopDeploymentCommand")
268+
break;
269+
case "TagResourceCommand":
270+
logger.info("AppConfig TagResourceCommand")
271+
break;
272+
case "UntagResourceCommand":
273+
logger.info("AppConfig UntagResourceCommand")
274+
break;
275+
case "UpdateApplicationCommand":
276+
logger.info("AppConfig UpdateApplicationCommand")
277+
return await client.send(new UpdateApplicationCommand({
278+
ApplicationId: actionData.ApplicationId,
279+
Name: actionData.Name,
280+
Description: actionData.Description,
281+
}))
282+
case "UpdateConfigurationProfileCommand":
283+
logger.info("AppConfig UpdateConfigurationProfileCommand")
284+
return await client.send(new UpdateConfigurationProfileCommand({
285+
ApplicationId: actionData.ApplicationId,
286+
ConfigurationProfileId: actionData.ConfigurationProfileId,
287+
Description: actionData.Description,
288+
KmsKeyIdentifier: actionData.KmsKeyIdentifier,
289+
Name: actionData.Name,
290+
RetrievalRoleArn: actionData.RetrievalRoleArn,
291+
Validators: actionData.Validators
292+
}))
293+
case "UpdateDeploymentStrategyCommand":
294+
logger.info("AppConfig UpdateDeploymentStrategyCommand")
295+
break;
296+
case "UpdateEnvironmentCommand":
297+
logger.info("AppConfig UpdateEnvironmentCommand")
298+
break;
299+
case "UpdateExtensionAssociationCommand":
300+
logger.info("AppConfig UpdateExtensionAssociationCommand")
301+
break;
302+
case "UpdateExtensionCommand":
303+
logger.info("AppConfig UpdateExtensionCommand")
304+
break;
305+
case "ValidateConfigurationCommand":
306+
logger.info("AppConfig ValidateConfigurationCommand")
307+
break;
308+
default:
309+
logger.info(`Unable to find action ${actionData}`)
310+
break;
311+
}
312+
}
313+
};
314+
315+
export default appConfigPlugin;

0 commit comments

Comments
 (0)