Skip to content

Commit

Permalink
fix(discovery): remove unused shared discovery service code (migtools#72
Browse files Browse the repository at this point in the history
)

This code is only relevant to MTC and should be removed.
  • Loading branch information
ibolton336 authored Jul 13, 2021
1 parent 91d4089 commit 8da81af
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 304 deletions.
40 changes: 0 additions & 40 deletions src/modules/kube-client/client_factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ClusterClient } from './client';
import { DiscoveryClient } from './discoveryClient';
import { ResponseType } from 'axios';
import { TokenExpiryHandler } from './resources/common';

Expand All @@ -24,13 +23,6 @@ export class ClientFactoryMissingApiRoot extends Error {
}
}

export class ClientFactoryMissingDiscoveryApi extends Error {
constructor() {
super('Discovery API URL missing from client factory');
Object.setPrototypeOf(this, ClientFactoryMissingDiscoveryApi.prototype);
}
}

interface IUser {
access_token: string;
expiry_time: number;
Expand Down Expand Up @@ -61,38 +53,6 @@ export const ClientFactory = {

return newClient;
},
discovery: (
user: IUser,
namespace: string,
discoveryApi: string,
clusterName?: string,
tokenSecret?: string,
customResponseType: ResponseType = 'json'
): DiscoveryClient | null => {
if (!user) {
throw new ClientFactoryMissingUserError();
}

let decodedToken: string | null = null;
if (clusterName && tokenSecret) {
decodedToken = atob(tokenSecret);
}

const discoveryClient = new DiscoveryClient(
discoveryApi,
namespace,
decodedToken ? decodedToken : user.access_token,
customResponseType
);

if (tokenExpiryHandler) {
discoveryClient.setTokenExpiryHandler(
(tokenExpiryHandler as unknown) as TokenExpiryHandler,
user.expiry_time
);
}
return discoveryClient;
},
};

export const setTokenExpiryHandler = (newExpiryHandler: TokenExpiryHandler): void => {
Expand Down
76 changes: 0 additions & 76 deletions src/modules/kube-client/discoveryClient.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/modules/kube-client/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export * from './client';
export * from './client_factory';
export * from './discoveryClient';
export * from './resources/common';
export * from './resources/core';
export * from './resources/discovery';
84 changes: 0 additions & 84 deletions src/modules/kube-client/resources/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,12 @@ export interface IKubeResource {
namedPath(name: string): string;
}

export interface IDiscoveryResource {
discoveryAggregator(): string;
discoveryType(): string;
path(): string;
parametrized?(params?: IDiscoveryParameters): { [param: string]: string };
}
export interface INamedDiscoveryResource extends IDiscoveryResource {
discoveryName(): string;
}

export interface IGroupVersionKindPlural {
group: string;
version: string;
kindPlural: string;
}

export interface IDiscoveryParameters {
offset?: number;
limit?: number;
[param: string]: string | number | undefined;
}

// eslint-disable-next-line @typescript-eslint/ban-types
export type TokenExpiryHandler = (oldToken: object) => void;

Expand Down Expand Up @@ -70,74 +54,6 @@ export abstract class ClusterResource implements IKubeResource {
}
}

export abstract class DiscoveryResource implements IDiscoveryResource {
private readonly _type: string;
private readonly _aggregatorType: string;
private readonly _aggregatorName: string;
private _discoveryParameters: IDiscoveryParameters;

constructor(
aggregatorName: string,
type: string,
discoveryParameters: IDiscoveryParameters,
customAggregatorType = 'clusters'
) {
this._aggregatorType = customAggregatorType;
this._aggregatorName = aggregatorName;
this._type = type;
this._discoveryParameters = discoveryParameters;
}

public discoveryType(): string {
return this._type;
}

public discoveryAggregator(): string {
return [this._aggregatorType, this._aggregatorName].join('/');
}

public parametrized(params: IDiscoveryParameters = {}): { [param: string]: string } {
const merged = {};
Object.keys(this._discoveryParameters).map(
(param) => (merged[param] = this._discoveryParameters[param]?.toString())
);
Object.keys(params).map(
(param) => (merged[param] = this._discoveryParameters[param]?.toString())
);
return merged;
}

public path(): string {
return [this.discoveryAggregator(), this.discoveryType()].join('/');
}
}

export abstract class NamedDiscoveryResource
extends DiscoveryResource
implements INamedDiscoveryResource {
private readonly _name: string;

constructor(
name: string,
aggregator: string,
type: string,
discoveryParameters: IDiscoveryParameters,
customAggregatorType = 'clusters'
) {
super(aggregator, type, discoveryParameters, customAggregatorType);

this._name = name;
}

public discoveryName(): string {
return this._name;
}

public path(): string {
return [super.path(), this.discoveryName()].join('/');
}
}

export abstract class OAuthClient {
private _token: string;
private _tokenExpiryTime: number | null = null;
Expand Down
102 changes: 0 additions & 102 deletions src/modules/kube-client/resources/discovery.ts

This file was deleted.

0 comments on commit 8da81af

Please sign in to comment.