@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
@@ -8,6 +8,7 @@ import {
8
8
  z,
9
9
  } from "@highstate/contract"
10
10
  import { serverEntity, serverOutputs, vmSecrets, vmSshArgs } from "../common"
11
+ import { l4EndpointEntity, portSchema } from "../network"
11
12
  import * as ssh from "../ssh"
12
13
 
13
14
  export const connectionEntity = defineEntity({
@@ -77,7 +78,7 @@ export const connection = defineUnit({
77
78
  * The default availability zone in ru-central1 to place resources in.
78
79
  */
79
80
  defaultZone: z
80
- .enum(["ru-central1-a", "ru-central1-b", "ru-central1-d"])
81
+ .enum(["ru-central1-a", "ru-central1-b", "ru-central1-d", "ru-central1-e"])
81
82
  .default("ru-central1-d"),
82
83
  }),
83
84
  z.object({
@@ -222,6 +223,91 @@ export const disk = defineUnit({
222
223
  },
223
224
  })
224
225
 
226
+ export const publicAddressEntity = defineEntity({
227
+ type: "yandex.public-address.v1",
228
+
229
+ schema: z.object({
230
+ /**
231
+ * The global ID of the public address.
232
+ */
233
+ id: z.string(),
234
+
235
+ /**
236
+ * The name of the public address.
237
+ */
238
+ name: z.string(),
239
+
240
+ /**
241
+ * The IPv4 address value.
242
+ */
243
+ address: z.string(),
244
+ }),
245
+
246
+ meta: {
247
+ title: "YC Public Address",
248
+ icon: "simple-icons:yandexcloud",
249
+ iconColor: "#0080ff",
250
+ secondaryIcon: "mdi:ip-network-outline",
251
+ },
252
+ })
253
+
254
+ /**
255
+ * The reserved public IPv4 address on Yandex Cloud.
256
+ */
257
+ export const publicAddress = defineUnit({
258
+ type: "yandex.public-address.v1",
259
+
260
+ args: {
261
+ /**
262
+ * The name of the public address in the folder.
263
+ * If not specified, the name of the unit will be used.
264
+ */
265
+ addressName: z.string().optional(),
266
+
267
+ /**
268
+ * The ID of the cloud to create the public address in.
269
+ * If not specified, will use the cloud from the connection.
270
+ */
271
+ cloudId: z.string().optional(),
272
+
273
+ /**
274
+ * The ID of the folder to create the public address in.
275
+ * If not specified, will use the default folder from the connection.
276
+ */
277
+ folderId: z.string().optional(),
278
+
279
+ /**
280
+ * The availability zone to reserve the address in.
281
+ * If not specified, will use the default zone from the connection.
282
+ */
283
+ zone: z.string().optional(),
284
+ },
285
+
286
+ inputs: {
287
+ connection: connectionEntity,
288
+ },
289
+
290
+ outputs: {
291
+ /**
292
+ * The public address entity.
293
+ */
294
+ publicAddress: publicAddressEntity,
295
+ },
296
+
297
+ meta: {
298
+ title: "YC Public Address",
299
+ category: "Yandex Cloud",
300
+ icon: "simple-icons:yandexcloud",
301
+ iconColor: "#0080ff",
302
+ secondaryIcon: "mdi:ip-network-outline",
303
+ },
304
+
305
+ source: {
306
+ package: "@highstate/yandex",
307
+ path: "public-address",
308
+ },
309
+ })
310
+
225
311
  export const imageEntity = defineEntity({
226
312
  type: "yandex.image.v1",
227
313
 
@@ -378,6 +464,65 @@ const vmArgs = $args({
378
464
  preemptible: z.boolean().default(false),
379
465
  })
380
466
 
467
+ const nlbArgs = z.object({
468
+ /**
469
+ * Whether to create a network load balancer for the instance group.
470
+ */
471
+ enabled: z.boolean().default(false),
472
+
473
+ /**
474
+ * The name of the network load balancer.
475
+ * If not specified, the instance group name will be used.
476
+ */
477
+ name: z.string().optional(),
478
+
479
+ /**
480
+ * The load-balanced ports to expose through the shared public address.
481
+ *
482
+ * Each listener must use `protocol:source=>target` format, for example `tcp:80=>8080`.
483
+ *
484
+ * If the source and target ports are the same, use `protocol:port` shorthand, for example `tcp:80`.
485
+ *
486
+ * When SSH is enabled, the `tcp:<ssh-port>` listener is included automatically.
487
+ */
488
+ listeners: z.string().array().default([]),
489
+
490
+ /**
491
+ * The health check protocol.
492
+ */
493
+ healthCheckProtocol: z.enum(["tcp", "http"]).default("tcp"),
494
+
495
+ /**
496
+ * The port to use for health checks.
497
+ */
498
+ healthCheckPort: portSchema.default(22),
499
+
500
+ /**
501
+ * The HTTP path to use for health checks.
502
+ */
503
+ healthCheckPath: z.string().default("/"),
504
+
505
+ /**
506
+ * The interval between health checks in seconds.
507
+ */
508
+ healthCheckInterval: z.number().int().min(1).max(60).default(2),
509
+
510
+ /**
511
+ * The timeout for health check responses in seconds.
512
+ */
513
+ healthCheckTimeout: z.number().int().min(1).max(60).default(1),
514
+
515
+ /**
516
+ * The number of successful checks required to mark a target healthy.
517
+ */
518
+ healthCheckHealthyThreshold: z.number().int().default(2),
519
+
520
+ /**
521
+ * The number of failed checks required to mark a target unhealthy.
522
+ */
523
+ healthCheckUnhealthyThreshold: z.number().int().default(2),
524
+ })
525
+
381
526
  /**
382
527
  * The virtual machine on Yandex Cloud.
383
528
  */
@@ -413,6 +558,23 @@ export const virtualMachine = defineUnit({
413
558
  inputs: {
414
559
  connection: connectionEntity,
415
560
  image: imageEntity,
561
+
562
+ /**
563
+ * The reserved public address to attach to the virtual machine.
564
+ */
565
+ publicAddress: {
566
+ entity: publicAddressEntity,
567
+ required: false,
568
+ },
569
+
570
+ /**
571
+ * The endpoint of the SSH jump host used to connect to the virtual machine.
572
+ */
573
+ sshProxyEndpoint: {
574
+ entity: l4EndpointEntity,
575
+ required: false,
576
+ },
577
+
416
578
  ...ssh.inputs,
417
579
  },
418
580
 
@@ -462,6 +624,17 @@ export const instanceGroup = defineUnit({
462
624
  */
463
625
  size: z.number().default(1),
464
626
 
627
+ /**
628
+ * The zones to spread instances across.
629
+ * If not specified, will use the default zone from the connection.
630
+ */
631
+ zones: z.string().array().optional(),
632
+
633
+ /**
634
+ * The network load balancer configuration.
635
+ */
636
+ nlb: nlbArgs.prefault({}),
637
+
465
638
  ...vmArgs,
466
639
  },
467
640
 
@@ -472,6 +645,33 @@ export const instanceGroup = defineUnit({
472
645
  inputs: {
473
646
  connection: connectionEntity,
474
647
  image: imageEntity,
648
+
649
+ /**
650
+ * The public addresses to attach to instances.
651
+ * Addresses are sorted by name and assigned to instances in that order.
652
+ */
653
+ publicAddresses: {
654
+ entity: publicAddressEntity,
655
+ required: false,
656
+ multiple: true,
657
+ },
658
+
659
+ /**
660
+ * The reserved public address to use for the network load balancer.
661
+ */
662
+ nlbPublicAddress: {
663
+ entity: publicAddressEntity,
664
+ required: false,
665
+ },
666
+
667
+ /**
668
+ * The endpoint of the SSH jump host used to connect to the instances.
669
+ */
670
+ sshProxyEndpoint: {
671
+ entity: l4EndpointEntity,
672
+ required: false,
673
+ },
674
+
475
675
  ...ssh.inputs,
476
676
  },
477
677
 
@@ -480,6 +680,12 @@ export const instanceGroup = defineUnit({
480
680
  entity: serverEntity,
481
681
  multiple: true,
482
682
  },
683
+
684
+ nlbEndpoints: {
685
+ entity: l4EndpointEntity,
686
+ multiple: true,
687
+ required: false,
688
+ },
483
689
  },
484
690
 
485
691
  meta: {
@@ -502,5 +708,8 @@ export type ConnectionInput = EntityInput<typeof connectionEntity>
502
708
  export type Disk = EntityValue<typeof diskEntity>
503
709
  export type DiskInput = EntityInput<typeof diskEntity>
504
710
 
711
+ export type PublicAddress = EntityValue<typeof publicAddressEntity>
712
+ export type PublicAddressInput = EntityInput<typeof publicAddressEntity>
713
+
505
714
  export type Image = EntityValue<typeof imageEntity>
506
715
  export type ImageInput = EntityInput<typeof imageEntity>
package/src/tls.ts CHANGED
@@ -1,22 +1,151 @@
1
- import { defineEntity, z } from "@highstate/contract"
2
- import { fileEntity } from "./common"
1
+ import {
2
+ defineEntity,
3
+ defineUnit,
4
+ type EntityInput,
5
+ type EntityValue,
6
+ z,
7
+ } from "@highstate/contract"
8
+ import { fileEntity, tlsIssuerEntity } from "./common"
9
+
10
+ export const privateKeyAlgorithmSchema = z.enum(["RSA", "ECDSA", "Ed25519"])
11
+
12
+ export const privateKeySchema = z
13
+ .object({
14
+ /**
15
+ * The private key algorithm.
16
+ */
17
+ algorithm: privateKeyAlgorithmSchema.default("RSA"),
18
+
19
+ /**
20
+ * The private key size in bits.
21
+ */
22
+ size: z.number().int().positive().optional(),
23
+ })
24
+ .default({
25
+ algorithm: "RSA",
26
+ size: 4096,
27
+ })
28
+
29
+ export const certificateUsageSchema = z.enum([
30
+ "digitalSignature",
31
+ "keyEncipherment",
32
+ "serverAuth",
33
+ "clientAuth",
34
+ ])
35
+
36
+ export const certificateChainEntity = defineEntity({
37
+ type: "tls.certificate-chain.v1",
38
+
39
+ includes: {
40
+ /**
41
+ * The file containing the certificate chain (leaf and intermediate certificates) in PEM format.
42
+ */
43
+ chain: fileEntity,
44
+
45
+ /**
46
+ * The file containing the root certificate in PEM format.
47
+ * May be omitted if the root certificate is already trusted by the system.
48
+ */
49
+ root: {
50
+ entity: fileEntity,
51
+ required: false,
52
+ },
53
+ },
54
+
55
+ schema: z.unknown(),
56
+
57
+ meta: {
58
+ title: "TLS Certificate Chain",
59
+ color: "#2E7D32",
60
+ icon: "mdi:certificate",
61
+ iconColor: "#2E7D32",
62
+ },
63
+ })
3
64
 
4
65
  export const certificateEntity = defineEntity({
5
66
  type: "tls.certificate.v1",
6
67
 
7
68
  includes: {
8
69
  /**
9
- * The file containing the certificate in PEM format.
70
+ * The public chain of the certificate.
71
+ */
72
+ chain: certificateChainEntity,
73
+
74
+ /**
75
+ * The private key of the certificate in PEM format.
10
76
  */
11
- file: fileEntity,
77
+ privateKey: fileEntity,
12
78
  },
13
79
 
14
80
  schema: z.unknown(),
15
81
 
16
82
  meta: {
17
83
  title: "TLS Certificate",
18
- color: "#4caf50",
84
+ color: "#4CAF50",
19
85
  icon: "mdi:certificate",
20
- iconColor: "#4caf50",
86
+ iconColor: "#4CAF50",
21
87
  },
22
88
  })
89
+
90
+ /**
91
+ * Issues a TLS certificate using the provided TLS issuer.
92
+ */
93
+ export const certificate = defineUnit({
94
+ type: "tls.certificate.v1",
95
+
96
+ args: {
97
+ /**
98
+ * The common name for the certificate.
99
+ */
100
+ commonName: z.string().optional(),
101
+
102
+ /**
103
+ * The alternative DNS names for the certificate.
104
+ */
105
+ dnsNames: z.string().array().default([]),
106
+
107
+ /**
108
+ * The private key configuration for the certificate.
109
+ */
110
+ privateKey: privateKeySchema,
111
+
112
+ /**
113
+ * The requested key usages for the certificate.
114
+ *
115
+ * If not provided, the issuer default usages will be used.
116
+ */
117
+ usages: certificateUsageSchema.array().default(["digitalSignature", "keyEncipherment"]),
118
+ },
119
+
120
+ inputs: {
121
+ /**
122
+ * The TLS issuer used to issue the certificate.
123
+ */
124
+ issuer: tlsIssuerEntity,
125
+ },
126
+
127
+ outputs: {
128
+ certificate: certificateEntity,
129
+ },
130
+
131
+ meta: {
132
+ title: "TLS Certificate",
133
+ icon: "mdi:certificate",
134
+ category: "Security",
135
+ },
136
+
137
+ source: {
138
+ package: "@highstate/common",
139
+ path: "units/tls/certificate",
140
+ },
141
+ })
142
+
143
+ export type CertificateChain = EntityValue<typeof certificateChainEntity>
144
+ export type CertificateChainInput = EntityInput<typeof certificateChainEntity>
145
+
146
+ export type Certificate = EntityValue<typeof certificateEntity>
147
+ export type CertificateInput = EntityInput<typeof certificateEntity>
148
+
149
+ export type PrivateKeyAlgorithm = z.infer<typeof privateKeyAlgorithmSchema>
150
+ export type PrivateKeySpec = z.infer<typeof privateKeySchema>
151
+ export type CertificateUsage = z.infer<typeof certificateUsageSchema>
package/src/utils.ts CHANGED
@@ -1,4 +1,9 @@
1
- import { type FullComponentArgumentOptions, genericNameSchema, z } from "@highstate/contract"
1
+ import {
2
+ type FullComponentArgumentOptions,
3
+ genericNameSchema,
4
+ objectMetaSchema,
5
+ z,
6
+ } from "@highstate/contract"
2
7
  import { mapValues } from "remeda"
3
8
 
4
9
  type PrefixWith<TString extends string, TPrefix extends string> = TPrefix extends ""
@@ -101,3 +106,13 @@ export const metadataSchema = z.record(metadataKeySchema, z.unknown())
101
106
  export type Metadata = z.infer<typeof metadataSchema>
102
107
  export type MetadataKey = z.infer<typeof metadataKeySchema>
103
108
  export type MetadataContainer = { metadata?: Metadata }
109
+
110
+ export const entityMetaArgsSchema = objectMetaSchema
111
+ .pick({
112
+ title: true,
113
+ description: true,
114
+ icon: true,
115
+ iconColor: true,
116
+ })
117
+ .partial()
118
+ .prefault({})