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

Commit

Permalink
Alter acls to utilize json output
Browse files Browse the repository at this point in the history
  • Loading branch information
wcarlsen committed Apr 28, 2022
1 parent f1eebcc commit 4502980
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
32 changes: 24 additions & 8 deletions server/src/server/wrapper/connected/CcloudAccessControlLists.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
import { parse } from "./../parser";
import { executeCli } from "./executeCli";
import { GetConfig } from "../../config";
import { Deserializer, ConcatOutput } from "../utils";
import { ListAcls } from "../model/acls";

export class CcloudAccessControlLists implements AccessControlLists {
async getAccessControlLists(): Promise<AccessControlList[]> {
let config = GetConfig();
let result = await executeCli(["kafka", "acl", "list", "--cluster", config.clusterId, "--environment", config.environmentId]);
let resultObjects = parse(result) as AccessControlList[];
let result = await executeCli(["kafka", "acl", "list", "--cluster", config.clusterId, "--environment", config.environmentId, "--output", "json"]);

resultObjects.forEach(elem => {
elem.UserId = elem.UserId.split(':')[1];
});

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

return deserializedResult.map(t => {
let obj = {
UserId: "", // removed property by Confluent
ServiceAccountId: t.principal.split(":")[1],
Permission: t.permission,
Operation: t.operation,
Resource: t.resource_type,
Name: t.resource_name,
Type: t.pattern_type
};
return obj;
})
}

async createAccessControlList(
serviceAccountId: number,
Expand Down
10 changes: 10 additions & 0 deletions server/src/server/wrapper/model/acls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export class ListAcl {
operation: string
pattern_type: string
permission: string
principal: string
resource_name: string
resource_type: string
}

export type ListAcls = Array<ListAcl>

0 comments on commit 4502980

Please sign in to comment.