@highstate/common 0.4.4 → 0.4.6

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.
@@ -1,6 +1,9 @@
1
1
  import { common } from '@highstate/library';
2
2
  import { forUnit, output } from '@highstate/pulumi';
3
3
  import { remote } from '@pulumi/command';
4
+ import '@noble/hashes/utils';
5
+ import 'micro-key-producer/password.js';
6
+ import { c as createSshTerminal } from '../ssh-XS5DEPfW.js';
4
7
 
5
8
  const { args, secrets, outputs } = forUnit(common.existingServer);
6
9
  const hostnameResult = new remote.Command("hostname", {
@@ -15,40 +18,24 @@ const hostnameResult = new remote.Command("hostname", {
15
18
  triggers: [Date.now()]
16
19
  });
17
20
  const hostname = hostnameResult.stdout.apply((x) => x.trim());
18
- const port = args.sshPort ?? 22;
19
- const user = args.sshUser ?? "root";
21
+ const sshCredentials = output({
22
+ user: args.sshUser,
23
+ port: args.sshPort,
24
+ password: secrets.sshPassword
25
+ });
20
26
  var index = outputs({
21
27
  server: {
22
28
  endpoint: args.endpoint,
23
29
  hostname,
24
- sshCredentials: {
25
- user: args.sshUser,
26
- port: args.sshPort,
27
- password: secrets.sshPassword
28
- }
30
+ sshCredentials
29
31
  },
30
32
  $status: {
31
33
  hostname: {
32
34
  value: hostname
33
35
  }
34
36
  },
35
- $terminal: {
36
- image: "ghcr.io/exeteres/highstate/terminal-ssh",
37
- command: [
38
- "sshpass",
39
- "-f",
40
- "/password",
41
- "ssh",
42
- "-tt",
43
- "-o",
44
- "StrictHostKeyChecking=no",
45
- "-p",
46
- port.toString(),
47
- `${user}@${args.endpoint}`
48
- ],
49
- files: {
50
- "/password": secrets.sshPassword?.apply((x) => x ?? "") ?? ""
51
- }
37
+ $terminals: {
38
+ ssh: sshCredentials.apply((credentials) => createSshTerminal(credentials, args.endpoint))
52
39
  }
53
40
  });
54
41
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { types, remote } from '@pulumi/command';
2
- import { Input, Output, InputOrArray, Resource } from '@highstate/pulumi';
3
- import { common } from '@highstate/library';
2
+ import { Input, Output, InputOrArray, Resource, ComponentResource, ResourceOptions, Unwrap, InstanceTerminal } from '@highstate/pulumi';
3
+ import { common, ssh } from '@highstate/library';
4
4
 
5
5
  declare function getServerConnection(server: Input<common.Server>): Output<types.input.remote.ConnectionArgs>;
6
6
  interface CommandOptions {
@@ -19,4 +19,44 @@ declare class Server {
19
19
  command(options: CommandOptions): remote.Command;
20
20
  }
21
21
 
22
- export { type CommandOptions, Server, getServerConnection };
22
+ type DnsRecordArgs = {
23
+ /**
24
+ * The DNS provider to use.
25
+ */
26
+ provider: Input<common.DnsProvider>;
27
+ /**
28
+ * The name of the DNS record.
29
+ * If not provided, the name of the resource will be used.
30
+ */
31
+ name?: Input<string>;
32
+ /**
33
+ * The type of the DNS record.
34
+ */
35
+ type: Input<string>;
36
+ /**
37
+ * The value of the DNS record.
38
+ */
39
+ value: Input<string>;
40
+ /**
41
+ * Whether the DNS record is proxied (e.g. to provide DDoS protection).
42
+ *
43
+ * Available only for public IPs and some DNS providers like Cloudflare.
44
+ * If not supported, the DNS provider will ignore this value.
45
+ */
46
+ proxied?: Input<boolean>;
47
+ };
48
+ declare abstract class DnsRecord extends ComponentResource {
49
+ /**
50
+ * The underlying dns record resource.
51
+ */
52
+ readonly dnsRecord: Output<Resource>;
53
+ constructor(name: string, args: DnsRecordArgs, opts?: ResourceOptions);
54
+ protected abstract create(name: string, args: Unwrap<DnsRecordArgs>, opts?: ResourceOptions): Input<Resource>;
55
+ static create(name: string, args: DnsRecordArgs, opts?: ResourceOptions): Output<DnsRecord>;
56
+ }
57
+
58
+ declare function generatePassword(): string;
59
+
60
+ declare function createSshTerminal(credentials: ssh.Credentials, fallbackEndpoint: string): InstanceTerminal;
61
+
62
+ export { type CommandOptions, DnsRecord, type DnsRecordArgs, Server, createSshTerminal, generatePassword, getServerConnection };
package/dist/index.js CHANGED
@@ -1,6 +1,9 @@
1
1
  import { remote } from '@pulumi/command';
2
- import { output } from '@highstate/pulumi';
2
+ import { output, ComponentResource } from '@highstate/pulumi';
3
3
  import '@highstate/library';
4
+ import { randomBytes } from '@noble/hashes/utils';
5
+ import { secureMask } from 'micro-key-producer/password.js';
6
+ export { c as createSshTerminal } from './ssh-XS5DEPfW.js';
4
7
 
5
8
  function getServerConnection(server) {
6
9
  return output(server).apply((server2) => ({
@@ -8,6 +11,7 @@ function getServerConnection(server) {
8
11
  port: server2.sshCredentials?.port ?? 22,
9
12
  user: server2.sshCredentials?.user ?? "root",
10
13
  password: server2.sshCredentials?.password,
14
+ privateKey: server2.sshCredentials?.keyPair?.privateKey,
11
15
  dialErrorLimit: 3
12
16
  }));
13
17
  }
@@ -38,4 +42,48 @@ class Server {
38
42
  }
39
43
  }
40
44
 
41
- export { Server, getServerConnection };
45
+ function u$1(o, n, a) {
46
+ let t = (r) => o(r, ...n);
47
+ return a === void 0 ? t : Object.assign(t, { lazy: a, lazyArgs: n });
48
+ }
49
+
50
+ function u(r, n, o) {
51
+ let a = r.length - n.length;
52
+ if (a === 0) return r(...n);
53
+ if (a === 1) return u$1(r, n, o);
54
+ throw new Error("Wrong number of arguments");
55
+ }
56
+
57
+ function n(...t) {
58
+ return u(e, t);
59
+ }
60
+ var e = (t) => `${t[0]?.toUpperCase() ?? ""}${t.slice(1)}`;
61
+
62
+ class DnsRecord extends ComponentResource {
63
+ /**
64
+ * The underlying dns record resource.
65
+ */
66
+ dnsRecord;
67
+ constructor(name, args, opts) {
68
+ super("highstate:common:DnsRecord", name, args, opts);
69
+ this.dnsRecord = output(args).apply((args2) => {
70
+ return output(this.create(name, args2, { ...opts, parent: this }));
71
+ });
72
+ this.registerOutputs({ dnsRecord: this.dnsRecord });
73
+ }
74
+ static create(name, args, opts) {
75
+ return output(args).apply(async (args2) => {
76
+ const providerType = args2.provider.type;
77
+ const implName = `${n(providerType)}DnsRecord`;
78
+ const implModule = await import(`@highstate/${providerType}`);
79
+ const implClass = implModule[implName];
80
+ return new implClass(name, args2, opts);
81
+ });
82
+ }
83
+ }
84
+
85
+ function generatePassword() {
86
+ return secureMask.apply(randomBytes(32)).password;
87
+ }
88
+
89
+ export { DnsRecord, Server, generatePassword, getServerConnection };
@@ -0,0 +1,28 @@
1
+ function createSshTerminal(credentials, fallbackEndpoint) {
2
+ const command = ["ssh", "-tt", "-o", "StrictHostKeyChecking=no"];
3
+ if (credentials.port) {
4
+ command.push("-p", credentials.port.toString());
5
+ }
6
+ if (credentials.keyPair) {
7
+ command.push("-i", "/private-key");
8
+ }
9
+ const endpoint = credentials.endpoint ?? fallbackEndpoint;
10
+ const user = credentials.user ?? "root";
11
+ command.push(`${user}@${endpoint}`);
12
+ if (credentials.password) {
13
+ command.unshift("sshpass", "-f", "/password");
14
+ }
15
+ return {
16
+ name: "ssh",
17
+ title: "SSH",
18
+ description: "Connect to the server via SSH.",
19
+ image: "ghcr.io/exeteres/highstate/terminal-ssh",
20
+ command,
21
+ files: {
22
+ "/password": credentials.password,
23
+ "/private-key": credentials.keyPair?.privateKey
24
+ }
25
+ };
26
+ }
27
+
28
+ export { createSshTerminal as c };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@highstate/common",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -22,15 +22,16 @@
22
22
  "build": "pkgroll --tsconfig=tsconfig.build.json"
23
23
  },
24
24
  "dependencies": {
25
- "@highstate/pulumi": "^0.4.4",
26
- "@pulumi/command": "^1.0.1",
25
+ "@highstate/pulumi": "^0.4.6",
26
+ "@noble/hashes": "^1.7.1",
27
+ "@pulumi/command": "^1.0.2",
27
28
  "micro-key-producer": "^0.7.3"
28
29
  },
29
30
  "peerDependencies": {
30
- "@highstate/library": "workspace:^"
31
+ "@highstate/library": "workspace:^0.4.4"
31
32
  },
32
33
  "devDependencies": {
33
34
  "pkgroll": "^2.5.1"
34
35
  },
35
- "gitHead": "58a1b969cca5dad233f885f2e67185a0384ea1aa"
36
+ "gitHead": "dbb1d8125884cfe3a9d95df2e0710333c01c7edf"
36
37
  }