@kubernetes/client-node
Version:
NodeJS client for kubernetes
47 lines • 1.65 kB
JavaScript
import { RequestContext } from "./http/http.js";
/**
*
* Represents the configuration of a server including its
* url template and variable configuration based on the url.
*
*/
export class ServerConfiguration {
constructor(url, variableConfiguration) {
this.url = url;
this.variableConfiguration = variableConfiguration;
}
/**
* Sets the value of the variables of this server. Variables are included in
* the `url` of this ServerConfiguration in the form `{variableName}`
*
* @param variableConfiguration a partial variable configuration for the
* variables contained in the url
*/
setVariables(variableConfiguration) {
Object.assign(this.variableConfiguration, variableConfiguration);
}
getConfiguration() {
return this.variableConfiguration;
}
getUrl() {
let replacedUrl = this.url;
for (const [key, value] of Object.entries(this.variableConfiguration)) {
replacedUrl = replacedUrl.replaceAll(`{${key}}`, value);
}
return replacedUrl;
}
/**
* Creates a new request context for this server using the url with variables
* replaced with their respective values and the endpoint of the request appended.
*
* @param endpoint the endpoint to be queried on the server
* @param httpMethod httpMethod to be used
*
*/
makeRequestContext(endpoint, httpMethod) {
return new RequestContext(this.getUrl() + endpoint, httpMethod);
}
}
export const server1 = new ServerConfiguration("", {});
export const servers = [server1];
//# sourceMappingURL=servers.js.map