-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathindex.ts
More file actions
75 lines (68 loc) · 1.64 KB
/
index.ts
File metadata and controls
75 lines (68 loc) · 1.64 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { z } from "zod";
import {
getUserBindingServiceName,
Plugin,
ProxyNodeBinding,
remoteProxyClientWorker,
RemoteProxyConnectionString,
} from "../shared";
const VpcNetworksSchema = z.object({
tunnel_id: z.string(),
remoteProxyConnectionString: z
.custom<RemoteProxyConnectionString>()
.optional(),
});
export const VpcNetworksOptionsSchema = z.object({
vpcNetworks: z.record(VpcNetworksSchema).optional(),
});
export const VPC_NETWORKS_PLUGIN_NAME = "vpc-networks";
export const VPC_NETWORKS_PLUGIN: Plugin<typeof VpcNetworksOptionsSchema> = {
options: VpcNetworksOptionsSchema,
async getBindings(options) {
if (!options.vpcNetworks) {
return [];
}
return Object.entries(options.vpcNetworks).map(
([name, { tunnel_id, remoteProxyConnectionString }]) => {
return {
name,
service: {
name: getUserBindingServiceName(
VPC_NETWORKS_PLUGIN_NAME,
tunnel_id,
remoteProxyConnectionString
),
},
};
}
);
},
getNodeBindings(options: z.infer<typeof VpcNetworksOptionsSchema>) {
if (!options.vpcNetworks) {
return {};
}
return Object.fromEntries(
Object.keys(options.vpcNetworks).map((name) => [
name,
new ProxyNodeBinding(),
])
);
},
async getServices({ options }) {
if (!options.vpcNetworks) {
return [];
}
return Object.entries(options.vpcNetworks).map(
([name, { tunnel_id, remoteProxyConnectionString }]) => {
return {
name: getUserBindingServiceName(
VPC_NETWORKS_PLUGIN_NAME,
tunnel_id,
remoteProxyConnectionString
),
worker: remoteProxyClientWorker(remoteProxyConnectionString, name),
};
}
);
},
};