@highstate/common 0.9.8 → 0.9.10

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.
@@ -99,15 +99,16 @@ function l3ToL4Endpoint(l3Endpoint, port, protocol = "tcp") {
99
99
  protocol
100
100
  };
101
101
  }
102
- function filterEndpoints(endpoints, filter) {
102
+ function filterEndpoints(endpoints, filter, types) {
103
103
  if (filter?.length) {
104
- return endpoints.filter((endpoint) => filter.includes(endpoint.visibility));
104
+ endpoints = endpoints.filter((endpoint) => filter.includes(endpoint.visibility));
105
+ } else if (endpoints.some((endpoint) => endpoint.visibility === "public")) {
106
+ endpoints = endpoints.filter((endpoint) => endpoint.visibility === "public");
107
+ } else if (endpoints.some((endpoint) => endpoint.visibility === "external")) {
108
+ endpoints = endpoints.filter((endpoint) => endpoint.visibility === "external");
105
109
  }
106
- if (endpoints.some((endpoint) => endpoint.visibility === "public")) {
107
- return endpoints.filter((endpoint) => endpoint.visibility === "public");
108
- }
109
- if (endpoints.some((endpoint) => endpoint.visibility === "external")) {
110
- return endpoints.filter((endpoint) => endpoint.visibility === "external");
110
+ if (types && types.length) {
111
+ endpoints = endpoints.filter((endpoint) => types.includes(endpoint.type));
111
112
  }
112
113
  return endpoints;
113
114
  }
@@ -325,7 +326,7 @@ var DnsRecordSet = class _DnsRecordSet extends ComponentResource2 {
325
326
  return values.map((value) => {
326
327
  const l3Endpoint = parseL3Endpoint(value);
327
328
  return DnsRecord.create(
328
- `${provider.type}-from-${provider.name}-to-${l3EndpointToString(l3Endpoint)}`,
329
+ `${provider.type}-from-${recordName}-to-${l3EndpointToString(l3Endpoint)}`,
329
330
  { name: recordName, ...args2, value: l3Endpoint, provider },
330
331
  opts
331
332
  );
@@ -527,4 +528,4 @@ export {
527
528
  getOrCreateSshKeyPair,
528
529
  createServerEntity
529
530
  };
530
- //# sourceMappingURL=chunk-USV6SHAU.js.map
531
+ //# sourceMappingURL=chunk-INONQX2G.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/network.ts","../src/shared/command.ts","../src/shared/dns.ts","../src/shared/passwords.ts","../src/shared/ssh.ts"],"sourcesContent":["import type { ArrayPatchMode, network } from \"@highstate/library\"\nimport { toPromise, type Input } from \"@highstate/pulumi\"\nimport { uniqueBy } from \"remeda\"\n\n/**\n * The L3 or L4 endpoint for some service.\n *\n * The format is: `[protocol://]endpoint[:port]`\n */\nexport type InputL34Endpoint = network.L34Endpoint | string\n\n/**\n * The L3 endpoint for some service.\n */\nexport type InputL3Endpoint = network.L3Endpoint | string\n\n/**\n * The L4 endpoint for some service.\n */\nexport type InputL4Endpoint = network.L4Endpoint | string\n\n/**\n * Stringifies a L3 endpoint object into a string.\n *\n * @param l3Endpoint The L3 endpoint object to stringify.\n * @returns The string representation of the L3 endpoint.\n */\nexport function l3EndpointToString(l3Endpoint: network.L3Endpoint): string {\n switch (l3Endpoint.type) {\n case \"ipv4\":\n return l3Endpoint.address\n case \"ipv6\":\n return l3Endpoint.address\n case \"hostname\":\n return l3Endpoint.hostname\n }\n}\n\n/**\n * Stringifies a L4 endpoint object into a string.\n *\n * @param l4Endpoint The L4 endpoint object to stringify.\n *\n * @returns The string representation of the L4 endpoint.\n */\nexport function l4EndpointToString(l4Endpoint: network.L4Endpoint): string {\n if (l4Endpoint.type === \"ipv6\") {\n return `[${l4Endpoint.address}]:${l4Endpoint.port}`\n }\n\n return `${l3EndpointToString(l4Endpoint)}:${l4Endpoint.port}`\n}\n\n/**\n * Stringifies a L3 or L4 endpoint object into a string.\n *\n * @param l34Endpoint The L3 or L4 endpoint object to stringify.\n * @returns The string representation of the L3 or L4 endpoint.\n */\nexport function l34EndpointToString(l34Endpoint: network.L34Endpoint): string {\n if (l34Endpoint.port) {\n return l4EndpointToString(l34Endpoint)\n }\n\n return l3EndpointToString(l34Endpoint)\n}\n\nconst L34_ENDPOINT_RE =\n /^(?:(?<protocol>[a-z]+):\\/\\/)?(?:(?:\\[?(?<ipv6>[0-9A-Fa-f:]+)\\]?)|(?<ipv4>(?:\\d{1,3}\\.){3}\\d{1,3})|(?<hostname>[a-zA-Z0-9-*]+(?:\\.[a-zA-Z0-9-*]+)*))(?::(?<port>\\d{1,5}))?$/\n\n/**\n * Parses a L3 or L4 endpoint from a string.\n *\n * The format is `[protocol://]endpoint[:port]`.\n *\n * @param l34Endpoint The L3 or L4 endpoint string to parse.\n * @returns The parsed L3 or L4 endpoint object.\n */\nexport function parseL34Endpoint(l34Endpoint: InputL34Endpoint): network.L34Endpoint {\n if (typeof l34Endpoint === \"object\") {\n return l34Endpoint\n }\n\n const match = l34Endpoint.match(L34_ENDPOINT_RE)\n if (!match) {\n throw new Error(`Invalid L3/L4 endpoint: \"${l34Endpoint}\"`)\n }\n\n const { protocol, ipv6, ipv4, hostname, port } = match.groups!\n\n if (protocol && protocol !== \"tcp\" && protocol !== \"udp\") {\n throw new Error(`Invalid L4 endpoint protocol: \"${protocol}\"`)\n }\n\n let visibility: network.EndpointVisibility = \"public\"\n\n if (ipv4 && IPV4_PRIVATE_REGEX.test(ipv4)) {\n visibility = \"external\"\n } else if (ipv6 && IPV6_PRIVATE_REGEX.test(ipv6)) {\n visibility = \"external\"\n }\n\n const fallbackProtocol = port ? \"tcp\" : undefined\n\n return {\n type: ipv6 ? \"ipv6\" : ipv4 ? \"ipv4\" : \"hostname\",\n visibility,\n address: ipv6 || ipv4,\n hostname: hostname,\n port: port ? parseInt(port, 10) : undefined,\n protocol: protocol ? (protocol as network.L4Protocol) : fallbackProtocol,\n } as network.L34Endpoint\n}\n\n/**\n * Parses a L3 endpoint from a string.\n *\n * The same as `parseL34Endpoint`, but only for L3 endpoints and will throw an error if the endpoint contains a port.\n *\n * @param l3Endpoint The L3 endpoint string to parse.\n * @returns The parsed L3 endpoint object.\n */\nexport function parseL3Endpoint(l3Endpoint: InputL3Endpoint): network.L3Endpoint {\n if (typeof l3Endpoint === \"object\") {\n return l3Endpoint\n }\n\n const parsed = parseL34Endpoint(l3Endpoint)\n\n if (parsed.port) {\n throw new Error(`Port cannot be specified in L3 endpoint: \"${l3Endpoint}\"`)\n }\n\n return parsed\n}\n\n/**\n * Parses a L4 endpoint from a string.\n *\n * The same as `parseL34Endpoint`, but only for L4 endpoints and will throw an error if the endpoint does not contain a port.\n */\nexport function parseL4Endpoint(l4Endpoint: InputL4Endpoint): network.L4Endpoint {\n if (typeof l4Endpoint === \"object\") {\n return l4Endpoint\n }\n\n const parsed = parseL34Endpoint(l4Endpoint)\n\n if (!parsed.port) {\n throw new Error(`No port found in L4 endpoint: \"${l4Endpoint}\"`)\n }\n\n return parsed\n}\n\nconst IPV4_PRIVATE_REGEX =\n /^(?:10|127)(?:\\.\\d{1,3}){3}$|^(?:172\\.1[6-9]|172\\.2[0-9]|172\\.3[0-1])(?:\\.\\d{1,3}){2}$|^(?:192\\.168)(?:\\.\\d{1,3}){2}$/\n\nconst IPV6_PRIVATE_REGEX =\n /^(?:fc|fd)(?:[0-9a-f]{2}){0,2}::(?:[0-9a-f]{1,4}:){7}[0-9a-f]{1,4}$|^::(?:ffff:(?:10|127)(?:\\.\\d{1,3}){3}|(?:172\\.1[6-9]|172\\.2[0-9]|172\\.3[0-1])(?:\\.\\d{1,3}){2}|(?:192\\.168)(?:\\.\\d{1,3}){2})$/\n\n/**\n * Helper function to get the input L3 endpoint from the raw endpoint or input endpoint.\n *\n * If neither is provided, an error is thrown.\n *\n * @param rawEndpoint The raw endpoint string to parse.\n * @param inputEndpoint The input endpoint object to use if the raw endpoint is not provided.\n * @returns The parsed L3 endpoint object.\n */\nexport async function requireInputL3Endpoint(\n rawEndpoint: string | undefined,\n inputEndpoint: Input<network.L3Endpoint> | undefined,\n): Promise<network.L3Endpoint> {\n if (rawEndpoint) {\n return parseL3Endpoint(rawEndpoint)\n }\n\n if (inputEndpoint) {\n return toPromise(inputEndpoint)\n }\n\n throw new Error(\"No endpoint provided\")\n}\n\n/**\n * Helper function to get the input L4 endpoint from the raw endpoint or input endpoint.\n *\n * If neither is provided, an error is thrown.\n *\n * @param rawEndpoint The raw endpoint string to parse.\n * @param inputEndpoint The input endpoint object to use if the raw endpoint is not provided.\n * @returns The parsed L4 endpoint object.\n */\nexport async function requireInputL4Endpoint(\n rawEndpoint: string | undefined,\n inputEndpoint: Input<network.L4Endpoint> | undefined,\n): Promise<network.L4Endpoint> {\n if (rawEndpoint) {\n return parseL4Endpoint(rawEndpoint)\n }\n\n if (inputEndpoint) {\n return toPromise(inputEndpoint)\n }\n\n throw new Error(\"No endpoint provided\")\n}\n\n/**\n * Convers L3 endpoint to L4 endpoint by adding a port and protocol.\n *\n * @param l3Endpoint The L3 endpoint to convert.\n * @param port The port to add to the L3 endpoint.\n * @param protocol The protocol to add to the L3 endpoint. Defaults to \"tcp\".\n * @returns The L4 endpoint with the port and protocol added.\n */\nexport function l3ToL4Endpoint(\n l3Endpoint: InputL3Endpoint,\n port: number,\n protocol: network.L4Protocol = \"tcp\",\n): network.L4Endpoint {\n return {\n ...parseL3Endpoint(l3Endpoint),\n port,\n protocol,\n }\n}\n\n/**\n * Filters the endpoints based on the given filter.\n *\n * @param endpoints The list of endpoints to filter.\n * @param filter The filter to apply. If not provided, the endpoints will be filtered by the most accessible type: `public` > `external` > `internal`.\n * @param types The list of endpoint types to filter by. If provided, only endpoints of these types will be returned.\n *\n * @returns The filtered list of endpoints.\n */\nexport function filterEndpoints<TEndpoint extends network.L34Endpoint>(\n endpoints: TEndpoint[],\n filter?: network.EndpointFilter,\n types?: network.L34Endpoint[\"type\"][],\n): TEndpoint[] {\n if (filter?.length) {\n endpoints = endpoints.filter(endpoint => filter.includes(endpoint.visibility))\n } else if (endpoints.some(endpoint => endpoint.visibility === \"public\")) {\n endpoints = endpoints.filter(endpoint => endpoint.visibility === \"public\")\n } else if (endpoints.some(endpoint => endpoint.visibility === \"external\")) {\n endpoints = endpoints.filter(endpoint => endpoint.visibility === \"external\")\n }\n\n if (types && types.length) {\n endpoints = endpoints.filter(endpoint => types.includes(endpoint.type))\n }\n\n return endpoints\n}\n\n/**\n * Converts a L3 endpoint to CIDR notation.\n *\n * If the endpoint is a hostname, an error is thrown.\n *\n * @param l3Endpoint The L3 endpoint to convert.\n * @returns The CIDR notation of the L3 endpoint.\n */\nexport function l3EndpointToCidr(l3Endpoint: network.L3Endpoint): string {\n switch (l3Endpoint.type) {\n case \"ipv4\":\n return `${l3Endpoint.address}/32`\n case \"ipv6\":\n return `${l3Endpoint.address}/128`\n case \"hostname\":\n throw new Error(\"Cannot convert hostname to CIDR\")\n }\n}\n\n/**\n * Updates the endpoints based on the given mode.\n *\n * @param currentEndpoints The current endpoints to update.\n * @param endpoints The new endpoints to add in string format.\n * @param inputEndpoints The input endpoints to add in object format.\n * @param mode The mode to use when updating the endpoints. Can be \"replace\" or \"prepend\". Defaults to \"prepend\".\n *\n * @returns The updated list of endpoints.\n */\nexport async function updateEndpoints<TEdnpoints extends network.L34Endpoint>(\n currentEndpoints: Input<TEdnpoints[]>,\n endpoints: string[],\n inputEndpoints: Input<TEdnpoints[]>,\n mode: ArrayPatchMode = \"prepend\",\n): Promise<TEdnpoints[]> {\n const resolvedCurrentEndpoints = await toPromise(currentEndpoints)\n const resolvedInputEndpoints = await toPromise(inputEndpoints)\n\n const newEndpoints = uniqueBy(\n //\n [...endpoints.map(parseL34Endpoint), ...resolvedInputEndpoints],\n endpoint => l34EndpointToString(endpoint),\n )\n\n if (mode === \"replace\") {\n return newEndpoints as TEdnpoints[]\n }\n\n return uniqueBy(\n //\n [...newEndpoints, ...resolvedCurrentEndpoints],\n endpoint => l34EndpointToString(endpoint),\n ) as TEdnpoints[]\n}\n","import { local, remote, type types } from \"@pulumi/command\"\nimport {\n ComponentResource,\n interpolate,\n output,\n type ComponentResourceOptions,\n type Input,\n type InputOrArray,\n type Output,\n} from \"@highstate/pulumi\"\nimport { common, ssh } from \"@highstate/library\"\nimport { l3EndpointToString } from \"./network\"\n\nexport function getServerConnection(\n ssh: Input<ssh.Credentials>,\n): Output<types.input.remote.ConnectionArgs> {\n return output(ssh).apply(ssh => ({\n host: l3EndpointToString(ssh.endpoints[0]),\n port: ssh.endpoints[0].port,\n user: ssh.user,\n password: ssh.password,\n privateKey: ssh.keyPair?.privateKey,\n dialErrorLimit: 3,\n hostKey: ssh.hostKey,\n }))\n}\n\nexport type CommandHost = \"local\" | common.Server\n\nexport type CommandArgs = {\n host: Input<CommandHost>\n create: Input<string>\n update?: Input<string>\n delete?: Input<string>\n logging?: Input<remote.Logging>\n triggers?: InputOrArray<unknown>\n}\n\nexport type TextFileArgs = {\n host: CommandHost\n path: Input<string>\n content: Input<string>\n}\n\nexport class Command extends ComponentResource {\n public readonly command: Output<local.Command | remote.Command>\n\n public readonly stdout: Output<string>\n public readonly stderr: Output<string>\n\n constructor(name: string, args: CommandArgs, opts?: ComponentResourceOptions) {\n super(\"highstate:common:Command\", name, args, opts)\n\n this.command = output(args).apply(args => {\n if (args.host === \"local\") {\n return new local.Command(\n name,\n {\n create: args.create,\n update: args.update,\n delete: args.delete,\n logging: args.logging,\n triggers: args.triggers,\n },\n { ...opts, parent: this },\n )\n }\n\n if (!args.host.ssh) {\n throw new Error(`The host \"${args.host.hostname}\" has no SSH credentials`)\n }\n\n return new remote.Command(\n name,\n {\n connection: getServerConnection(args.host.ssh),\n create: args.create,\n update: args.update,\n delete: args.delete,\n logging: args.logging,\n triggers: args.triggers,\n },\n { ...opts, parent: this },\n )\n })\n\n this.stdout = this.command.stdout\n this.stderr = this.command.stderr\n }\n\n static createTextFile(\n name: string,\n options: TextFileArgs,\n opts?: ComponentResourceOptions,\n ): Output<Command> {\n return output(options).apply(options => {\n const escapedContent = options.content.replace(/\"/g, '\\\\\"')\n\n const command = new Command(\n name,\n {\n host: options.host,\n create: interpolate`mkdir -p $(dirname ${options.path}) && echo \"${escapedContent}\" > ${options.path}`,\n delete: interpolate`rm -rf ${options.path}`,\n },\n opts,\n )\n\n return command\n })\n }\n\n static receiveTextFile(\n name: string,\n options: Omit<TextFileArgs, \"content\">,\n opts?: ComponentResourceOptions,\n ): Output<Command> {\n return output(options).apply(options => {\n const command = new Command(\n name,\n {\n host: options.host,\n create: interpolate`while ! test -f ${options.path}; do sleep 1; done; cat ${options.path}`,\n logging: \"stderr\",\n },\n opts,\n )\n\n return command\n })\n }\n}\n","import type { ArrayPatchMode, dns, network } from \"@highstate/library\"\nimport {\n ComponentResource,\n normalize,\n output,\n Output,\n Resource,\n toPromise,\n type Input,\n type InputArray,\n type InputOrArray,\n type ResourceOptions,\n type Unwrap,\n} from \"@highstate/pulumi\"\nimport { capitalize, groupBy, uniqueBy } from \"remeda\"\nimport { Command, type CommandHost } from \"./command\"\nimport {\n filterEndpoints,\n l34EndpointToString,\n l3EndpointToString,\n parseL3Endpoint,\n type InputL3Endpoint,\n} from \"./network\"\n\nexport type DnsRecordArgs = {\n /**\n * The DNS provider to use.\n */\n provider: Input<dns.Provider>\n\n /**\n * The name of the DNS record.\n * If not provided, the name of the resource will be used.\n */\n name?: Input<string>\n\n /**\n * The type of the DNS record.\n *\n * If not provided, will be automatically detected based on the value.\n */\n type?: Input<string>\n\n /**\n * The value of the DNS record.\n */\n value: Input<InputL3Endpoint>\n\n /**\n * Whether the DNS record is proxied (e.g. to provide DDoS protection).\n *\n * Available only for public IPs and some DNS providers like Cloudflare.\n * If not supported, the DNS provider will ignore this value.\n */\n proxied?: Input<boolean>\n\n /**\n * The TTL of the DNS record.\n *\n * If not provided, the DNS provider will use its default value.\n */\n ttl?: Input<number>\n\n /**\n * The priority of the DNS record.\n *\n * Only used for some DNS record types (e.g. MX).\n */\n priority?: Input<number>\n\n /**\n * Wait for the DNS record to be created/updated at the specified environment(s) before continuing.\n */\n waitAt?: InputOrArray<CommandHost>\n}\n\nexport type ResolvedDnsRecordArgs = Unwrap<Omit<DnsRecordArgs, \"value\" | \"type\">> & {\n /**\n * The value of the DNS record.\n */\n value: string\n\n /**\n * The type of the DNS record.\n */\n type: string\n}\n\nexport type DnsRecordSetArgs = Omit<DnsRecordArgs, \"provider\" | \"value\"> & {\n /**\n * The DNS providers to use to create the DNS records.\n *\n * If multiple providers matched the specified domain, multiple DNS records will be created.\n */\n providers: Input<dns.Provider[]>\n\n /**\n * The value of the DNS record.\n */\n value?: Input<InputL3Endpoint>\n\n /**\n * The values of the DNS records.\n */\n values?: InputArray<InputL3Endpoint>\n}\n\nfunction getTypeByEndpoint(endpoint: network.L3Endpoint): string {\n switch (endpoint.type) {\n case \"ipv4\":\n return \"A\"\n case \"ipv6\":\n return \"AAAA\"\n case \"hostname\":\n return \"CNAME\"\n }\n}\n\nexport abstract class DnsRecord extends ComponentResource {\n /**\n * The underlying dns record resource.\n */\n public readonly dnsRecord: Output<Resource>\n\n /**\n * The wait commands to be executed after the DNS record is created/updated.\n *\n * Use this field as a dependency for other resources.\n */\n public readonly waitCommands: Output<Command[]>\n\n protected constructor(name: string, args: DnsRecordArgs, opts?: ResourceOptions) {\n super(\"highstate:common:DnsRecord\", name, args, opts)\n\n this.dnsRecord = output(args).apply(args => {\n const l3Endpoint = parseL3Endpoint(args.value)\n const type = args.type ?? getTypeByEndpoint(l3Endpoint)\n\n return output(\n this.create(\n name,\n {\n ...args,\n type,\n value: l3EndpointToString(l3Endpoint),\n },\n { ...opts, parent: this },\n ),\n )\n })\n\n this.waitCommands = output(args).apply(args => {\n const waitAt = args.waitAt ? (Array.isArray(args.waitAt) ? args.waitAt : [args.waitAt]) : []\n\n return waitAt.map(host => {\n const hostname = host === \"local\" ? \"local\" : host.hostname\n\n return new Command(\n `${name}-wait-${hostname}`,\n {\n host,\n create: `while ! getent hosts ${args.name} >/dev/null; do echo \"Waiting for DNS record ${args.name} to be created\"; sleep 5; done`,\n triggers: [args.type, args.ttl, args.priority, args.proxied],\n },\n { parent: this },\n )\n })\n })\n }\n\n protected abstract create(\n name: string,\n args: ResolvedDnsRecordArgs,\n opts?: ResourceOptions,\n ): Input<Resource>\n\n static create(name: string, args: DnsRecordArgs, opts?: ResourceOptions): Output<DnsRecord> {\n return output(args).apply(async args => {\n const providerType = args.provider.type\n const implName = `${capitalize(providerType)}DnsRecord`\n const implModule = (await import(`@highstate/${providerType}`)) as Record<string, unknown>\n\n const implClass = implModule[implName] as new (\n name: string,\n args: Unwrap<DnsRecordArgs>,\n opts?: ResourceOptions,\n ) => DnsRecord\n\n return new implClass(name, args, opts)\n })\n }\n}\n\nexport class DnsRecordSet extends ComponentResource {\n /**\n * The underlying dns record resources.\n */\n public readonly dnsRecords: Output<DnsRecord[]>\n\n /**\n * The wait commands to be executed after the DNS records are created/updated.\n */\n public readonly waitCommands: Output<Command[]>\n\n private constructor(name: string, records: Output<DnsRecord[]>, opts?: ResourceOptions) {\n super(\"highstate:common:DnsRecordSet\", name, records, opts)\n\n this.dnsRecords = records\n\n this.waitCommands = records.apply(records =>\n records.flatMap(record => record.waitCommands),\n ) as unknown as Output<Command[]>\n }\n\n static create(name: string, args: DnsRecordSetArgs, opts?: ResourceOptions): DnsRecordSet {\n const records = output(args).apply(args => {\n const recordName = args.name ?? name\n const values = normalize(args.value, args.values)\n\n return output(\n args.providers\n .filter(provider => recordName.endsWith(provider.domain))\n .flatMap(provider => {\n return values.map(value => {\n const l3Endpoint = parseL3Endpoint(value)\n\n return DnsRecord.create(\n `${provider.type}-from-${recordName}-to-${l3EndpointToString(l3Endpoint)}`,\n { name: recordName, ...args, value: l3Endpoint, provider },\n opts,\n )\n })\n }),\n )\n })\n\n return new DnsRecordSet(name, records, opts)\n }\n}\n\n/**\n * Registers the DNS record set for the given endpoints and prepends the corresponding hostname endpoint to the list.\n *\n * Waits for the DNS record set to be created/updated before continuing.\n *\n * Ignores the \"hostname\" endpoints in the list.\n *\n * @param endpoints The list of endpoints to register. Will be modified in place.\n * @param fqdn The FQDN to register the DNS record set for. If not provided, no DNS record set will be created and array will not be modified.\n * @param fqdnEndpointFilter The filter to apply to the endpoints before passing them to the DNS record set. Does not apply to the resulted endpoint list.\n * @param dnsProviders The DNS providers to use to create the DNS records.\n */\nexport async function updateEndpointsWithFqdn<TEndpoint extends network.L34Endpoint>(\n endpoints: Input<TEndpoint[]>,\n fqdn: string | undefined,\n fqdnEndpointFilter: network.EndpointFilter,\n patchMode: ArrayPatchMode,\n dnsProviders: Input<dns.Provider[]>,\n): Promise<{ endpoints: TEndpoint[]; dnsRecordSet: DnsRecordSet | undefined }> {\n const resolvedEndpoints = await toPromise(endpoints)\n\n if (!fqdn) {\n return {\n endpoints: resolvedEndpoints as TEndpoint[],\n dnsRecordSet: undefined,\n }\n }\n\n const filteredEndpoints = filterEndpoints(resolvedEndpoints, fqdnEndpointFilter)\n\n const dnsRecordSet = DnsRecordSet.create(fqdn, {\n providers: dnsProviders,\n values: filteredEndpoints,\n waitAt: \"local\",\n })\n\n const portProtocolGroups = groupBy(filteredEndpoints, endpoint =>\n endpoint.port ? `${endpoint.port}-${endpoint.protocol}` : \"\",\n )\n\n const newEndpoints: TEndpoint[] = []\n\n for (const group of Object.values(portProtocolGroups)) {\n newEndpoints.unshift({\n type: \"hostname\",\n hostname: fqdn,\n visibility: group[0].visibility,\n port: group[0].port,\n protocol: group[0].protocol,\n } as TEndpoint)\n }\n\n await toPromise(\n dnsRecordSet.waitCommands.apply(waitCommands => waitCommands.map(command => command.stdout)),\n )\n\n if (patchMode === \"prepend\") {\n return {\n endpoints: uniqueBy(\n //\n [...newEndpoints, ...(resolvedEndpoints as TEndpoint[])],\n endpoint => l34EndpointToString(endpoint),\n ),\n dnsRecordSet,\n }\n }\n\n return {\n endpoints: newEndpoints,\n dnsRecordSet,\n }\n}\n","import { randomBytes } from \"@noble/hashes/utils\"\nimport { secureMask } from \"micro-key-producer/password.js\"\n\nexport function generatePassword() {\n return secureMask.apply(randomBytes(32)).password\n}\n","import type { common, network, ssh } from \"@highstate/library\"\nimport {\n getOrCreateSecret,\n getUnitInstanceName,\n output,\n Output,\n secret,\n type Input,\n type InstanceTerminal,\n} from \"@highstate/pulumi\"\nimport getKeys, { PrivateExport } from \"micro-key-producer/ssh.js\"\nimport { randomBytes } from \"micro-key-producer/utils.js\"\nimport { local, remote } from \"@pulumi/command\"\nimport { l3EndpointToString, l3ToL4Endpoint, l4EndpointToString } from \"./network\"\n\nexport function createSshTerminal(\n credentials: Input<ssh.Credentials | undefined>,\n): Output<InstanceTerminal | undefined> {\n return output(credentials).apply(credentials => {\n if (!credentials) {\n return undefined\n }\n\n const command = [\"ssh\", \"-tt\", \"-o\", \"UserKnownHostsFile=/known_hosts\"]\n\n // TODO: select best endpoint based on the environment\n const endpoint = credentials.endpoints[0]\n\n command.push(\"-p\", endpoint.port.toString())\n\n if (credentials.keyPair) {\n command.push(\"-i\", \"/private_key\")\n }\n\n command.push(`${credentials.user}@${l3EndpointToString(endpoint)}`)\n\n if (credentials.password) {\n command.unshift(\"sshpass\", \"-f\", \"/password\")\n }\n\n return {\n name: \"ssh\",\n title: `SSH: ${getUnitInstanceName()}`,\n description: \"Connect to the server via SSH\",\n image: \"ghcr.io/exeteres/highstate/terminal-ssh\",\n command,\n\n files: {\n \"/password\": credentials.password,\n\n \"/private_key\": {\n content: credentials.keyPair?.privateKey,\n mode: 0o600,\n },\n\n \"/known_hosts\": {\n content: `${l4EndpointToString(endpoint)} ${credentials.hostKey}`,\n mode: 0o644,\n },\n },\n }\n })\n}\n\nexport function generatePrivateKey(): string {\n const seed = randomBytes(32)\n\n return getKeys(seed).privateKey\n}\n\nexport function privateKeyToKeyPair(privateKeyString: Input<string>): Output<ssh.KeyPair> {\n return output(privateKeyString).apply(privateKeyString => {\n const privateKeyStruct = PrivateExport.decode(privateKeyString)\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const privKey = privateKeyStruct.keys[0].privKey.privKey as Uint8Array\n\n const { fingerprint, publicKey, privateKey } = getKeys(privKey.slice(0, 32))\n\n return output({\n type: \"ed25519\" as const,\n fingerprint,\n publicKey,\n privateKey: secret(privateKey),\n })\n })\n}\n\nexport type SshKeyPairInputs = {\n sshKeyPair?: Input<ssh.KeyPair>\n}\n\nexport type SshKeyPairSecrets = {\n sshPrivateKey?: Input<string>\n}\n\nexport function getOrCreateSshKeyPair(\n inputs: SshKeyPairInputs,\n secrets: Output<SshKeyPairSecrets>,\n): Output<ssh.KeyPair> {\n if (inputs.sshKeyPair) {\n return output(inputs.sshKeyPair)\n }\n\n const privateKey = getOrCreateSecret(secrets, \"sshPrivateKey\", generatePrivateKey)\n\n return privateKey.apply(privateKeyToKeyPair)\n}\n\nexport function createServerEntity(\n fallbackHostname: string,\n endpoint: network.L3Endpoint,\n sshPort = 22,\n sshUser = \"root\",\n sshPassword?: Input<string | undefined>,\n sshPrivateKey?: Input<string>,\n): Output<common.Server> {\n const connection = output({\n host: l3EndpointToString(endpoint),\n port: sshPort,\n user: sshUser,\n password: sshPassword,\n privateKey: sshPrivateKey,\n dialErrorLimit: 3,\n })\n\n const command = new local.Command(\"check-ssh\", {\n create: `nc -zv ${l3EndpointToString(endpoint)} ${sshPort} && echo \"up\" || echo \"down\"`,\n })\n\n return command.stdout.apply(result => {\n if (result === \"down\") {\n return output({\n hostname: fallbackHostname,\n endpoints: [endpoint],\n })\n }\n\n const hostnameResult = new remote.Command(\"hostname\", {\n connection,\n create: \"hostname\",\n triggers: [Date.now()],\n })\n\n const hostKeyResult = new remote.Command(\"host-key\", {\n connection,\n create: \"cat /etc/ssh/ssh_host_ed25519_key.pub\",\n triggers: [Date.now()],\n })\n\n return output({\n endpoints: [endpoint],\n hostname: hostnameResult.stdout.apply(x => x.trim()),\n ssh: {\n endpoints: [l3ToL4Endpoint(endpoint, sshPort)],\n user: sshUser,\n hostKey: hostKeyResult.stdout.apply(x => x.trim()),\n password: sshPassword,\n keyPair: sshPrivateKey ? privateKeyToKeyPair(sshPrivateKey) : undefined,\n },\n })\n })\n}\n"],"mappings":";AACA,SAAS,iBAA6B;AACtC,SAAS,gBAAgB;AAyBlB,SAAS,mBAAmB,YAAwC;AACzE,UAAQ,WAAW,MAAM;AAAA,IACvB,KAAK;AACH,aAAO,WAAW;AAAA,IACpB,KAAK;AACH,aAAO,WAAW;AAAA,IACpB,KAAK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IAAII,OAAM,QAAQ,aAAa;AAAA,IAC7C,QAAQ,UAAU,mBAAmB,QAAQ,CAAC,IAAI,OAAO;AAAA,EAC3D,CAAC;AAED,SAAO,QAAQ,OAAO,MAAM,YAAU;AACpC,QAAI,WAAW,QAAQ;AACrB,aAAOJ,QAAO;AAAA,QACZ,UAAU;AAAA,QACV,WAAW,CAAC,QAAQ;AAAA,MACtB,CAAC;AAAA,IACH;AAEA,UAAM,iBAAiB,IAAIK,QAAO,QAAQ,YAAY;AAAA,MACpD;AAAA,MACA,QAAQ;AAAA,MACR,UAAU,CAAC,KAAK,IAAI,CAAC;AAAA,IACvB,CAAC;AAED,UAAM,gBAAgB,IAAIA,QAAO,QAAQ,YAAY;AAAA,MACnD;AAAA,MACA,QAAQ;AAAA,MACR,UAAU,CAAC,KAAK,IAAI,CAAC;AAAA,IACvB,CAAC;AAED,WAAOL,QAAO;AAAA,MACZ,WAAW,CAAC,QAAQ;AAAA,MACpB,UAAU,eAAe,OAAO,MAAM,OAAK,EAAE,KAAK,CAAC;AAAA,MACnD,KAAK;AAAA,QACH,WAAW,CAAC,eAAe,UAAU,OAAO,CAAC;AAAA,QAC7C,MAAM;AAAA,QACN,SAAS,cAAc,OAAO,MAAM,OAAK,EAAE,KAAK,CAAC;AAAA,QACjD,UAAU;AAAA,QACV,SAAS,gBAAgB,oBAAoB,aAAa,IAAI;AAAA,MAChE;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":["ssh","args","options","ComponentResource","output","toPromise","uniqueBy","ComponentResource","output","args","records","toPromise","uniqueBy","output","randomBytes","local","remote","output","credentials","randomBytes","privateKeyString","local","remote"]}
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "sourceHashes": {
3
- "./dist/index.js": "72c0b335a1996396fb5cd11e2f50e32ac46112062e5d6a8d995fe1c09465c710",
4
- "./dist/units/dns/record-set/index.js": "8875747bcfdea0f4af4bf1172938751bcc1e1e3262fd73975c16194e97c65aab",
5
- "./dist/units/network/l3-endpoint/index.js": "5af399fbc653ab8d4fef499c04ef90ffd106156af1947dc024f649c8d36a17d2",
6
- "./dist/units/network/l4-endpoint/index.js": "aabc2a23b8977f6aac0e3e7ce64c44ea4656e13b65d36d586f7ff8e1bfde5d4b",
7
- "./dist/units/existing-server/index.js": "7a50a5ba150556cfa440b5dd977376ebe4d16165f92d1175e688bf1a3b52e6ab",
8
- "./dist/units/ssh/key-pair/index.js": "f88c29988f14fd81ba88219ae445c42476e734b2784f488de5aae8f5f0c77f4a",
9
- "./dist/units/script/index.js": "bd095cdd005451ea8efc18837e9ff95ae152acc7374e15d2f02870c2cc1a2f98",
10
- "./dist/units/server-dns/index.js": "05248c338318a9761fe7497e113d3e2afe8d3167bbb3554d8014fc63abe3ff8b",
11
- "./dist/units/server-patch/index.js": "50d26e714bb3156e89a70b09be79cb66a0d3bdf764443bb1a336960a603759eb"
3
+ "./dist/index.js": "4ea6aff91a7c0d3e830ef8993b8203b102ecb1508dcd53f24a6ee161c40b5377",
4
+ "./dist/units/dns/record-set/index.js": "9681cd073b2952d51e42e3e34687b28ce768a62de35befb4c60369f2efb7deaa",
5
+ "./dist/units/network/l3-endpoint/index.js": "3c1a1dd6793647faab90007729377cdd0ba7b8cc6f2bce79f5af8148adaf7b65",
6
+ "./dist/units/network/l4-endpoint/index.js": "83536fa13db962cd20d47c88746bba54de08fc7fa75fde7f1aee48381c8dfa70",
7
+ "./dist/units/existing-server/index.js": "8a1a23b991861f7d45dc1e06856979b756a28dda3c4d51e17ef9f918474874c2",
8
+ "./dist/units/ssh/key-pair/index.js": "65a0d3b5207e34fc5a1304ea7af599edfdfaba28eff63c203fd14e04e477c312",
9
+ "./dist/units/script/index.js": "aaf046a1d10fc6e126cb9e6208ae7f4b827e3804a20b11724782b21bd0c09805",
10
+ "./dist/units/server-dns/index.js": "b292750ad381a22eb7abc9d3a0efebf78a476bbac6ff3d0bb79144530e80facc",
11
+ "./dist/units/server-patch/index.js": "9f4c0a2c95b34cbb587d93eba7ff72826cf2fc6d72e56bd430073c0ea26f092e"
12
12
  }
13
13
  }
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  requireInputL4Endpoint,
23
23
  updateEndpoints,
24
24
  updateEndpointsWithFqdn
25
- } from "./chunk-USV6SHAU.js";
25
+ } from "./chunk-INONQX2G.js";
26
26
  export {
27
27
  Command,
28
28
  DnsRecord,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DnsRecordSet
3
- } from "../../../chunk-USV6SHAU.js";
3
+ } from "../../../chunk-INONQX2G.js";
4
4
 
5
5
  // src/units/dns/record-set/index.ts
6
6
  import { dns } from "@highstate/library";
@@ -3,7 +3,7 @@ import {
3
3
  createSshTerminal,
4
4
  l3EndpointToString,
5
5
  requireInputL3Endpoint
6
- } from "../../chunk-USV6SHAU.js";
6
+ } from "../../chunk-INONQX2G.js";
7
7
 
8
8
  // src/units/existing-server/index.ts
9
9
  import { common } from "@highstate/library";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  parseL3Endpoint
3
- } from "../../../chunk-USV6SHAU.js";
3
+ } from "../../../chunk-INONQX2G.js";
4
4
 
5
5
  // src/units/network/l3-endpoint/index.ts
6
6
  import { network } from "@highstate/library";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  parseL4Endpoint
3
- } from "../../../chunk-USV6SHAU.js";
3
+ } from "../../../chunk-INONQX2G.js";
4
4
 
5
5
  // src/units/network/l4-endpoint/index.ts
6
6
  import { network } from "@highstate/library";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Command
3
- } from "../../chunk-USV6SHAU.js";
3
+ } from "../../chunk-INONQX2G.js";
4
4
 
5
5
  // src/units/script/index.ts
6
6
  import { common } from "@highstate/library";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  l3EndpointToString,
3
3
  updateEndpointsWithFqdn
4
- } from "../../chunk-USV6SHAU.js";
4
+ } from "../../chunk-INONQX2G.js";
5
5
 
6
6
  // src/units/server-dns/index.ts
7
7
  import { common } from "@highstate/library";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  l3EndpointToString,
3
3
  updateEndpoints
4
- } from "../../chunk-USV6SHAU.js";
4
+ } from "../../chunk-INONQX2G.js";
5
5
 
6
6
  // src/units/server-patch/index.ts
7
7
  import { common } from "@highstate/library";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  generatePrivateKey,
3
3
  privateKeyToKeyPair
4
- } from "../../../chunk-USV6SHAU.js";
4
+ } from "../../../chunk-INONQX2G.js";
5
5
 
6
6
  // src/units/ssh/key-pair/index.ts
7
7
  import { ssh } from "@highstate/library";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@highstate/common",
3
- "version": "0.9.8",
3
+ "version": "0.9.10",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -27,15 +27,15 @@
27
27
  "build": "highstate build"
28
28
  },
29
29
  "dependencies": {
30
- "@highstate/library": "^0.9.8",
31
- "@highstate/pulumi": "^0.9.8",
30
+ "@highstate/library": "^0.9.10",
31
+ "@highstate/pulumi": "^0.9.10",
32
32
  "@noble/hashes": "^1.7.1",
33
33
  "@pulumi/command": "^1.0.2",
34
34
  "micro-key-producer": "^0.7.3",
35
35
  "remeda": "^2.21.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@highstate/cli": "^0.9.8"
38
+ "@highstate/cli": "^0.9.10"
39
39
  },
40
- "gitHead": "036db4d9937ff30edf15f143482c5702e5b7a7fb"
40
+ "gitHead": "aacf8837fdf40f2bb2f83d4c11b35a358e26ec33"
41
41
  }
package/src/shared/dns.ts CHANGED
@@ -225,7 +225,7 @@ export class DnsRecordSet extends ComponentResource {
225
225
  const l3Endpoint = parseL3Endpoint(value)
226
226
 
227
227
  return DnsRecord.create(
228
- `${provider.type}-from-${provider.name}-to-${l3EndpointToString(l3Endpoint)}`,
228
+ `${provider.type}-from-${recordName}-to-${l3EndpointToString(l3Endpoint)}`,
229
229
  { name: recordName, ...args, value: l3Endpoint, provider },
230
230
  opts,
231
231
  )
@@ -232,26 +232,27 @@ export function l3ToL4Endpoint(
232
232
  *
233
233
  * @param endpoints The list of endpoints to filter.
234
234
  * @param filter The filter to apply. If not provided, the endpoints will be filtered by the most accessible type: `public` > `external` > `internal`.
235
+ * @param types The list of endpoint types to filter by. If provided, only endpoints of these types will be returned.
235
236
  *
236
237
  * @returns The filtered list of endpoints.
237
238
  */
238
239
  export function filterEndpoints<TEndpoint extends network.L34Endpoint>(
239
240
  endpoints: TEndpoint[],
240
241
  filter?: network.EndpointFilter,
242
+ types?: network.L34Endpoint["type"][],
241
243
  ): TEndpoint[] {
242
244
  if (filter?.length) {
243
- return endpoints.filter(endpoint => filter.includes(endpoint.visibility))
245
+ endpoints = endpoints.filter(endpoint => filter.includes(endpoint.visibility))
246
+ } else if (endpoints.some(endpoint => endpoint.visibility === "public")) {
247
+ endpoints = endpoints.filter(endpoint => endpoint.visibility === "public")
248
+ } else if (endpoints.some(endpoint => endpoint.visibility === "external")) {
249
+ endpoints = endpoints.filter(endpoint => endpoint.visibility === "external")
244
250
  }
245
251
 
246
- if (endpoints.some(endpoint => endpoint.visibility === "public")) {
247
- return endpoints.filter(endpoint => endpoint.visibility === "public")
252
+ if (types && types.length) {
253
+ endpoints = endpoints.filter(endpoint => types.includes(endpoint.type))
248
254
  }
249
255
 
250
- if (endpoints.some(endpoint => endpoint.visibility === "external")) {
251
- return endpoints.filter(endpoint => endpoint.visibility === "external")
252
- }
253
-
254
- // in this case all endpoints are already internal
255
256
  return endpoints
256
257
  }
257
258
 
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/shared/network.ts","../src/shared/command.ts","../src/shared/dns.ts","../src/shared/passwords.ts","../src/shared/ssh.ts"],"sourcesContent":["import type { ArrayPatchMode, network } from \"@highstate/library\"\nimport { toPromise, type Input } from \"@highstate/pulumi\"\nimport { uniqueBy } from \"remeda\"\n\n/**\n * The L3 or L4 endpoint for some service.\n *\n * The format is: `[protocol://]endpoint[:port]`\n */\nexport type InputL34Endpoint = network.L34Endpoint | string\n\n/**\n * The L3 endpoint for some service.\n */\nexport type InputL3Endpoint = network.L3Endpoint | string\n\n/**\n * The L4 endpoint for some service.\n */\nexport type InputL4Endpoint = network.L4Endpoint | string\n\n/**\n * Stringifies a L3 endpoint object into a string.\n *\n * @param l3Endpoint The L3 endpoint object to stringify.\n * @returns The string representation of the L3 endpoint.\n */\nexport function l3EndpointToString(l3Endpoint: network.L3Endpoint): string {\n switch (l3Endpoint.type) {\n case \"ipv4\":\n return l3Endpoint.address\n case \"ipv6\":\n return l3Endpoint.address\n case \"hostname\":\n return l3Endpoint.hostname\n }\n}\n\n/**\n * Stringifies a L4 endpoint object into a string.\n *\n * @param l4Endpoint The L4 endpoint object to stringify.\n *\n * @returns The string representation of the L4 endpoint.\n */\nexport function l4EndpointToString(l4Endpoint: network.L4Endpoint): string {\n if (l4Endpoint.type === \"ipv6\") {\n return `[${l4Endpoint.address}]:${l4Endpoint.port}`\n }\n\n return `${l3EndpointToString(l4Endpoint)}:${l4Endpoint.port}`\n}\n\n/**\n * Stringifies a L3 or L4 endpoint object into a string.\n *\n * @param l34Endpoint The L3 or L4 endpoint object to stringify.\n * @returns The string representation of the L3 or L4 endpoint.\n */\nexport function l34EndpointToString(l34Endpoint: network.L34Endpoint): string {\n if (l34Endpoint.port) {\n return l4EndpointToString(l34Endpoint)\n }\n\n return l3EndpointToString(l34Endpoint)\n}\n\nconst L34_ENDPOINT_RE =\n /^(?:(?<protocol>[a-z]+):\\/\\/)?(?:(?:\\[?(?<ipv6>[0-9A-Fa-f:]+)\\]?)|(?<ipv4>(?:\\d{1,3}\\.){3}\\d{1,3})|(?<hostname>[a-zA-Z0-9-*]+(?:\\.[a-zA-Z0-9-*]+)*))(?::(?<port>\\d{1,5}))?$/\n\n/**\n * Parses a L3 or L4 endpoint from a string.\n *\n * The format is `[protocol://]endpoint[:port]`.\n *\n * @param l34Endpoint The L3 or L4 endpoint string to parse.\n * @returns The parsed L3 or L4 endpoint object.\n */\nexport function parseL34Endpoint(l34Endpoint: InputL34Endpoint): network.L34Endpoint {\n if (typeof l34Endpoint === \"object\") {\n return l34Endpoint\n }\n\n const match = l34Endpoint.match(L34_ENDPOINT_RE)\n if (!match) {\n throw new Error(`Invalid L3/L4 endpoint: \"${l34Endpoint}\"`)\n }\n\n const { protocol, ipv6, ipv4, hostname, port } = match.groups!\n\n if (protocol && protocol !== \"tcp\" && protocol !== \"udp\") {\n throw new Error(`Invalid L4 endpoint protocol: \"${protocol}\"`)\n }\n\n let visibility: network.EndpointVisibility = \"public\"\n\n if (ipv4 && IPV4_PRIVATE_REGEX.test(ipv4)) {\n visibility = \"external\"\n } else if (ipv6 && IPV6_PRIVATE_REGEX.test(ipv6)) {\n visibility = \"external\"\n }\n\n const fallbackProtocol = port ? \"tcp\" : undefined\n\n return {\n type: ipv6 ? \"ipv6\" : ipv4 ? \"ipv4\" : \"hostname\",\n visibility,\n address: ipv6 || ipv4,\n hostname: hostname,\n port: port ? parseInt(port, 10) : undefined,\n protocol: protocol ? (protocol as network.L4Protocol) : fallbackProtocol,\n } as network.L34Endpoint\n}\n\n/**\n * Parses a L3 endpoint from a string.\n *\n * The same as `parseL34Endpoint`, but only for L3 endpoints and will throw an error if the endpoint contains a port.\n *\n * @param l3Endpoint The L3 endpoint string to parse.\n * @returns The parsed L3 endpoint object.\n */\nexport function parseL3Endpoint(l3Endpoint: InputL3Endpoint): network.L3Endpoint {\n if (typeof l3Endpoint === \"object\") {\n return l3Endpoint\n }\n\n const parsed = parseL34Endpoint(l3Endpoint)\n\n if (parsed.port) {\n throw new Error(`Port cannot be specified in L3 endpoint: \"${l3Endpoint}\"`)\n }\n\n return parsed\n}\n\n/**\n * Parses a L4 endpoint from a string.\n *\n * The same as `parseL34Endpoint`, but only for L4 endpoints and will throw an error if the endpoint does not contain a port.\n */\nexport function parseL4Endpoint(l4Endpoint: InputL4Endpoint): network.L4Endpoint {\n if (typeof l4Endpoint === \"object\") {\n return l4Endpoint\n }\n\n const parsed = parseL34Endpoint(l4Endpoint)\n\n if (!parsed.port) {\n throw new Error(`No port found in L4 endpoint: \"${l4Endpoint}\"`)\n }\n\n return parsed\n}\n\nconst IPV4_PRIVATE_REGEX =\n /^(?:10|127)(?:\\.\\d{1,3}){3}$|^(?:172\\.1[6-9]|172\\.2[0-9]|172\\.3[0-1])(?:\\.\\d{1,3}){2}$|^(?:192\\.168)(?:\\.\\d{1,3}){2}$/\n\nconst IPV6_PRIVATE_REGEX =\n /^(?:fc|fd)(?:[0-9a-f]{2}){0,2}::(?:[0-9a-f]{1,4}:){7}[0-9a-f]{1,4}$|^::(?:ffff:(?:10|127)(?:\\.\\d{1,3}){3}|(?:172\\.1[6-9]|172\\.2[0-9]|172\\.3[0-1])(?:\\.\\d{1,3}){2}|(?:192\\.168)(?:\\.\\d{1,3}){2})$/\n\n/**\n * Helper function to get the input L3 endpoint from the raw endpoint or input endpoint.\n *\n * If neither is provided, an error is thrown.\n *\n * @param rawEndpoint The raw endpoint string to parse.\n * @param inputEndpoint The input endpoint object to use if the raw endpoint is not provided.\n * @returns The parsed L3 endpoint object.\n */\nexport async function requireInputL3Endpoint(\n rawEndpoint: string | undefined,\n inputEndpoint: Input<network.L3Endpoint> | undefined,\n): Promise<network.L3Endpoint> {\n if (rawEndpoint) {\n return parseL3Endpoint(rawEndpoint)\n }\n\n if (inputEndpoint) {\n return toPromise(inputEndpoint)\n }\n\n throw new Error(\"No endpoint provided\")\n}\n\n/**\n * Helper function to get the input L4 endpoint from the raw endpoint or input endpoint.\n *\n * If neither is provided, an error is thrown.\n *\n * @param rawEndpoint The raw endpoint string to parse.\n * @param inputEndpoint The input endpoint object to use if the raw endpoint is not provided.\n * @returns The parsed L4 endpoint object.\n */\nexport async function requireInputL4Endpoint(\n rawEndpoint: string | undefined,\n inputEndpoint: Input<network.L4Endpoint> | undefined,\n): Promise<network.L4Endpoint> {\n if (rawEndpoint) {\n return parseL4Endpoint(rawEndpoint)\n }\n\n if (inputEndpoint) {\n return toPromise(inputEndpoint)\n }\n\n throw new Error(\"No endpoint provided\")\n}\n\n/**\n * Convers L3 endpoint to L4 endpoint by adding a port and protocol.\n *\n * @param l3Endpoint The L3 endpoint to convert.\n * @param port The port to add to the L3 endpoint.\n * @param protocol The protocol to add to the L3 endpoint. Defaults to \"tcp\".\n * @returns The L4 endpoint with the port and protocol added.\n */\nexport function l3ToL4Endpoint(\n l3Endpoint: InputL3Endpoint,\n port: number,\n protocol: network.L4Protocol = \"tcp\",\n): network.L4Endpoint {\n return {\n ...parseL3Endpoint(l3Endpoint),\n port,\n protocol,\n }\n}\n\n/**\n * Filters the endpoints based on the given filter.\n *\n * @param endpoints The list of endpoints to filter.\n * @param filter The filter to apply. If not provided, the endpoints will be filtered by the most accessible type: `public` > `external` > `internal`.\n *\n * @returns The filtered list of endpoints.\n */\nexport function filterEndpoints<TEndpoint extends network.L34Endpoint>(\n endpoints: TEndpoint[],\n filter?: network.EndpointFilter,\n): TEndpoint[] {\n if (filter?.length) {\n return endpoints.filter(endpoint => filter.includes(endpoint.visibility))\n }\n\n if (endpoints.some(endpoint => endpoint.visibility === \"public\")) {\n return endpoints.filter(endpoint => endpoint.visibility === \"public\")\n }\n\n if (endpoints.some(endpoint => endpoint.visibility === \"external\")) {\n return endpoints.filter(endpoint => endpoint.visibility === \"external\")\n }\n\n // in this case all endpoints are already internal\n return endpoints\n}\n\n/**\n * Converts a L3 endpoint to CIDR notation.\n *\n * If the endpoint is a hostname, an error is thrown.\n *\n * @param l3Endpoint The L3 endpoint to convert.\n * @returns The CIDR notation of the L3 endpoint.\n */\nexport function l3EndpointToCidr(l3Endpoint: network.L3Endpoint): string {\n switch (l3Endpoint.type) {\n case \"ipv4\":\n return `${l3Endpoint.address}/32`\n case \"ipv6\":\n return `${l3Endpoint.address}/128`\n case \"hostname\":\n throw new Error(\"Cannot convert hostname to CIDR\")\n }\n}\n\n/**\n * Updates the endpoints based on the given mode.\n *\n * @param currentEndpoints The current endpoints to update.\n * @param endpoints The new endpoints to add in string format.\n * @param inputEndpoints The input endpoints to add in object format.\n * @param mode The mode to use when updating the endpoints. Can be \"replace\" or \"prepend\". Defaults to \"prepend\".\n *\n * @returns The updated list of endpoints.\n */\nexport async function updateEndpoints<TEdnpoints extends network.L34Endpoint>(\n currentEndpoints: Input<TEdnpoints[]>,\n endpoints: string[],\n inputEndpoints: Input<TEdnpoints[]>,\n mode: ArrayPatchMode = \"prepend\",\n): Promise<TEdnpoints[]> {\n const resolvedCurrentEndpoints = await toPromise(currentEndpoints)\n const resolvedInputEndpoints = await toPromise(inputEndpoints)\n\n const newEndpoints = uniqueBy(\n //\n [...endpoints.map(parseL34Endpoint), ...resolvedInputEndpoints],\n endpoint => l34EndpointToString(endpoint),\n )\n\n if (mode === \"replace\") {\n return newEndpoints as TEdnpoints[]\n }\n\n return uniqueBy(\n //\n [...newEndpoints, ...resolvedCurrentEndpoints],\n endpoint => l34EndpointToString(endpoint),\n ) as TEdnpoints[]\n}\n","import { local, remote, type types } from \"@pulumi/command\"\nimport {\n ComponentResource,\n interpolate,\n output,\n type ComponentResourceOptions,\n type Input,\n type InputOrArray,\n type Output,\n} from \"@highstate/pulumi\"\nimport { common, ssh } from \"@highstate/library\"\nimport { l3EndpointToString } from \"./network\"\n\nexport function getServerConnection(\n ssh: Input<ssh.Credentials>,\n): Output<types.input.remote.ConnectionArgs> {\n return output(ssh).apply(ssh => ({\n host: l3EndpointToString(ssh.endpoints[0]),\n port: ssh.endpoints[0].port,\n user: ssh.user,\n password: ssh.password,\n privateKey: ssh.keyPair?.privateKey,\n dialErrorLimit: 3,\n hostKey: ssh.hostKey,\n }))\n}\n\nexport type CommandHost = \"local\" | common.Server\n\nexport type CommandArgs = {\n host: Input<CommandHost>\n create: Input<string>\n update?: Input<string>\n delete?: Input<string>\n logging?: Input<remote.Logging>\n triggers?: InputOrArray<unknown>\n}\n\nexport type TextFileArgs = {\n host: CommandHost\n path: Input<string>\n content: Input<string>\n}\n\nexport class Command extends ComponentResource {\n public readonly command: Output<local.Command | remote.Command>\n\n public readonly stdout: Output<string>\n public readonly stderr: Output<string>\n\n constructor(name: string, args: CommandArgs, opts?: ComponentResourceOptions) {\n super(\"highstate:common:Command\", name, args, opts)\n\n this.command = output(args).apply(args => {\n if (args.host === \"local\") {\n return new local.Command(\n name,\n {\n create: args.create,\n update: args.update,\n delete: args.delete,\n logging: args.logging,\n triggers: args.triggers,\n },\n { ...opts, parent: this },\n )\n }\n\n if (!args.host.ssh) {\n throw new Error(`The host \"${args.host.hostname}\" has no SSH credentials`)\n }\n\n return new remote.Command(\n name,\n {\n connection: getServerConnection(args.host.ssh),\n create: args.create,\n update: args.update,\n delete: args.delete,\n logging: args.logging,\n triggers: args.triggers,\n },\n { ...opts, parent: this },\n )\n })\n\n this.stdout = this.command.stdout\n this.stderr = this.command.stderr\n }\n\n static createTextFile(\n name: string,\n options: TextFileArgs,\n opts?: ComponentResourceOptions,\n ): Output<Command> {\n return output(options).apply(options => {\n const escapedContent = options.content.replace(/\"/g, '\\\\\"')\n\n const command = new Command(\n name,\n {\n host: options.host,\n create: interpolate`mkdir -p $(dirname ${options.path}) && echo \"${escapedContent}\" > ${options.path}`,\n delete: interpolate`rm -rf ${options.path}`,\n },\n opts,\n )\n\n return command\n })\n }\n\n static receiveTextFile(\n name: string,\n options: Omit<TextFileArgs, \"content\">,\n opts?: ComponentResourceOptions,\n ): Output<Command> {\n return output(options).apply(options => {\n const command = new Command(\n name,\n {\n host: options.host,\n create: interpolate`while ! test -f ${options.path}; do sleep 1; done; cat ${options.path}`,\n logging: \"stderr\",\n },\n opts,\n )\n\n return command\n })\n }\n}\n","import type { ArrayPatchMode, dns, network } from \"@highstate/library\"\nimport {\n ComponentResource,\n normalize,\n output,\n Output,\n Resource,\n toPromise,\n type Input,\n type InputArray,\n type InputOrArray,\n type ResourceOptions,\n type Unwrap,\n} from \"@highstate/pulumi\"\nimport { capitalize, groupBy, uniqueBy } from \"remeda\"\nimport { Command, type CommandHost } from \"./command\"\nimport {\n filterEndpoints,\n l34EndpointToString,\n l3EndpointToString,\n parseL3Endpoint,\n type InputL3Endpoint,\n} from \"./network\"\n\nexport type DnsRecordArgs = {\n /**\n * The DNS provider to use.\n */\n provider: Input<dns.Provider>\n\n /**\n * The name of the DNS record.\n * If not provided, the name of the resource will be used.\n */\n name?: Input<string>\n\n /**\n * The type of the DNS record.\n *\n * If not provided, will be automatically detected based on the value.\n */\n type?: Input<string>\n\n /**\n * The value of the DNS record.\n */\n value: Input<InputL3Endpoint>\n\n /**\n * Whether the DNS record is proxied (e.g. to provide DDoS protection).\n *\n * Available only for public IPs and some DNS providers like Cloudflare.\n * If not supported, the DNS provider will ignore this value.\n */\n proxied?: Input<boolean>\n\n /**\n * The TTL of the DNS record.\n *\n * If not provided, the DNS provider will use its default value.\n */\n ttl?: Input<number>\n\n /**\n * The priority of the DNS record.\n *\n * Only used for some DNS record types (e.g. MX).\n */\n priority?: Input<number>\n\n /**\n * Wait for the DNS record to be created/updated at the specified environment(s) before continuing.\n */\n waitAt?: InputOrArray<CommandHost>\n}\n\nexport type ResolvedDnsRecordArgs = Unwrap<Omit<DnsRecordArgs, \"value\" | \"type\">> & {\n /**\n * The value of the DNS record.\n */\n value: string\n\n /**\n * The type of the DNS record.\n */\n type: string\n}\n\nexport type DnsRecordSetArgs = Omit<DnsRecordArgs, \"provider\" | \"value\"> & {\n /**\n * The DNS providers to use to create the DNS records.\n *\n * If multiple providers matched the specified domain, multiple DNS records will be created.\n */\n providers: Input<dns.Provider[]>\n\n /**\n * The value of the DNS record.\n */\n value?: Input<InputL3Endpoint>\n\n /**\n * The values of the DNS records.\n */\n values?: InputArray<InputL3Endpoint>\n}\n\nfunction getTypeByEndpoint(endpoint: network.L3Endpoint): string {\n switch (endpoint.type) {\n case \"ipv4\":\n return \"A\"\n case \"ipv6\":\n return \"AAAA\"\n case \"hostname\":\n return \"CNAME\"\n }\n}\n\nexport abstract class DnsRecord extends ComponentResource {\n /**\n * The underlying dns record resource.\n */\n public readonly dnsRecord: Output<Resource>\n\n /**\n * The wait commands to be executed after the DNS record is created/updated.\n *\n * Use this field as a dependency for other resources.\n */\n public readonly waitCommands: Output<Command[]>\n\n protected constructor(name: string, args: DnsRecordArgs, opts?: ResourceOptions) {\n super(\"highstate:common:DnsRecord\", name, args, opts)\n\n this.dnsRecord = output(args).apply(args => {\n const l3Endpoint = parseL3Endpoint(args.value)\n const type = args.type ?? getTypeByEndpoint(l3Endpoint)\n\n return output(\n this.create(\n name,\n {\n ...args,\n type,\n value: l3EndpointToString(l3Endpoint),\n },\n { ...opts, parent: this },\n ),\n )\n })\n\n this.waitCommands = output(args).apply(args => {\n const waitAt = args.waitAt ? (Array.isArray(args.waitAt) ? args.waitAt : [args.waitAt]) : []\n\n return waitAt.map(host => {\n const hostname = host === \"local\" ? \"local\" : host.hostname\n\n return new Command(\n `${name}-wait-${hostname}`,\n {\n host,\n create: `while ! getent hosts ${args.name} >/dev/null; do echo \"Waiting for DNS record ${args.name} to be created\"; sleep 5; done`,\n triggers: [args.type, args.ttl, args.priority, args.proxied],\n },\n { parent: this },\n )\n })\n })\n }\n\n protected abstract create(\n name: string,\n args: ResolvedDnsRecordArgs,\n opts?: ResourceOptions,\n ): Input<Resource>\n\n static create(name: string, args: DnsRecordArgs, opts?: ResourceOptions): Output<DnsRecord> {\n return output(args).apply(async args => {\n const providerType = args.provider.type\n const implName = `${capitalize(providerType)}DnsRecord`\n const implModule = (await import(`@highstate/${providerType}`)) as Record<string, unknown>\n\n const implClass = implModule[implName] as new (\n name: string,\n args: Unwrap<DnsRecordArgs>,\n opts?: ResourceOptions,\n ) => DnsRecord\n\n return new implClass(name, args, opts)\n })\n }\n}\n\nexport class DnsRecordSet extends ComponentResource {\n /**\n * The underlying dns record resources.\n */\n public readonly dnsRecords: Output<DnsRecord[]>\n\n /**\n * The wait commands to be executed after the DNS records are created/updated.\n */\n public readonly waitCommands: Output<Command[]>\n\n private constructor(name: string, records: Output<DnsRecord[]>, opts?: ResourceOptions) {\n super(\"highstate:common:DnsRecordSet\", name, records, opts)\n\n this.dnsRecords = records\n\n this.waitCommands = records.apply(records =>\n records.flatMap(record => record.waitCommands),\n ) as unknown as Output<Command[]>\n }\n\n static create(name: string, args: DnsRecordSetArgs, opts?: ResourceOptions): DnsRecordSet {\n const records = output(args).apply(args => {\n const recordName = args.name ?? name\n const values = normalize(args.value, args.values)\n\n return output(\n args.providers\n .filter(provider => recordName.endsWith(provider.domain))\n .flatMap(provider => {\n return values.map(value => {\n const l3Endpoint = parseL3Endpoint(value)\n\n return DnsRecord.create(\n `${provider.type}-from-${provider.name}-to-${l3EndpointToString(l3Endpoint)}`,\n { name: recordName, ...args, value: l3Endpoint, provider },\n opts,\n )\n })\n }),\n )\n })\n\n return new DnsRecordSet(name, records, opts)\n }\n}\n\n/**\n * Registers the DNS record set for the given endpoints and prepends the corresponding hostname endpoint to the list.\n *\n * Waits for the DNS record set to be created/updated before continuing.\n *\n * Ignores the \"hostname\" endpoints in the list.\n *\n * @param endpoints The list of endpoints to register. Will be modified in place.\n * @param fqdn The FQDN to register the DNS record set for. If not provided, no DNS record set will be created and array will not be modified.\n * @param fqdnEndpointFilter The filter to apply to the endpoints before passing them to the DNS record set. Does not apply to the resulted endpoint list.\n * @param dnsProviders The DNS providers to use to create the DNS records.\n */\nexport async function updateEndpointsWithFqdn<TEndpoint extends network.L34Endpoint>(\n endpoints: Input<TEndpoint[]>,\n fqdn: string | undefined,\n fqdnEndpointFilter: network.EndpointFilter,\n patchMode: ArrayPatchMode,\n dnsProviders: Input<dns.Provider[]>,\n): Promise<{ endpoints: TEndpoint[]; dnsRecordSet: DnsRecordSet | undefined }> {\n const resolvedEndpoints = await toPromise(endpoints)\n\n if (!fqdn) {\n return {\n endpoints: resolvedEndpoints as TEndpoint[],\n dnsRecordSet: undefined,\n }\n }\n\n const filteredEndpoints = filterEndpoints(resolvedEndpoints, fqdnEndpointFilter)\n\n const dnsRecordSet = DnsRecordSet.create(fqdn, {\n providers: dnsProviders,\n values: filteredEndpoints,\n waitAt: \"local\",\n })\n\n const portProtocolGroups = groupBy(filteredEndpoints, endpoint =>\n endpoint.port ? `${endpoint.port}-${endpoint.protocol}` : \"\",\n )\n\n const newEndpoints: TEndpoint[] = []\n\n for (const group of Object.values(portProtocolGroups)) {\n newEndpoints.unshift({\n type: \"hostname\",\n hostname: fqdn,\n visibility: group[0].visibility,\n port: group[0].port,\n protocol: group[0].protocol,\n } as TEndpoint)\n }\n\n await toPromise(\n dnsRecordSet.waitCommands.apply(waitCommands => waitCommands.map(command => command.stdout)),\n )\n\n if (patchMode === \"prepend\") {\n return {\n endpoints: uniqueBy(\n //\n [...newEndpoints, ...(resolvedEndpoints as TEndpoint[])],\n endpoint => l34EndpointToString(endpoint),\n ),\n dnsRecordSet,\n }\n }\n\n return {\n endpoints: newEndpoints,\n dnsRecordSet,\n }\n}\n","import { randomBytes } from \"@noble/hashes/utils\"\nimport { secureMask } from \"micro-key-producer/password.js\"\n\nexport function generatePassword() {\n return secureMask.apply(randomBytes(32)).password\n}\n","import type { common, network, ssh } from \"@highstate/library\"\nimport {\n getOrCreateSecret,\n getUnitInstanceName,\n output,\n Output,\n secret,\n type Input,\n type InstanceTerminal,\n} from \"@highstate/pulumi\"\nimport getKeys, { PrivateExport } from \"micro-key-producer/ssh.js\"\nimport { randomBytes } from \"micro-key-producer/utils.js\"\nimport { local, remote } from \"@pulumi/command\"\nimport { l3EndpointToString, l3ToL4Endpoint, l4EndpointToString } from \"./network\"\n\nexport function createSshTerminal(\n credentials: Input<ssh.Credentials | undefined>,\n): Output<InstanceTerminal | undefined> {\n return output(credentials).apply(credentials => {\n if (!credentials) {\n return undefined\n }\n\n const command = [\"ssh\", \"-tt\", \"-o\", \"UserKnownHostsFile=/known_hosts\"]\n\n // TODO: select best endpoint based on the environment\n const endpoint = credentials.endpoints[0]\n\n command.push(\"-p\", endpoint.port.toString())\n\n if (credentials.keyPair) {\n command.push(\"-i\", \"/private_key\")\n }\n\n command.push(`${credentials.user}@${l3EndpointToString(endpoint)}`)\n\n if (credentials.password) {\n command.unshift(\"sshpass\", \"-f\", \"/password\")\n }\n\n return {\n name: \"ssh\",\n title: `SSH: ${getUnitInstanceName()}`,\n description: \"Connect to the server via SSH\",\n image: \"ghcr.io/exeteres/highstate/terminal-ssh\",\n command,\n\n files: {\n \"/password\": credentials.password,\n\n \"/private_key\": {\n content: credentials.keyPair?.privateKey,\n mode: 0o600,\n },\n\n \"/known_hosts\": {\n content: `${l4EndpointToString(endpoint)} ${credentials.hostKey}`,\n mode: 0o644,\n },\n },\n }\n })\n}\n\nexport function generatePrivateKey(): string {\n const seed = randomBytes(32)\n\n return getKeys(seed).privateKey\n}\n\nexport function privateKeyToKeyPair(privateKeyString: Input<string>): Output<ssh.KeyPair> {\n return output(privateKeyString).apply(privateKeyString => {\n const privateKeyStruct = PrivateExport.decode(privateKeyString)\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const privKey = privateKeyStruct.keys[0].privKey.privKey as Uint8Array\n\n const { fingerprint, publicKey, privateKey } = getKeys(privKey.slice(0, 32))\n\n return output({\n type: \"ed25519\" as const,\n fingerprint,\n publicKey,\n privateKey: secret(privateKey),\n })\n })\n}\n\nexport type SshKeyPairInputs = {\n sshKeyPair?: Input<ssh.KeyPair>\n}\n\nexport type SshKeyPairSecrets = {\n sshPrivateKey?: Input<string>\n}\n\nexport function getOrCreateSshKeyPair(\n inputs: SshKeyPairInputs,\n secrets: Output<SshKeyPairSecrets>,\n): Output<ssh.KeyPair> {\n if (inputs.sshKeyPair) {\n return output(inputs.sshKeyPair)\n }\n\n const privateKey = getOrCreateSecret(secrets, \"sshPrivateKey\", generatePrivateKey)\n\n return privateKey.apply(privateKeyToKeyPair)\n}\n\nexport function createServerEntity(\n fallbackHostname: string,\n endpoint: network.L3Endpoint,\n sshPort = 22,\n sshUser = \"root\",\n sshPassword?: Input<string | undefined>,\n sshPrivateKey?: Input<string>,\n): Output<common.Server> {\n const connection = output({\n host: l3EndpointToString(endpoint),\n port: sshPort,\n user: sshUser,\n password: sshPassword,\n privateKey: sshPrivateKey,\n dialErrorLimit: 3,\n })\n\n const command = new local.Command(\"check-ssh\", {\n create: `nc -zv ${l3EndpointToString(endpoint)} ${sshPort} && echo \"up\" || echo \"down\"`,\n })\n\n return command.stdout.apply(result => {\n if (result === \"down\") {\n return output({\n hostname: fallbackHostname,\n endpoints: [endpoint],\n })\n }\n\n const hostnameResult = new remote.Command(\"hostname\", {\n connection,\n create: \"hostname\",\n triggers: [Date.now()],\n })\n\n const hostKeyResult = new remote.Command(\"host-key\", {\n connection,\n create: \"cat /etc/ssh/ssh_host_ed25519_key.pub\",\n triggers: [Date.now()],\n })\n\n return output({\n endpoints: [endpoint],\n hostname: hostnameResult.stdout.apply(x => x.trim()),\n ssh: {\n endpoints: [l3ToL4Endpoint(endpoint, sshPort)],\n user: sshUser,\n hostKey: hostKeyResult.stdout.apply(x => x.trim()),\n password: sshPassword,\n keyPair: sshPrivateKey ? privateKeyToKeyPair(sshPrivateKey) : undefined,\n },\n })\n })\n}\n"],"mappings":";AACA,SAAS,iBAA6B;AACtC,SAAS,gBAAgB;AAyBlB,SAAS,mBAAmB,YAAwC;AACzE,UAAQ,WAAW,MAAM;AAAA,IACvB,KAAK;AACH,aAAO,WAAW;AAAA,IACpB,KAAK;AACH,aAAO,WAAW;AAAA,IACpB,KAAK;AACH,aAAO,WAAW;AAAA,EACtB;AACF;AASO,SAAS,mBAAmB,YAAwC;AACzE,MAAI,WAAW,SAAS,QAAQ;AAC9B,WAAO,IAAI,WAAW,OAAO,KAAK,WAAW,IAAI;AAAA,EACnD;AAEA,SAAO,GAAG,mBAAmB,UAAU,CAAC,IAAI,WAAW,IAAI;AAC7D;AAQO,SAAS,oBAAoB,aAA0C;AAC5E,MAAI,YAAY,MAAM;AACpB,WAAO,mBAAmB,WAAW;AAAA,EACvC;AAEA,SAAO,mBAAmB,WAAW;AACvC;AAEA,IAAM,kBACJ;AAUK,SAAS,iBAAiB,aAAoD;AAC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AAU,CAAC,KAAK,IAAI,CAAC;AAAA,IACvB,CAAC;AAED,WAAOL,QAAO;AAAA,MACZ,WAAW,CAAC,QAAQ;AAAA,MACpB,UAAU,eAAe,OAAO,MAAM,OAAK,EAAE,KAAK,CAAC;AAAA,MACnD,KAAK;AAAA,QACH,WAAW,CAAC,eAAe,UAAU,OAAO,CAAC;AAAA,QAC7C,MAAM;AAAA,QACN,SAAS,cAAc,OAAO,MAAM,OAAK,EAAE,KAAK,CAAC;AAAA,QACjD,UAAU;AAAA,QACV,SAAS,gBAAgB,oBAAoB,aAAa,IAAI;AAAA,MAChE;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":["ssh","args","options","ComponentResource","output","toPromise","uniqueBy","ComponentResource","output","args","records","toPromise","uniqueBy","output","randomBytes","local","remote","output","credentials","randomBytes","privateKeyString","local","remote"]}