Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
Updated CcloudCluster class and changed parsing to utilize json
Browse files Browse the repository at this point in the history
  • Loading branch information
wcarlsen committed Apr 27, 2022
1 parent 77ecf86 commit 7d052e1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
17 changes: 12 additions & 5 deletions server/src/server/wrapper/connected/CcloudCluster.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import { parse, parseSideColumns } from "./../parser";
import {executeCli } from "./executeCli";
import { GetConfig } from "../../config";
import { Deserializer, ConcatOutput } from "../utils";
import Clusters from "../model/clusters";

export class CcloudCluster {
ccloud: CCloudCliWrapper;

async list(): Promise<any[]> {
let config = GetConfig();

let result = await executeCli(["kafka", "cluster", "list", "--environment", config.environmentId]);
parse(result);
console.log("\n::SEP::\n");
console.log(result);
let result = await executeCli(["kafka", "cluster", "list", "--environment", config.environmentId, "--output", "json"]);

let combinedResult = ConcatOutput(result);
let deserializedResult : Clusters;
try {
deserializedResult = Deserializer<Clusters>(combinedResult);
} catch (error) {
return error;
}

return result;
return deserializedResult;
}

constructor(ccloud: CCloudCliWrapper) {
Expand Down
13 changes: 13 additions & 0 deletions server/src/server/wrapper/model/clusters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class Cluster {
availability: string
id: string
name: string
provider: string
region: string
status: string
type: string
}

type Clusters = Array<Cluster>;

export default Clusters;
10 changes: 10 additions & 0 deletions server/src/server/wrapper/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function Deserializer<T>(json:string) : T {
let payload = JSON.parse(json);
return payload;
}

export function ConcatOutput(output:Array<string>) : string {
return output.join("\n");
}

export default Deserializer;

0 comments on commit 7d052e1

Please sign in to comment.