Skip to content

Commit

Permalink
feat(kube-client): Add debug tree modifications (migtools#67)
Browse files Browse the repository at this point in the history
* Add changes to support debug tree api

* Make parameterized param optional

* add check for paramaterized resource
  • Loading branch information
ibolton336 authored Jun 29, 2021
1 parent 5dd826e commit 13b7e48
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/modules/kube-client/discoveryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export class DiscoveryClient extends OAuthClient implements IDiscoveryClient {
}

public get = (resource: IDiscoveryResource, params?: IDiscoveryParameters): Promise<any> => {
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<any> => {
Expand Down
6 changes: 3 additions & 3 deletions src/modules/kube-client/resources/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down
30 changes: 27 additions & 3 deletions src/modules/kube-client/resources/discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
}
}

0 comments on commit 13b7e48

Please sign in to comment.