-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathautocomplete.js
54 lines (47 loc) · 1.53 KB
/
autocomplete.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const { autocomplete } = require("@kaholo/aws-plugin-library");
const { DescribeInstanceTypeOfferingsCommand, DescribeSubnetsCommand } = require("@aws-sdk/client-ec2");
const { createSubnetText } = require("./helpers");
async function getInstanceTypes(query, params, client, region) {
const payload = {
Filters: [{
Name: "location",
Values: [region],
}],
};
const {
InstanceTypeOfferings: instanceTypes,
} = await client.send(new DescribeInstanceTypeOfferingsCommand(payload));
const autocompleteItems = instanceTypes.map((type) => (
autocomplete.toAutocompleteItemFromPrimitive(type.InstanceType)
));
const lowerCaseQuery = query.toLowerCase();
const filteredItems = autocompleteItems.filter(({ id, value }) => (
id.toLowerCase().includes(lowerCaseQuery)
|| value.toLowerCase().includes(lowerCaseQuery)
));
return filteredItems;
}
async function listSubnets(query, params, client) {
const payload = {};
if (params.vpcId) {
payload.Filters = [
{
Name: "vpc-id",
Values: [params.vpcId],
},
];
}
const subnets = await client.send(new DescribeSubnetsCommand(payload));
return subnets.Subnets.filter(
(subnet) => subnet.VpcId.includes(query)
|| subnet.AvailabilityZone.includes(query)
|| subnet.SubnetId.includes(query),
).map((subnet) => (
autocomplete.toAutocompleteItemFromPrimitive(subnet.SubnetId, createSubnetText(subnet))
));
}
module.exports = {
listSubnets,
getInstanceTypes,
listRegions: autocomplete.listRegions,
};