@highstate/common 0.4.2

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.
@@ -0,0 +1,55 @@
1
+ import { common } from '@highstate/library';
2
+ import { forUnit, output } from '@highstate/pulumi';
3
+ import { remote } from '@pulumi/command';
4
+
5
+ const { args, secrets, outputs } = forUnit(common.existingServer);
6
+ const hostnameResult = new remote.Command("hostname", {
7
+ connection: output({
8
+ host: args.endpoint,
9
+ port: args.sshPort,
10
+ user: args.sshUser,
11
+ password: secrets.sshPassword,
12
+ dialErrorLimit: 3
13
+ }),
14
+ create: "hostname",
15
+ triggers: [Date.now()]
16
+ });
17
+ const hostname = hostnameResult.stdout.apply((x) => x.trim());
18
+ const port = args.sshPort ?? 22;
19
+ const user = args.sshUser ?? "root";
20
+ var index = outputs({
21
+ server: {
22
+ endpoint: args.endpoint,
23
+ hostname,
24
+ sshCredentials: {
25
+ user: args.sshUser,
26
+ port: args.sshPort,
27
+ password: secrets.sshPassword
28
+ }
29
+ },
30
+ $status: {
31
+ hostname: {
32
+ value: hostname
33
+ }
34
+ },
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
+ }
52
+ }
53
+ });
54
+
55
+ export { index as default };
@@ -0,0 +1,22 @@
1
+ import { types, remote } from '@pulumi/command';
2
+ import { Input, Output, InputOrArray, Resource } from '@highstate/pulumi';
3
+ import { common } from '@highstate/library';
4
+
5
+ declare function getServerConnection(server: Input<common.Server>): Output<types.input.remote.ConnectionArgs>;
6
+ interface CommandOptions {
7
+ id: string;
8
+ create: Input<string>;
9
+ update?: Input<string>;
10
+ delete?: Input<string>;
11
+ dependsOn?: InputOrArray<Resource>;
12
+ }
13
+ declare class Server {
14
+ readonly server: Output<common.Server>;
15
+ readonly connection: Output<types.input.remote.ConnectionArgs>;
16
+ get endpoint(): Output<string>;
17
+ get hostname(): Output<string>;
18
+ constructor(server: Input<common.Server>);
19
+ command(options: CommandOptions): remote.Command;
20
+ }
21
+
22
+ export { type CommandOptions, Server, getServerConnection };
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ import { remote } from '@pulumi/command';
2
+ import { output } from '@highstate/pulumi';
3
+ import '@highstate/library';
4
+
5
+ function getServerConnection(server) {
6
+ return output(server).apply((server2) => ({
7
+ host: server2.endpoint,
8
+ port: server2.sshCredentials?.port ?? 22,
9
+ user: server2.sshCredentials?.user ?? "root",
10
+ password: server2.sshCredentials?.password,
11
+ dialErrorLimit: 3
12
+ }));
13
+ }
14
+ class Server {
15
+ server;
16
+ connection;
17
+ get endpoint() {
18
+ return this.server.endpoint;
19
+ }
20
+ get hostname() {
21
+ return this.server.hostname;
22
+ }
23
+ constructor(server) {
24
+ this.server = output(server);
25
+ this.connection = getServerConnection(this.server);
26
+ }
27
+ command(options) {
28
+ return new remote.Command(
29
+ options.id,
30
+ {
31
+ connection: this.connection,
32
+ create: options.create,
33
+ update: options.update,
34
+ delete: options.delete
35
+ },
36
+ { dependsOn: options.dependsOn }
37
+ );
38
+ }
39
+ }
40
+
41
+ export { Server, getServerConnection };
@@ -0,0 +1,33 @@
1
+ import { ssh } from '@highstate/library';
2
+ import { forUnit, getOrCreateSecret, unsecret } from '@highstate/pulumi';
3
+ import { getKeys, PrivateExport } from 'micro-key-producer/ssh.js';
4
+ import { randomBytes } from 'micro-key-producer/utils.js';
5
+
6
+ const { secrets, outputs } = forUnit(ssh.keyPair);
7
+ const privateKey = getOrCreateSecret(secrets, "privateKey", () => {
8
+ const seed = randomBytes(32);
9
+ return getKeys(seed).privateKey;
10
+ });
11
+ function getKeysFromString(privateKey2) {
12
+ const privateKeyStruct = PrivateExport.decode(privateKey2);
13
+ const privKey = privateKeyStruct.keys[0].privKey.privKey;
14
+ return getKeys(privKey.slice(0, 32));
15
+ }
16
+ const keys = privateKey.apply(getKeysFromString);
17
+ var index = outputs({
18
+ keyPair: {
19
+ type: "ed25519",
20
+ privateKey: keys.privateKey,
21
+ publicKey: unsecret(keys.publicKey)
22
+ },
23
+ $status: {
24
+ fingerprint: {
25
+ value: unsecret(keys.fingerprint)
26
+ },
27
+ publicKey: {
28
+ value: unsecret(keys.publicKey)
29
+ }
30
+ }
31
+ });
32
+
33
+ export { index as default };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@highstate/common",
3
+ "version": "0.4.2",
4
+ "type": "module",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "module": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.js",
13
+ "types": "./dist/index.d.ts"
14
+ },
15
+ "./existing-server": "./dist/existing-server/index.js",
16
+ "./ssh/key-pair": "./dist/ssh/key-pair/index.js"
17
+ },
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "scripts": {
22
+ "build": "pkgroll --tsconfig=tsconfig.build.json"
23
+ },
24
+ "dependencies": {
25
+ "@highstate/pulumi": "^0.4.2",
26
+ "@pulumi/command": "^1.0.1",
27
+ "micro-key-producer": "^0.7.3"
28
+ },
29
+ "peerDependencies": {
30
+ "@highstate/library": "workspace:^"
31
+ },
32
+ "devDependencies": {
33
+ "pkgroll": "^2.5.1"
34
+ },
35
+ "gitHead": "e88c7c588267cf028c054f694d402902dc057919"
36
+ }