Skip to content

Commit 2f23dde

Browse files
committed
si space <spc> disconnect
1 parent 6ea9c9d commit 2f23dde

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

packages/cli/src/lib/commands/space.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-console */
2+
import { PostDisconnectPayload } from "@scramjet/types/src/rest-api-manager";
23
import { CommandDefinition, isProductionEnv } from "../../types";
34
import { profileManager, sessionConfig } from "../config";
45
import { displayObject, displayStream } from "../output";
@@ -79,6 +80,32 @@ export const space: CommandDefinition = (program) => {
7980
await displayStream(await managerClient.getLogStream());
8081
});
8182

83+
spaceCmd
84+
.command("disconnect")
85+
.description("Disconnect self hosted Hubs from space")
86+
.argument("<space_name>", "The name of the Space")
87+
.option("--id <id>", "Hub Id")
88+
.option("--all", "Disconnects all self-hosted Hubs connected to Space", false)
89+
.action(async (spaceName: string, id: string, all: string) => {
90+
const mwClient = getMiddlewareClient();
91+
const managerClient = mwClient.getManagerClient(spaceName);
92+
let opts = { } as PostDisconnectPayload;
93+
94+
if (typeof id === "string") {
95+
opts = { id };
96+
}
97+
98+
if (all) {
99+
opts = { limit: 0 };
100+
}
101+
102+
if (!Object.keys(opts).length) {
103+
throw new Error("Missing --id or --all");
104+
}
105+
106+
displayObject(await managerClient.disconnectHubs(opts), profileManager.getProfileConfig().format);
107+
});
108+
82109
const accessKeyCmd = spaceCmd
83110
.command("access")
84111
.description("Manages Access Keys for active Space");
@@ -94,7 +121,7 @@ export const space: CommandDefinition = (program) => {
94121
throw new Error("No Space set");
95122
}
96123

97-
displayObject(await mwClient.createAccessKey(spaceName, { description }), "json");
124+
displayObject(await mwClient.createAccessKey(spaceName, { description }), profileManager.getProfileConfig().format);
98125
});
99126

100127
accessKeyCmd.command("list")
@@ -108,7 +135,7 @@ export const space: CommandDefinition = (program) => {
108135
throw new Error("No Space set");
109136
}
110137

111-
displayObject(await mwClient.listAccessKeys(spaceName), "json");
138+
displayObject(await mwClient.listAccessKeys(spaceName), profileManager.getProfileConfig().format);
112139
});
113140

114141
accessKeyCmd.command("revoke")
@@ -122,6 +149,6 @@ export const space: CommandDefinition = (program) => {
122149
throw new Error("No Space set");
123150
}
124151

125-
displayObject(await mwClient.revokeAccessKey(spaceName, accessKey), "json");
152+
displayObject(await mwClient.revokeAccessKey(spaceName, accessKey), profileManager.getProfileConfig().format);
126153
});
127154
};

packages/model/src/stream-handler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type ControlMessageHandlerList = {
5656
[CPMMessageCode.STH_ID]: ConfiguredMessageHandler<CPMMessageCode.STH_ID>[];
5757
[CPMMessageCode.KEY_REVOKED]: ConfiguredMessageHandler<CPMMessageCode.KEY_REVOKED>[];
5858
[CPMMessageCode.LIMIT_EXCEEDED]: ConfiguredMessageHandler<CPMMessageCode.LIMIT_EXCEEDED>[];
59+
[CPMMessageCode.ID_DROP]: ConfiguredMessageHandler<CPMMessageCode.ID_DROP>[];
5960
};
6061

6162
export class CommunicationHandler implements ICommunicationHandler {
@@ -92,6 +93,7 @@ export class CommunicationHandler implements ICommunicationHandler {
9293
[CPMMessageCode.STH_ID]: [],
9394
[CPMMessageCode.KEY_REVOKED]: [],
9495
[CPMMessageCode.LIMIT_EXCEEDED]: [],
96+
[CPMMessageCode.ID_DROP]: [],
9597
};
9698
this.monitoringHandlerHash = {
9799
[RunnerMessageCode.ACKNOWLEDGE]: [],

packages/symbols/src/cpm-message-code.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ export enum CPMMessageCode {
1414
CONFIRM_MSG = 8000,
1515

1616
KEY_REVOKED = 9001,
17-
LIMIT_EXCEEDED = 9002
17+
LIMIT_EXCEEDED = 9002,
18+
ID_DROP = 9003
1819
}

packages/types/src/message-streams.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export type EncodedMessage<
9595
export type ControlMessageCode =
9696
RunnerMessageCode.KILL | RunnerMessageCode.MONITORING_RATE | RunnerMessageCode.STOP | RunnerMessageCode.EVENT |
9797
RunnerMessageCode.PONG |
98-
CPMMessageCode.STH_ID | CPMMessageCode.KEY_REVOKED | CPMMessageCode.LIMIT_EXCEEDED |
98+
CPMMessageCode.STH_ID | CPMMessageCode.KEY_REVOKED | CPMMessageCode.LIMIT_EXCEEDED | CPMMessageCode.ID_DROP |
9999
RunnerMessageCode.INPUT_CONTENT_TYPE;
100100

101101
export type EncodedControlMessage = EncodedMessage<ControlMessageCode>;

packages/types/src/rest-api-manager/post-disconnect.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { OpResponse } from "../rest-api-multi-manager";
22

33
export type PostDisconnectPayload = {
4+
id?: string;
45
limit?: number;
56
accessKey?: string;
67
}

0 commit comments

Comments
 (0)