@highstate/library 0.21.1 → 0.26.0

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.
Files changed (58) hide show
  1. package/dist/highstate.library.msgpack +0 -0
  2. package/dist/index.js +3934 -1838
  3. package/package.json +3 -3
  4. package/src/abbreviations.ts +2 -0
  5. package/src/apps/index.ts +1 -0
  6. package/src/apps/vault.ts +374 -0
  7. package/src/common/access-point.ts +152 -9
  8. package/src/common/filter.ts +40 -0
  9. package/src/common/index.ts +1 -0
  10. package/src/common/server.ts +131 -1
  11. package/src/databases/etcd.ts +12 -4
  12. package/src/databases/index.ts +1 -0
  13. package/src/databases/minio.ts +19 -0
  14. package/src/databases/mongodb.ts +12 -4
  15. package/src/databases/mysql.ts +12 -4
  16. package/src/databases/postgresql.ts +12 -4
  17. package/src/databases/rustfs.ts +169 -0
  18. package/src/dns.ts +3 -3
  19. package/src/index.ts +3 -2
  20. package/src/k3s.ts +129 -3
  21. package/src/k8s/apps/envoy-gateway.ts +50 -0
  22. package/src/k8s/apps/etcd.ts +1 -1
  23. package/src/k8s/apps/grafana.ts +1 -1
  24. package/src/k8s/apps/index.ts +4 -0
  25. package/src/k8s/apps/mariadb.ts +1 -1
  26. package/src/k8s/apps/matrix-stack.ts +2 -1
  27. package/src/k8s/apps/minio.ts +2 -2
  28. package/src/k8s/apps/mongodb.ts +1 -1
  29. package/src/k8s/apps/postgresql.ts +1 -1
  30. package/src/k8s/apps/rustfs.ts +119 -0
  31. package/src/k8s/apps/shared.ts +16 -1
  32. package/src/k8s/apps/signoz.ts +32 -0
  33. package/src/k8s/apps/traefik.ts +5 -5
  34. package/src/k8s/apps/valkey.ts +1 -1
  35. package/src/k8s/apps/vault.ts +113 -0
  36. package/src/k8s/apps/vaultwarden.ts +31 -2
  37. package/src/k8s/apps/workload.ts +12 -14
  38. package/src/k8s/cert-manager.ts +44 -2
  39. package/src/k8s/cilium.ts +3 -16
  40. package/src/k8s/coredns.ts +62 -0
  41. package/src/k8s/gateway.ts +25 -0
  42. package/src/k8s/index.ts +1 -0
  43. package/src/k8s/scheduling.ts +87 -0
  44. package/src/k8s/service-args.ts +109 -0
  45. package/src/k8s/shared.ts +26 -0
  46. package/src/k8s/workload.ts +21 -0
  47. package/src/netaminity.ts +950 -0
  48. package/src/network/endpoint.ts +12 -1
  49. package/src/network/index.ts +1 -0
  50. package/src/network/network.ts +58 -0
  51. package/src/restic.ts +2 -1
  52. package/src/ssh.ts +27 -0
  53. package/src/third-party/gcp.ts +427 -0
  54. package/src/third-party/index.ts +1 -0
  55. package/src/third-party/yandex.ts +210 -1
  56. package/src/tls.ts +135 -6
  57. package/src/utils.ts +16 -1
  58. package/src/wireguard.ts +257 -4
@@ -18,6 +18,7 @@ import {
18
18
  type l7AppInfoSchema,
19
19
  l7EndpointSchema,
20
20
  } from "./endpoint-schema"
21
+ import { networkEntity } from "./network"
21
22
  import { subnetEntity } from "./subnet"
22
23
 
23
24
  /**
@@ -48,6 +49,16 @@ export const l3EndpointEntity = defineEntity({
48
49
  entity: addressEntity,
49
50
  required: false,
50
51
  },
52
+
53
+ /**
54
+ * The optional network to which the endpoint belongs.
55
+ *
56
+ * Can be set for both IP and hostname endpoints.
57
+ */
58
+ network: {
59
+ entity: networkEntity,
60
+ required: false,
61
+ },
51
62
  },
52
63
 
53
64
  schema: l3EndpointSchema,
@@ -114,7 +125,7 @@ export const endpointArgs = $args({
114
125
  *
115
126
  * Can be used to filter them (for example, by environment, region, etc.).
116
127
  */
117
- metadata: metadataSchema,
128
+ metadata: metadataSchema.default({}),
118
129
  })
119
130
 
120
131
  /**
@@ -3,4 +3,5 @@ export * from "./address-space"
3
3
  export * from "./endpoint"
4
4
  export * from "./endpoint-container"
5
5
  export * from "./endpoint-schema"
6
+ export * from "./network"
6
7
  export * from "./subnet"
@@ -0,0 +1,58 @@
1
+ import { defineEntity, defineUnit, z } from "@highstate/contract"
2
+ import { entityMetaArgsSchema } from "../utils"
3
+ import { addressSpaceEntity } from "./address-space"
4
+
5
+ export const networkEntity = defineEntity({
6
+ type: "network.v1",
7
+
8
+ schema: z.unknown(),
9
+
10
+ extends: { addressSpaceEntity },
11
+ })
12
+
13
+ export const network = defineUnit({
14
+ type: "network.v1",
15
+
16
+ args: {
17
+ /**
18
+ * The custom identity string of the network.
19
+ * Will be used to generate its ID which itself will be used to compare network entities.
20
+ *
21
+ * If not provided, the ID of the unit state will be used as identity string.
22
+ */
23
+ identity: z.string().optional(),
24
+
25
+ /**
26
+ * The subnets that belong to the network.
27
+ */
28
+ subnets: z.string().array().default([]),
29
+
30
+ /**
31
+ * The custom meta for the network entity.
32
+ */
33
+ entityMeta: entityMetaArgsSchema,
34
+ },
35
+
36
+ inputs: {
37
+ /**
38
+ * The subnets that belong to the network.
39
+ */
40
+ subnets: {
41
+ entity: networkEntity,
42
+ multiple: true,
43
+ required: false,
44
+ },
45
+ },
46
+
47
+ outputs: {
48
+ /**
49
+ * The network entity itself.
50
+ */
51
+ network: networkEntity,
52
+ },
53
+
54
+ source: {
55
+ package: "@highstate/common",
56
+ path: "units/network/network",
57
+ },
58
+ })
package/src/restic.ts CHANGED
@@ -3,6 +3,7 @@ import {
3
3
  defineUnit,
4
4
  type EntityInput,
5
5
  type EntityValue,
6
+ secretSchema,
6
7
  z,
7
8
  } from "@highstate/contract"
8
9
  import { l3EndpointEntity, l4EndpointEntity } from "./network"
@@ -14,7 +15,7 @@ export const repositoryEntity = defineEntity({
14
15
  remoteEndpoints: z.union([l3EndpointEntity.schema, l4EndpointEntity.schema]).array(),
15
16
 
16
17
  type: z.literal("rclone"),
17
- rcloneConfig: z.string(),
18
+ rcloneConfig: secretSchema(z.string()),
18
19
  remoteName: z.string(),
19
20
  pathPattern: z.string(),
20
21
  }),
package/src/ssh.ts CHANGED
@@ -64,6 +64,18 @@ export const keyPairEntity = defineEntity({
64
64
  },
65
65
  })
66
66
 
67
+ export const proxySchema = z.object({
68
+ /**
69
+ * The SSH endpoint of the proxy server.
70
+ */
71
+ endpoint: l4EndpointEntity.schema,
72
+
73
+ /**
74
+ * The SSH user to connect as on the proxy server.
75
+ */
76
+ user: z.string(),
77
+ })
78
+
67
79
  /**
68
80
  * The schema for the SSH connection credentials.
69
81
  */
@@ -103,6 +115,13 @@ export const connectionEntity = defineEntity({
103
115
  * The password to use for authentication.
104
116
  */
105
117
  password: secretSchema(z.string()).optional(),
118
+
119
+ /**
120
+ * The proxy server to use for connecting to the target.
121
+ *
122
+ * Proxy server host keys are intentionally not verified.
123
+ */
124
+ proxy: proxySchema.optional(),
106
125
  }),
107
126
 
108
127
  meta: {
@@ -135,6 +154,13 @@ export const argsSchema = z.object({
135
154
  * The SSH user to connect as.
136
155
  */
137
156
  user: z.string().default("root"),
157
+
158
+ /**
159
+ * The proxy server to use for connecting to the target.
160
+ *
161
+ * Proxy server host keys are intentionally not verified.
162
+ */
163
+ proxy: proxySchema.optional(),
138
164
  })
139
165
 
140
166
  export const secrets = $secrets({
@@ -237,6 +263,7 @@ export const keyPair = defineUnit({
237
263
  })
238
264
 
239
265
  export type Args = z.infer<typeof argsSchema>
266
+ export type Proxy = z.infer<typeof proxySchema>
240
267
  export type KeyType = z.infer<typeof keyTypeSchema>
241
268
  export type PublicKey = EntityValue<typeof publicKeyEntity>
242
269
  export type KeyPair = EntityValue<typeof keyPairEntity>
@@ -0,0 +1,427 @@
1
+ import {
2
+ $args,
3
+ defineEntity,
4
+ defineUnit,
5
+ type EntityInput,
6
+ type EntityValue,
7
+ secretSchema,
8
+ z,
9
+ } from "@highstate/contract"
10
+ import { serverEntity, serverOutputs, vmSecrets, vmSshArgs } from "../common"
11
+ import * as ssh from "../ssh"
12
+
13
+ export const connectionEntity = defineEntity({
14
+ type: "gcp.connection.v1",
15
+
16
+ schema: z.object({
17
+ /**
18
+ * The service account JSON key used for authentication.
19
+ */
20
+ serviceAccountKeyJson: secretSchema(z.string()),
21
+
22
+ /**
23
+ * The ID of the Google Cloud project.
24
+ */
25
+ projectId: z.string(),
26
+
27
+ /**
28
+ * The default region.
29
+ */
30
+ defaultRegion: z.string(),
31
+
32
+ /**
33
+ * The default availability zone.
34
+ */
35
+ defaultZone: z.string().optional(),
36
+ }),
37
+
38
+ meta: {
39
+ color: "#4285F4",
40
+ title: "GCP Connection",
41
+ icon: "material-icon-theme:gcp",
42
+ iconColor: "#4285F4",
43
+ },
44
+ })
45
+
46
+ /**
47
+ * The connection to a Google Cloud account.
48
+ */
49
+ export const connection = defineUnit({
50
+ type: "gcp.connection.v1",
51
+
52
+ args: {
53
+ /**
54
+ * The region to create connection for.
55
+ */
56
+ region: z
57
+ .object({
58
+ /**
59
+ * The ID of the region.
60
+ */
61
+ id: z.string().default("us-central1"),
62
+
63
+ /**
64
+ * The default availability zone in the selected region.
65
+ *
66
+ * If not specified, an available zone in the region will be selected automatically.
67
+ */
68
+ defaultZone: z.string().optional(),
69
+ })
70
+ .prefault({}),
71
+ },
72
+
73
+ secrets: {
74
+ /**
75
+ * The JSON service account key.
76
+ */
77
+ serviceAccountKeyJson: {
78
+ schema: z.string().meta({ language: "json" }),
79
+ meta: {
80
+ title: "Service Account Key JSON",
81
+ },
82
+ },
83
+ },
84
+
85
+ inputs: {
86
+ ...ssh.inputs,
87
+ },
88
+
89
+ outputs: {
90
+ /**
91
+ * The Google Cloud connection.
92
+ */
93
+ connection: connectionEntity,
94
+ },
95
+
96
+ meta: {
97
+ title: "GCP Connection",
98
+ category: "Google Cloud",
99
+ icon: "material-icon-theme:gcp",
100
+ iconColor: "#4285F4",
101
+ },
102
+
103
+ source: {
104
+ package: "@highstate/gcp",
105
+ path: "connection",
106
+ },
107
+ })
108
+
109
+ export const diskSchema = z.object({
110
+ /**
111
+ * The disk type.
112
+ */
113
+ type: z.enum(["pd-standard", "pd-balanced", "pd-ssd", "pd-extreme"]).default("pd-balanced"),
114
+
115
+ /**
116
+ * The disk size in GB.
117
+ */
118
+ size: z.number().default(20),
119
+
120
+ /**
121
+ * Whether the disk should be encrypted with a separate KMS key.
122
+ */
123
+ encrypted: z.boolean().default(false),
124
+ })
125
+
126
+ export const diskEntity = defineEntity({
127
+ type: "gcp.disk.v1",
128
+
129
+ schema: z.object({
130
+ /**
131
+ * The global ID of the disk.
132
+ */
133
+ id: z.string(),
134
+ }),
135
+
136
+ meta: {
137
+ title: "GCP Disk",
138
+ icon: "material-icon-theme:gcp",
139
+ iconColor: "#4285F4",
140
+ secondaryIcon: "icon-park-outline:disk",
141
+ },
142
+ })
143
+
144
+ /**
145
+ * The disk on Google Cloud.
146
+ */
147
+ export const disk = defineUnit({
148
+ type: "gcp.disk.v1",
149
+
150
+ args: {
151
+ /**
152
+ * The name of the disk in the project.
153
+ * If not specified, the name of the unit will be used.
154
+ */
155
+ diskName: z.string().optional(),
156
+
157
+ ...diskSchema.shape,
158
+ },
159
+
160
+ inputs: {
161
+ connection: connectionEntity,
162
+ },
163
+
164
+ outputs: {
165
+ /**
166
+ * The disk entity.
167
+ */
168
+ disk: diskEntity,
169
+ },
170
+
171
+ meta: {
172
+ title: "GCP Disk",
173
+ category: "Google Cloud",
174
+ icon: "icon-park-outline:disk",
175
+ iconColor: "#4285F4",
176
+ secondaryIcon: "mage:compact-disk-fill",
177
+ },
178
+
179
+ source: {
180
+ package: "@highstate/gcp",
181
+ path: "disk",
182
+ },
183
+ })
184
+
185
+ export const imageEntity = defineEntity({
186
+ type: "gcp.image.v1",
187
+
188
+ schema: z.object({
189
+ /**
190
+ * The global ID of the image.
191
+ */
192
+ id: z.string(),
193
+ }),
194
+
195
+ meta: {
196
+ title: "GCP Image",
197
+ icon: "material-icon-theme:gcp",
198
+ iconColor: "#4285F4",
199
+ secondaryIcon: "mage:compact-disk-fill",
200
+ },
201
+ })
202
+
203
+ /**
204
+ * The existing image from Google Cloud public images or custom images.
205
+ */
206
+ export const existingImage = defineUnit({
207
+ type: "gcp.existing-image.v1",
208
+
209
+ args: {
210
+ /**
211
+ * The ID or self-link of the image.
212
+ *
213
+ * See [Compute Engine public images](https://cloud.google.com/compute/docs/images/os-details)
214
+ * and [Google Cloud Marketplace](https://console.cloud.google.com/marketplace)
215
+ * to find available images.
216
+ */
217
+ id: z.string(),
218
+ },
219
+
220
+ inputs: {
221
+ connection: connectionEntity,
222
+ },
223
+
224
+ outputs: {
225
+ /**
226
+ * The image entity.
227
+ */
228
+ image: imageEntity,
229
+ },
230
+
231
+ meta: {
232
+ title: "GCP Existing Image",
233
+ category: "Google Cloud",
234
+ icon: "material-icon-theme:gcp",
235
+ iconColor: "#4285F4",
236
+ secondaryIcon: "mage:compact-disk-fill",
237
+ },
238
+
239
+ source: {
240
+ package: "@highstate/gcp",
241
+ path: "existing-image",
242
+ },
243
+ })
244
+
245
+ const vmArgs = $args({
246
+ /**
247
+ * The machine type for the instance.
248
+ */
249
+ machineType: z.string().default("e2-standard-2"),
250
+
251
+ /**
252
+ * The boot disk configuration.
253
+ */
254
+ bootDisk: diskSchema.prefault({}),
255
+
256
+ /**
257
+ * The network configuration.
258
+ */
259
+ network: z
260
+ .object({
261
+ /**
262
+ * The subnetwork self-link to connect to.
263
+ * If not specified, will auto-discover the default subnet for the zone.
264
+ */
265
+ subnetworkId: z.string().optional(),
266
+
267
+ /**
268
+ * Whether to assign a public IP.
269
+ */
270
+ assignPublicIp: z.boolean().default(true),
271
+
272
+ /**
273
+ * Whether to reserve the public IP permanently.
274
+ */
275
+ reservePublicIp: z.boolean().default(true),
276
+ })
277
+ .prefault({}),
278
+
279
+ /**
280
+ * The SSH configuration.
281
+ */
282
+ ssh: vmSshArgs,
283
+
284
+ /**
285
+ * Whether the virtual machine is preemptible.
286
+ */
287
+ preemptible: z.boolean().default(false),
288
+ })
289
+
290
+ /**
291
+ * The virtual machine on Google Cloud.
292
+ */
293
+ export const virtualMachine = defineUnit({
294
+ type: "gcp.virtual-machine.v1",
295
+
296
+ args: {
297
+ /**
298
+ * The name of the virtual machine.
299
+ * If not specified, the name of the unit will be used.
300
+ */
301
+ vmName: z.string().optional(),
302
+
303
+ /**
304
+ * The ID of the project to create the VM in.
305
+ * If not specified, will use the project from the connection.
306
+ */
307
+ projectId: z.string().optional(),
308
+
309
+ /**
310
+ * The region to create the VM in.
311
+ * If not specified, will use the region from the connection.
312
+ */
313
+ region: z.string().optional(),
314
+
315
+ /**
316
+ * The zone to create the VM in.
317
+ * If not specified, will use the default zone from the connection.
318
+ */
319
+ zone: z.string().optional(),
320
+
321
+ ...vmArgs,
322
+ },
323
+
324
+ secrets: {
325
+ ...vmSecrets,
326
+ },
327
+
328
+ inputs: {
329
+ connection: connectionEntity,
330
+ image: imageEntity,
331
+ ...ssh.inputs,
332
+ },
333
+
334
+ outputs: serverOutputs,
335
+
336
+ meta: {
337
+ title: "GCP Virtual Machine",
338
+ category: "Google Cloud",
339
+ icon: "material-icon-theme:gcp",
340
+ iconColor: "#4285F4",
341
+ secondaryIcon: "codicon:vm",
342
+ },
343
+
344
+ source: {
345
+ package: "@highstate/gcp",
346
+ path: "virtual-machine",
347
+ },
348
+ })
349
+
350
+ /**
351
+ * The managed instance group on Google Cloud.
352
+ */
353
+ export const instanceGroup = defineUnit({
354
+ type: "gcp.instance-group.v1",
355
+
356
+ args: {
357
+ /**
358
+ * The name of the instance group.
359
+ * If not specified, the name of the unit will be used.
360
+ */
361
+ groupName: z.string().optional(),
362
+
363
+ /**
364
+ * The ID of the project to create the instance group in.
365
+ * If not specified, will use the project from the connection.
366
+ */
367
+ projectId: z.string().optional(),
368
+
369
+ /**
370
+ * The region to create the instance group in.
371
+ * If not specified, will use the region from the connection.
372
+ */
373
+ region: z.string().optional(),
374
+
375
+ /**
376
+ * The zone to create the instance group in.
377
+ * If not specified, will use the default zone from the connection.
378
+ */
379
+ zone: z.string().optional(),
380
+
381
+ /**
382
+ * The number of instances to create in the group.
383
+ */
384
+ size: z.number().default(1),
385
+
386
+ ...vmArgs,
387
+ },
388
+
389
+ secrets: {
390
+ ...vmSecrets,
391
+ },
392
+
393
+ inputs: {
394
+ connection: connectionEntity,
395
+ image: imageEntity,
396
+ ...ssh.inputs,
397
+ },
398
+
399
+ outputs: {
400
+ servers: {
401
+ entity: serverEntity,
402
+ multiple: true,
403
+ },
404
+ },
405
+
406
+ meta: {
407
+ title: "GCP Instance Group",
408
+ category: "Google Cloud",
409
+ icon: "material-icon-theme:gcp",
410
+ iconColor: "#4285F4",
411
+ secondaryIcon: "mdi:group",
412
+ },
413
+
414
+ source: {
415
+ package: "@highstate/gcp",
416
+ path: "instance-group",
417
+ },
418
+ })
419
+
420
+ export type Connection = EntityValue<typeof connectionEntity>
421
+ export type ConnectionInput = EntityInput<typeof connectionEntity>
422
+
423
+ export type Disk = EntityValue<typeof diskEntity>
424
+ export type DiskInput = EntityInput<typeof diskEntity>
425
+
426
+ export type Image = EntityValue<typeof imageEntity>
427
+ export type ImageInput = EntityInput<typeof imageEntity>
@@ -1,4 +1,5 @@
1
1
  export * as cloudflare from "./cloudflare"
2
+ export * as gcp from "./gcp"
2
3
  export * as mullvad from "./mullvad"
3
4
  export * as timeweb from "./timeweb"
4
5
  export * as yandex from "./yandex"