Skip to content

Commit

Permalink
si space <spc> disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
patuwwy committed Mar 20, 2023
1 parent 7b627fa commit 1fdea2a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
33 changes: 30 additions & 3 deletions packages/cli/src/lib/commands/space.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
import { PostDisconnectPayload } from "@scramjet/types/src/rest-api-manager";
import { CommandDefinition, isProductionEnv } from "../../types";
import { profileManager, sessionConfig } from "../config";
import { displayObject, displayStream } from "../output";
Expand Down Expand Up @@ -79,6 +80,32 @@ export const space: CommandDefinition = (program) => {
await displayStream(await managerClient.getLogStream());
});

spaceCmd
.command("disconnect")
.description("Disconnect self hosted Hubs from space")
.argument("<space_name>", "The name of the Space")
.option("--id <id>", "Hub Id")
.option("--all", "Disconnects all self-hosted Hubs connected to Space", false)
.action(async (spaceName: string, id: string, all: string) => {
const mwClient = getMiddlewareClient();
const managerClient = mwClient.getManagerClient(spaceName);
let opts = { } as PostDisconnectPayload;

if (typeof id === "string") {
opts = { id };
}

if (all) {
opts = { limit: 0 };
}

if (!Object.keys(opts).length) {
throw new Error("Missing --id or --all");
}

displayObject(await managerClient.disconnectHubs(opts), profileManager.getProfileConfig().format);
});

const accessKeyCmd = spaceCmd
.command("access")
.description("Manages Access Keys for active Space");
Expand All @@ -94,7 +121,7 @@ export const space: CommandDefinition = (program) => {
throw new Error("No Space set");
}

displayObject(await mwClient.createAccessKey(spaceName, { description }), "json");
displayObject(await mwClient.createAccessKey(spaceName, { description }), profileManager.getProfileConfig().format);
});

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

displayObject(await mwClient.listAccessKeys(spaceName), "json");
displayObject(await mwClient.listAccessKeys(spaceName), profileManager.getProfileConfig().format);
});

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

displayObject(await mwClient.revokeAccessKey(spaceName, accessKey), "json");
displayObject(await mwClient.revokeAccessKey(spaceName, accessKey), profileManager.getProfileConfig().format);
});
};
2 changes: 2 additions & 0 deletions packages/model/src/stream-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type ControlMessageHandlerList = {
[CPMMessageCode.STH_ID]: ConfiguredMessageHandler<CPMMessageCode.STH_ID>[];
[CPMMessageCode.KEY_REVOKED]: ConfiguredMessageHandler<CPMMessageCode.KEY_REVOKED>[];
[CPMMessageCode.LIMIT_EXCEEDED]: ConfiguredMessageHandler<CPMMessageCode.LIMIT_EXCEEDED>[];
[CPMMessageCode.ID_DROP]: ConfiguredMessageHandler<CPMMessageCode.ID_DROP>[];
};

export class CommunicationHandler implements ICommunicationHandler {
Expand Down Expand Up @@ -92,6 +93,7 @@ export class CommunicationHandler implements ICommunicationHandler {
[CPMMessageCode.STH_ID]: [],
[CPMMessageCode.KEY_REVOKED]: [],
[CPMMessageCode.LIMIT_EXCEEDED]: [],
[CPMMessageCode.ID_DROP]: [],
};
this.monitoringHandlerHash = {
[RunnerMessageCode.ACKNOWLEDGE]: [],
Expand Down
3 changes: 2 additions & 1 deletion packages/symbols/src/cpm-message-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export enum CPMMessageCode {
CONFIRM_MSG = 8000,

KEY_REVOKED = 9001,
LIMIT_EXCEEDED = 9002
LIMIT_EXCEEDED = 9002,
ID_DROP = 9003
}
2 changes: 1 addition & 1 deletion packages/types/src/message-streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export type EncodedMessage<
export type ControlMessageCode =
RunnerMessageCode.KILL | RunnerMessageCode.MONITORING_RATE | RunnerMessageCode.STOP | RunnerMessageCode.EVENT |
RunnerMessageCode.PONG |
CPMMessageCode.STH_ID | CPMMessageCode.KEY_REVOKED | CPMMessageCode.LIMIT_EXCEEDED |
CPMMessageCode.STH_ID | CPMMessageCode.KEY_REVOKED | CPMMessageCode.LIMIT_EXCEEDED | CPMMessageCode.ID_DROP |
RunnerMessageCode.INPUT_CONTENT_TYPE;

export type EncodedControlMessage = EncodedMessage<ControlMessageCode>;
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/rest-api-manager/post-disconnect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { OpResponse } from "../rest-api-multi-manager";

export type PostDisconnectPayload = {
id?: string;
limit?: number;
accessKey?: string;
}
Expand Down

0 comments on commit 1fdea2a

Please sign in to comment.