From 5f955d6bd7111a22a98ee834dde6a24250418a7c Mon Sep 17 00:00:00 2001 From: Willi Carlsen Date: Wed, 27 Apr 2022 13:08:30 +0200 Subject: [PATCH 01/13] Install confluent cli tool instead of the soon to be EOL ccloud cli --- server/Dockerfile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/server/Dockerfile b/server/Dockerfile index 3e50d3e..13e61a1 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -22,14 +22,13 @@ RUN apk add --update \ curl expect \ && rm -rf /var/cache/apk/* -# Install ccloud cli tool -RUN curl -L https://s3-us-west-2.amazonaws.com/confluent.cloud/ccloud-cli/install.sh | sh -s -- -b /ccloud/bin +# Install confluent cli tool +RUN apk --no-cache add ca-certificates bash curl -ENV TIKA_CCLOUD_BIN_PATH="/ccloud/bin/ccloud" -ENV PATH "$PATH:/ccloud/bin" - -RUN ccloud version +ENV CONFLUENT_CLI_VERSION="v2.12.0" +RUN curl -sL --http1.1 https://cnfl.io/cli | sh -s -- -b /usr/local/bin $CONFLUENT_CLI_VERSION +RUN confluent version # Copy app & supporting scripts COPY --from=Builder /app/dist/main.js /app/main.js From 77ecf86bd6b4c4656c5f3d54fe93dbbc8b9fca10 Mon Sep 17 00:00:00 2001 From: Willi Carlsen Date: Wed, 27 Apr 2022 13:13:57 +0200 Subject: [PATCH 02/13] Changed entrypoint login scripts and updated cli executable to confluent --- server/login.sh | 2 +- server/src/server/wrapper/connected/executeCli.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/login.sh b/server/login.sh index 3cabf89..e2c33dd 100755 --- a/server/login.sh +++ b/server/login.sh @@ -1,5 +1,5 @@ #!/usr/bin/expect -spawn ccloud login +spawn confluent login expect "Email: " diff --git a/server/src/server/wrapper/connected/executeCli.ts b/server/src/server/wrapper/connected/executeCli.ts index ac035bc..4cdfbc7 100644 --- a/server/src/server/wrapper/connected/executeCli.ts +++ b/server/src/server/wrapper/connected/executeCli.ts @@ -3,7 +3,7 @@ import * as readline from "readline"; import { CcloudSessionExpiredException, CliException } from "./../model/error"; export function executeCli(args: string[]): Promise { - const cli = process.env.TIKA_CCLOUD_BIN_PATH ?? "ccloud"; + const cli = process.env.TIKA_CCLOUD_BIN_PATH ?? "confluent"; return new Promise((resolve, reject) => { const lines: Array = []; @@ -21,7 +21,7 @@ export function executeCli(args: string[]): Promise { return resolve(lines); } - if (errLines.some((l: string): boolean => l.includes("You must log in to run that command."))) { + if (errLines.some((l: string): boolean => l.includes("You must be logged in to run this command"))) { return reject(new CcloudSessionExpiredException()); } From 7d052e1f88e0184e36a20df968a948475d6dc463 Mon Sep 17 00:00:00 2001 From: Willi Carlsen Date: Wed, 27 Apr 2022 13:45:02 +0200 Subject: [PATCH 03/13] Updated CcloudCluster class and changed parsing to utilize json --- .../server/wrapper/connected/CcloudCluster.ts | 17 ++++++++++++----- server/src/server/wrapper/model/clusters.ts | 13 +++++++++++++ server/src/server/wrapper/utils.ts | 10 ++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 server/src/server/wrapper/model/clusters.ts create mode 100644 server/src/server/wrapper/utils.ts diff --git a/server/src/server/wrapper/connected/CcloudCluster.ts b/server/src/server/wrapper/connected/CcloudCluster.ts index 316aabe..d17a0ed 100644 --- a/server/src/server/wrapper/connected/CcloudCluster.ts +++ b/server/src/server/wrapper/connected/CcloudCluster.ts @@ -1,6 +1,8 @@ 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; @@ -8,12 +10,17 @@ export class CcloudCluster { async list(): Promise { 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(combinedResult); + } catch (error) { + return error; + } - return result; + return deserializedResult; } constructor(ccloud: CCloudCliWrapper) { diff --git a/server/src/server/wrapper/model/clusters.ts b/server/src/server/wrapper/model/clusters.ts new file mode 100644 index 0000000..955b823 --- /dev/null +++ b/server/src/server/wrapper/model/clusters.ts @@ -0,0 +1,13 @@ +export class Cluster { + availability: string + id: string + name: string + provider: string + region: string + status: string + type: string +} + +type Clusters = Array; + +export default Clusters; \ No newline at end of file diff --git a/server/src/server/wrapper/utils.ts b/server/src/server/wrapper/utils.ts new file mode 100644 index 0000000..44968ab --- /dev/null +++ b/server/src/server/wrapper/utils.ts @@ -0,0 +1,10 @@ +export function Deserializer(json:string) : T { + let payload = JSON.parse(json); + return payload; +} + +export function ConcatOutput(output:Array) : string { + return output.join("\n"); +} + +export default Deserializer; \ No newline at end of file From 2860172cf15525b4a38d75ebc4c25a998de774c5 Mon Sep 17 00:00:00 2001 From: Willi Carlsen Date: Wed, 27 Apr 2022 14:12:22 +0200 Subject: [PATCH 04/13] Alter list topics to utilize json output --- .envrc | 1 + server/makefile | 2 +- .../server/wrapper/connected/CCloudTopics.ts | 25 +++++++++++++------ server/src/server/wrapper/model/topics.ts | 9 +++++++ 4 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 .envrc create mode 100644 server/src/server/wrapper/model/topics.ts diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..40448e6 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +dotenv \ No newline at end of file diff --git a/server/makefile b/server/makefile index 387b9c6..f988745 100644 --- a/server/makefile +++ b/server/makefile @@ -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) diff --git a/server/src/server/wrapper/connected/CCloudTopics.ts b/server/src/server/wrapper/connected/CCloudTopics.ts index e5c2c35..d874c4d 100644 --- a/server/src/server/wrapper/connected/CCloudTopics.ts +++ b/server/src/server/wrapper/connected/CCloudTopics.ts @@ -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 { 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(combinedResult); + } catch (error) { + return error; + } + + return deserializedResult + .filter(t => t.name.startsWith("_confluent") === false) + .map(t => t.name); } async describeTopic(name: string): Promise { 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); diff --git a/server/src/server/wrapper/model/topics.ts b/server/src/server/wrapper/model/topics.ts new file mode 100644 index 0000000..d6c5235 --- /dev/null +++ b/server/src/server/wrapper/model/topics.ts @@ -0,0 +1,9 @@ +export class ListTopic { + name: string +} + +type ListTopics = Array; + +export default ListTopics; + + From 2ed45ed3e9577dee7a1fe8bdba3055df1bb13f28 Mon Sep 17 00:00:00 2001 From: Willi Carlsen Date: Wed, 27 Apr 2022 14:36:21 +0200 Subject: [PATCH 05/13] Alter describe topics to utilize json output --- .../server/wrapper/connected/CCloudTopics.ts | 18 +++++++++++++++--- server/src/server/wrapper/model/topics.ts | 9 +++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/server/src/server/wrapper/connected/CCloudTopics.ts b/server/src/server/wrapper/connected/CCloudTopics.ts index d874c4d..fa7a13b 100644 --- a/server/src/server/wrapper/connected/CCloudTopics.ts +++ b/server/src/server/wrapper/connected/CCloudTopics.ts @@ -3,7 +3,7 @@ import { executeCli } from "./executeCli"; import { TopicAlreadyExistsException } from "../model/error"; import { GetConfig } from "../../config"; import { Deserializer, ConcatOutput } from "../utils"; -import ListTopics from "../model/topics"; +import { ListTopics, DescribeTopic } from "../model/topics"; export class CcloudTopics implements Topics { @@ -28,9 +28,21 @@ export class CcloudTopics implements Topics { async describeTopic(name: string): Promise { let config = GetConfig(); - let consoleLines = await executeCli(["kafka", "topic", "describe", name, "--cluster", config.clusterId, "--environment", config.environmentId, "--output", "json"]); + let result = await executeCli(["kafka", "topic", "describe", name, "--cluster", config.clusterId, "--environment", config.environmentId, "--output", "json"]); - var topic = parseTopicDescription(consoleLines); + let combinedResult = ConcatOutput(result); + let deserializedResult : DescribeTopic; + try { + deserializedResult = Deserializer(combinedResult); + } catch (error) { + return error; + } + + let topic = { + Name: deserializedResult.topic_name, + PartitionCount: deserializedResult.config["num.partitions"], // might be an issue that partitionCount is present twice + Configurations: deserializedResult.config // might be an issue that partitionCount is present twice + }; return topic; } diff --git a/server/src/server/wrapper/model/topics.ts b/server/src/server/wrapper/model/topics.ts index d6c5235..09cd930 100644 --- a/server/src/server/wrapper/model/topics.ts +++ b/server/src/server/wrapper/model/topics.ts @@ -2,8 +2,9 @@ export class ListTopic { name: string } -type ListTopics = Array; - -export default ListTopics; - +export type ListTopics = Array; +export class DescribeTopic { + topic_name: string + config: {[key: string]: any} +} \ No newline at end of file From 681ec317647778675ef07ba009a4c72b3671b663 Mon Sep 17 00:00:00 2001 From: Willi Carlsen Date: Wed, 27 Apr 2022 15:19:46 +0200 Subject: [PATCH 06/13] Alter list service-accounts to utilize json output --- .../wrapper/connected/CcloudServiceAccount.ts | 21 ++++++++++++++++--- .../server/wrapper/model/service-account.ts | 8 ++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/server/src/server/wrapper/connected/CcloudServiceAccount.ts b/server/src/server/wrapper/connected/CcloudServiceAccount.ts index a95e1f2..ef3290e 100644 --- a/server/src/server/wrapper/connected/CcloudServiceAccount.ts +++ b/server/src/server/wrapper/connected/CcloudServiceAccount.ts @@ -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 { - 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(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 { diff --git a/server/src/server/wrapper/model/service-account.ts b/server/src/server/wrapper/model/service-account.ts index 847f6f9..161982a 100644 --- a/server/src/server/wrapper/model/service-account.ts +++ b/server/src/server/wrapper/model/service-account.ts @@ -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; \ No newline at end of file From 964554c7227a5522f9acb7935bb0066d4e414499 Mon Sep 17 00:00:00 2001 From: Willi Carlsen Date: Wed, 27 Apr 2022 15:20:54 +0200 Subject: [PATCH 07/13] use list service-account --- server/src/server/wrapper/model/service-account.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/server/wrapper/model/service-account.ts b/server/src/server/wrapper/model/service-account.ts index 161982a..c90cadd 100644 --- a/server/src/server/wrapper/model/service-account.ts +++ b/server/src/server/wrapper/model/service-account.ts @@ -1,7 +1,7 @@ -export default class ServiceAccount { +export default class ListServiceAccount { id: number; name: string; description: string; // Currently isn't parsed properly (whitespace and space in general gets trimemd away) } -export type ListServiceAccounts = Array; \ No newline at end of file +export type ListServiceAccounts = Array; \ No newline at end of file From b9fe8e4bfdcb69bbdaef13cd6c2c9d55f325cefa Mon Sep 17 00:00:00 2001 From: Willi Carlsen Date: Thu, 28 Apr 2022 10:31:11 +0200 Subject: [PATCH 08/13] Alter create service-accounts to utilize json output --- .../wrapper/connected/CcloudServiceAccount.ts | 24 ++++++++++++------- .../server/wrapper/model/service-account.ts | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) 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) From f1eebcc42667b36ca02a930fc735682fa7b10e88 Mon Sep 17 00:00:00 2001 From: Willi Carlsen Date: Thu, 28 Apr 2022 11:08:32 +0200 Subject: [PATCH 09/13] Alter api-keys to utilize json output --- server/src/server/api/api-keys.ts | 2 +- .../server/wrapper/connected/CcloudApiKeys.ts | 47 ++++++++++++++----- server/src/server/wrapper/definitions.d.ts | 2 +- server/src/server/wrapper/model/api-keys.ts | 16 +++++++ .../server/wrapper/model/service-account.ts | 6 +-- .../notConnected/NotConnectedApiKeys.ts | 2 +- 6 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 server/src/server/wrapper/model/api-keys.ts diff --git a/server/src/server/api/api-keys.ts b/server/src/server/api/api-keys.ts index ced0de9..fb82be7 100644 --- a/server/src/server/api/api-keys.ts +++ b/server/src/server/api/api-keys.ts @@ -7,7 +7,7 @@ export class ApiKeysInterface { try { let apiKey = await apiKeys.createApiKey( - parseInt(req.body.serviceAccountId), + req.body.serviceAccountId, req.body.description ); res.json(apiKey); diff --git a/server/src/server/wrapper/connected/CcloudApiKeys.ts b/server/src/server/wrapper/connected/CcloudApiKeys.ts index e9916a8..28ae9bb 100644 --- a/server/src/server/wrapper/connected/CcloudApiKeys.ts +++ b/server/src/server/wrapper/connected/CcloudApiKeys.ts @@ -1,11 +1,13 @@ import { parse, parseSideColumns } from "./../parser"; import {executeCli } from "./executeCli"; import { GetConfig } from "../../config"; +import { Deserializer, ConcatOutput } from "../utils"; +import { CreateApiKey, ListApiKeys } from "../model/api-keys"; export class CcloudApiKeys implements ApiKeys { ccloud: CCloudCliWrapper; - async createApiKey(serviceAccountId: number, description: string): Promise { + async createApiKey(serviceAccountId: string, description: string): Promise { let config = GetConfig(); let cliOutput = await executeCli([ @@ -13,28 +15,51 @@ export class CcloudApiKeys implements ApiKeys { "create", "--resource", config.clusterId, "--environment", config.environmentId, - "--service-account", serviceAccountId + "", - "--description", description] + "--service-account", serviceAccountId, + "--description", description, "--output", "json"] ); let cliObjects: any = parseSideColumns(cliOutput); let apiKeySet: ApiKeySet = { Key: cliObjects.APIKey, Secret: cliObjects.Secret } + + let combinedResult = ConcatOutput(cliOutput); + let deserializedResult : CreateApiKey; + try { + deserializedResult = Deserializer(combinedResult); + } catch (error) { + return error; + } - return apiKeySet; + return { + Key: deserializedResult.key, + Secret: deserializedResult.secret + }; } async deleteApiKey(key: string): Promise { await executeCli(["api-key", "delete", key]); } + async getApiKeys(): Promise { - let cliOutput = await executeCli(["api-key", "list"]); - let cliObjects = parse(cliOutput); + let cliOutput = await executeCli(["api-key", "list", "--output", "json"]); - let apiKeys = cliObjects.map(function (obj) { - return { Key: obj.Key, Description: obj.Description, Owner: obj.Owner, Resource: obj.ResourceID } as ApiKey - }); - - return apiKeys; + let combinedResult = ConcatOutput(cliOutput); + let deserializedResult : ListApiKeys; + try { + deserializedResult = Deserializer(combinedResult); + } catch (error) { + return error; + } + + return deserializedResult.map(t => { + let obj = { + Key: t.key, + Description: t.description, + Owner: t.owner_resource_id, + Resource: t.resource_id + }; + return obj; + }) } constructor(ccloud: CCloudCliWrapper) { diff --git a/server/src/server/wrapper/definitions.d.ts b/server/src/server/wrapper/definitions.d.ts index f69e8f4..b2661d7 100644 --- a/server/src/server/wrapper/definitions.d.ts +++ b/server/src/server/wrapper/definitions.d.ts @@ -48,7 +48,7 @@ interface ServiceAccounts { interface ApiKeys { createApiKey( - serviceAccountId: number, + serviceAccountId: string, description: string ): Promise; diff --git a/server/src/server/wrapper/model/api-keys.ts b/server/src/server/wrapper/model/api-keys.ts new file mode 100644 index 0000000..794fc02 --- /dev/null +++ b/server/src/server/wrapper/model/api-keys.ts @@ -0,0 +1,16 @@ +export class CreateApiKey { + key: string + secret: string +} + +export class ListApiKey{ + created: string + description: string + key: string + owner_email: string + owner_resource_id: string + resource_id: string + resource_type: string +} + +export type ListApiKeys = Array \ No newline at end of file diff --git a/server/src/server/wrapper/model/service-account.ts b/server/src/server/wrapper/model/service-account.ts index 0fc1da2..cbab58d 100644 --- a/server/src/server/wrapper/model/service-account.ts +++ b/server/src/server/wrapper/model/service-account.ts @@ -1,7 +1,7 @@ export class ListServiceAccount { - 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; \ No newline at end of file diff --git a/server/src/server/wrapper/notConnected/NotConnectedApiKeys.ts b/server/src/server/wrapper/notConnected/NotConnectedApiKeys.ts index bc3dda6..aec323d 100644 --- a/server/src/server/wrapper/notConnected/NotConnectedApiKeys.ts +++ b/server/src/server/wrapper/notConnected/NotConnectedApiKeys.ts @@ -15,7 +15,7 @@ export class NotConnectedApiKeys implements ApiKeys { constructor() { this.apiKeys = []; } - async createApiKey(serviceAccountId: number, description: string): Promise { + async createApiKey(serviceAccountId: string, description: string): Promise { let key = NotConnectedApiKeys.createRandomString(16, true); let apiKey: ApiKey = { From 45029806ca01361d1c22854c2a0c08132b73f4ad Mon Sep 17 00:00:00 2001 From: Willi Carlsen Date: Thu, 28 Apr 2022 14:51:25 +0200 Subject: [PATCH 10/13] Alter acls to utilize json output --- .../connected/CcloudAccessControlLists.ts | 32 ++++++++++++++----- server/src/server/wrapper/model/acls.ts | 10 ++++++ 2 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 server/src/server/wrapper/model/acls.ts diff --git a/server/src/server/wrapper/connected/CcloudAccessControlLists.ts b/server/src/server/wrapper/connected/CcloudAccessControlLists.ts index 8610108..72efddb 100644 --- a/server/src/server/wrapper/connected/CcloudAccessControlLists.ts +++ b/server/src/server/wrapper/connected/CcloudAccessControlLists.ts @@ -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 { 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(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, diff --git a/server/src/server/wrapper/model/acls.ts b/server/src/server/wrapper/model/acls.ts new file mode 100644 index 0000000..c629463 --- /dev/null +++ b/server/src/server/wrapper/model/acls.ts @@ -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 From c85b687518cdb1497901d94a9038baeb2b2334cf Mon Sep 17 00:00:00 2001 From: Willi Carlsen Date: Fri, 29 Apr 2022 11:30:51 +0200 Subject: [PATCH 11/13] Convert ACL UserId from long to string, to make it clear that it is not in use --- .../src/Tika.RestClient/Features/Acls/Models/Acl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/dotnet-core-rest/src/Tika.RestClient/Features/Acls/Models/Acl.cs b/clients/dotnet-core-rest/src/Tika.RestClient/Features/Acls/Models/Acl.cs index a286372..e0db727 100644 --- a/clients/dotnet-core-rest/src/Tika.RestClient/Features/Acls/Models/Acl.cs +++ b/clients/dotnet-core-rest/src/Tika.RestClient/Features/Acls/Models/Acl.cs @@ -2,7 +2,7 @@ namespace Tika.RestClient.Features.Acls.Models { public class Acl { - public long UserId { get; set; } + public string UserId { get; set; } public string ServiceAccountId { get; set; } public string Permission { get; set; } public string Resource { get; set; } From ba26e3899841736d2a8ed86d811d6923c509592e Mon Sep 17 00:00:00 2001 From: Willi Carlsen Date: Fri, 29 Apr 2022 14:02:23 +0200 Subject: [PATCH 12/13] Convert ACL serviceAccountId from long to string --- .../Tika.RestClient/Features/Acls/Models/AclCreateDelete.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clients/dotnet-core-rest/src/Tika.RestClient/Features/Acls/Models/AclCreateDelete.cs b/clients/dotnet-core-rest/src/Tika.RestClient/Features/Acls/Models/AclCreateDelete.cs index 3f6ec6d..f506880 100644 --- a/clients/dotnet-core-rest/src/Tika.RestClient/Features/Acls/Models/AclCreateDelete.cs +++ b/clients/dotnet-core-rest/src/Tika.RestClient/Features/Acls/Models/AclCreateDelete.cs @@ -2,7 +2,7 @@ namespace Tika.RestClient.Features.Acls.Models { public class AclCreateDelete { - public long ServiceAccountId { get; set; } + public string ServiceAccountId { get; set; } public bool Allow { get; set; } public string Operation { get; set; } public string TopicPrefix { get; set; } @@ -10,7 +10,7 @@ public class AclCreateDelete public AclCreateDelete() {} - public AclCreateDelete(long serviceAccountId, bool allow, string operation, string topicPrefix = "", string consumerGroupPrefix = "") + public AclCreateDelete(string serviceAccountId, bool allow, string operation, string topicPrefix = "", string consumerGroupPrefix = "") { ServiceAccountId = serviceAccountId; Allow = allow; From 9e2274901b3eab78528ab030ec53531fb2a67ad9 Mon Sep 17 00:00:00 2001 From: "Emil H. Clausen" Date: Fri, 29 Apr 2022 14:24:32 +0200 Subject: [PATCH 13/13] Updated login.sh to use env vars instead of CLI automation to sign in --- server/login.sh | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/server/login.sh b/server/login.sh index e2c33dd..4cecb5a 100755 --- a/server/login.sh +++ b/server/login.sh @@ -1,15 +1,4 @@ -#!/usr/bin/expect -spawn confluent login - -expect "Email: " - -send -- "$env(TIKA_CC_USER)\r" - -expect "Password: " - -send -- "$env(TIKA_CC_PASS)\r" - -set timeout 600 -expect eof - -send_user "Confluent cloud login successful\n" \ No newline at end of file +#!/bin/ash +export CONFLUENT_CLOUD_EMAIL="$TIKA_CC_USER" +export CONFLUENT_CLOUD_PASSWORD="$TIKA_CC_PASS" +confluent login --save