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

Commit

Permalink
Alter list topics to utilize json output
Browse files Browse the repository at this point in the history
  • Loading branch information
wcarlsen committed Apr 27, 2022
1 parent 7d052e1 commit 2860172
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotenv
2 changes: 1 addition & 1 deletion server/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build:
docker build -t $(IMAGE_NAME) .

run:
docker run -it -p 3000:3000 --rm $(IMAGE_NAME)
docker run -it -p 3000:3000 --rm --env-file ../.env $(IMAGE_NAME)

release: build
chmod +x ../scripts/push_container_image.sh && ../scripts/push_container_image.sh $(IMAGE_NAME) $(BUILD_NUMBER)
Expand Down
25 changes: 17 additions & 8 deletions server/src/server/wrapper/connected/CCloudTopics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,33 @@ import { parse, parseTopicDescription } from "./../parser";
import { executeCli } from "./executeCli";
import { TopicAlreadyExistsException } from "../model/error";
import { GetConfig } from "../../config";
import { Deserializer, ConcatOutput } from "../utils";
import ListTopics from "../model/topics";


export class CcloudTopics implements Topics {

async getTopics(): Promise<string[]> {
let config = GetConfig();

let result = await executeCli(["kafka", "topic", "list", "--cluster", config.clusterId, "--environment", config.environmentId]);
result =
parse(result)
.filter(t => t.Name.startsWith("_confluent") === false)
.map(t => t.Name);

return result;
let result = await executeCli(["kafka", "topic", "list", "--cluster", config.clusterId, "--environment", config.environmentId, "--output", "json"]);

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

return deserializedResult
.filter(t => t.name.startsWith("_confluent") === false)
.map(t => t.name);
}

async describeTopic(name: string): Promise<Topic> {
let config = GetConfig();
let consoleLines = await executeCli(["kafka", "topic", "describe", name, "--cluster", config.clusterId, "--environment", config.environmentId]);
let consoleLines = await executeCli(["kafka", "topic", "describe", name, "--cluster", config.clusterId, "--environment", config.environmentId, "--output", "json"]);

var topic = parseTopicDescription(consoleLines);

Expand Down
9 changes: 9 additions & 0 deletions server/src/server/wrapper/model/topics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class ListTopic {
name: string
}

type ListTopics = Array<ListTopic>;

export default ListTopics;


0 comments on commit 2860172

Please sign in to comment.