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

Commit

Permalink
Alter list service-accounts 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 2ed45ed commit 681ec31
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
21 changes: 18 additions & 3 deletions server/src/server/wrapper/connected/CcloudServiceAccount.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
import { parse, parseSideColumns } from "./../parser";
import { executeCli } from "./executeCli";
import { CliException, ServiceAccountAlreadyExistsException } from "./../model/error";
import { Deserializer, ConcatOutput } from "../utils";
import { ListServiceAccounts } from "../model/service-account";

export class CcloudServiceAccount implements ServiceAccounts {
ccloud: CCloudCliWrapper;

async getServiceAccounts(): Promise<ServiceAccount[]> {
let result = await executeCli(["service-account", "list"]);
result = parse(result);
let result = await executeCli(["iam", "service-account", "list", "--output", "json"]);
let combinedResult = ConcatOutput(result);
let deserializedResult : ListServiceAccounts;
try {
deserializedResult = Deserializer<ListServiceAccounts>(combinedResult);
} catch (error) {
return error;
}

return (result as any) as ServiceAccount[];
return deserializedResult.map(t => {
let obj = {
Name: t.name,
Id: t.id,
Description: t.description
};
return obj;
})
}

async createServiceAccount(accountName: string, description: string = ""): Promise<ServiceAccount> {
Expand Down
8 changes: 5 additions & 3 deletions server/src/server/wrapper/model/service-account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export default class ServiceAccount {
Id: number;
Name: string;
Description: string; // Currently isn't parsed properly (whitespace and space in general gets trimemd away)
id: number;
name: string;
description: string; // Currently isn't parsed properly (whitespace and space in general gets trimemd away)
}

export type ListServiceAccounts = Array<ServiceAccount>;

0 comments on commit 681ec31

Please sign in to comment.