diff --git a/server/src/server/wrapper/connected/CcloudServiceAccount.ts b/server/src/server/wrapper/connected/CcloudServiceAccount.ts index ef3290e..5fd9fda 100644 --- a/server/src/server/wrapper/connected/CcloudServiceAccount.ts +++ b/server/src/server/wrapper/connected/CcloudServiceAccount.ts @@ -2,7 +2,7 @@ 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"; +import { ListServiceAccounts, ListServiceAccount } from "../model/service-account"; export class CcloudServiceAccount implements ServiceAccounts { ccloud: CCloudCliWrapper; @@ -30,14 +30,14 @@ export class CcloudServiceAccount implements ServiceAccounts { async createServiceAccount(accountName: string, description: string = ""): Promise { let cliResult; try { - cliResult = await executeCli(["service-account", "create", accountName, "--description", description]); + cliResult = await executeCli(["iam", "service-account", "create", accountName, "--description", description, "--output", "json"]); } catch (error) { if (error.name.valueOf() !== "CliException") { throw (error); } - if (error.consoleLines.some((l: string): boolean => l.includes("Service name is already in use"))) { + if (error.consoleLines.some((l: string): boolean => l.includes("is already in use"))) { let existingServicesAccounts = await this.getServiceAccounts(); let existingServicesAccount = existingServicesAccounts.find(s => s.Name === accountName); @@ -54,15 +54,23 @@ export class CcloudServiceAccount implements ServiceAccounts { throw (error); } + let combinedResult = ConcatOutput(cliResult); + let deserializedResult : ListServiceAccount; + try { + deserializedResult = Deserializer(combinedResult); + } catch (error) { + return error; + } - - let result = parseSideColumns(cliResult); - - return (result as any) as ServiceAccount; + return { + Name: deserializedResult.name, + Id: deserializedResult.id, + Description: deserializedResult.description + }; } async deleteServiceAccount(accountId: number): Promise { - await executeCli(["service-account", "delete", accountId.toString()]); + await executeCli(["iam", "service-account", "delete", accountId.toString()]); return true; } diff --git a/server/src/server/wrapper/model/service-account.ts b/server/src/server/wrapper/model/service-account.ts index c90cadd..0fc1da2 100644 --- a/server/src/server/wrapper/model/service-account.ts +++ b/server/src/server/wrapper/model/service-account.ts @@ -1,4 +1,4 @@ -export default class ListServiceAccount { +export class ListServiceAccount { id: number; name: string; description: string; // Currently isn't parsed properly (whitespace and space in general gets trimemd away)