From 13b7e48fdab72916d320081cfb02c5182a39a32f Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Tue, 29 Jun 2021 16:27:32 -0400 Subject: [PATCH] feat(kube-client): Add debug tree modifications (#67) * Add changes to support debug tree api * Make parameterized param optional * add check for paramaterized resource --- src/modules/kube-client/discoveryClient.ts | 6 +++- src/modules/kube-client/resources/common.ts | 6 ++-- .../kube-client/resources/discovery.ts | 30 +++++++++++++++++-- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/modules/kube-client/discoveryClient.ts b/src/modules/kube-client/discoveryClient.ts index 4292d4f..3412f58 100644 --- a/src/modules/kube-client/discoveryClient.ts +++ b/src/modules/kube-client/discoveryClient.ts @@ -54,7 +54,11 @@ export class DiscoveryClient extends OAuthClient implements IDiscoveryClient { } public get = (resource: IDiscoveryResource, params?: IDiscoveryParameters): Promise => { - return this._get(this.fullPath(resource.path()), resource.parametrized(params)); + if (params && resource.parametrized) { + return this._get(this.fullPath(resource.path()), resource?.parametrized(params)); + } else { + return this._get(this.fullPath(resource.path())); + } }; public getRaw = (path: string): Promise => { diff --git a/src/modules/kube-client/resources/common.ts b/src/modules/kube-client/resources/common.ts index 44af157..092c3d8 100644 --- a/src/modules/kube-client/resources/common.ts +++ b/src/modules/kube-client/resources/common.ts @@ -9,9 +9,8 @@ export interface IDiscoveryResource { discoveryAggregator(): string; discoveryType(): string; path(): string; - parametrized(params?: IDiscoveryParameters): { [param: string]: string }; + parametrized?(params?: IDiscoveryParameters): { [param: string]: string }; } - export interface INamedDiscoveryResource extends IDiscoveryResource { discoveryName(): string; } @@ -113,7 +112,8 @@ export abstract class DiscoveryResource implements IDiscoveryResource { } } -export abstract class NamedDiscoveryResource extends DiscoveryResource +export abstract class NamedDiscoveryResource + extends DiscoveryResource implements INamedDiscoveryResource { private readonly _name: string; diff --git a/src/modules/kube-client/resources/discovery.ts b/src/modules/kube-client/resources/discovery.ts index eb623d6..dcb649a 100644 --- a/src/modules/kube-client/resources/discovery.ts +++ b/src/modules/kube-client/resources/discovery.ts @@ -71,8 +71,32 @@ export class PlanPodReportDiscovery extends DiscoveryResource { } } -export class DebugTreeDiscoveryResource extends DiscoveryResource { - constructor(planName: string, params: IDiscoveryParameters = {}) { - super(planName, 'tree', params, 'plans'); +export interface IDebugTreeResource { + discoveryAggregator(): string; + discoveryType(): string; + path(): string; +} + +export class DebugTreeDiscoveryResource implements IDebugTreeResource { + private readonly _aggregatorType: string; + private readonly _aggregatorName: string; + private readonly _aggregatorSpecifier: string; + + constructor(planName: string, migrationName: string, treeType = 'plans') { + this._aggregatorType = treeType; + this._aggregatorName = planName; + this._aggregatorSpecifier = migrationName; + } + + public discoveryType() { + return 'tree'; + } + + public discoveryAggregator() { + return [this._aggregatorType, this._aggregatorName].join('/'); + } + + public path(): string { + return [this.discoveryAggregator(), this.discoveryType(), this._aggregatorSpecifier].join('/'); } }