@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
108 lines (106 loc) • 3.72 kB
JavaScript
import { Net } from './net';
export class GatewayUrlTranslator {
static translations = {
powerShellTranslationMatcher: /features\/powershellApi\/(.*)/,
cimTranslationMatcher: /features\/cim\/(.*)/,
wdacMatcher: /features\/wdac\/(.*)/,
jeaMatcher: /features\/jea\/(.*)/,
fileTransferMatcher: /features\/fileTransfer\/(.*)/,
counterMatcher: /counter\/(.*)/
};
/**
* Given url return a gateway v2 translation object that will work well with
* nodes/node api.
*
* @param url a gateway v1 url
* @returns
*/
static translate(url) {
if (this.translations.powerShellTranslationMatcher.test(url)) {
return this.translatePowerShellRequest(url);
}
if (this.translations.cimTranslationMatcher.test(url)) {
return this.translateCimRequest(url);
}
if (this.translations.jeaMatcher.test(url)) {
return this.translateJeaRequest(url);
}
if (this.translations.wdacMatcher.test(url)) {
return this.translateWdacRequest(url);
}
if (this.translations.fileTransferMatcher.test(url)) {
return this.translateFileTransferRequest(url);
}
if (this.translations.counterMatcher.test(url)) {
return this.translateCounterRequest(url);
}
return null;
}
static translatePowerShellRequest(url) {
const matches = url.match(this.translations.powerShellTranslationMatcher);
if (matches) {
const restOfString = matches[1];
return {
newUrl: restOfString,
startUrl: `services/${Net.serviceWinRest}/${Net.controllerPowerShell}`
};
}
return null;
}
static translateCimRequest(url) {
const matches = url.match(this.translations.cimTranslationMatcher);
if (matches) {
const restOfString = matches[1];
return {
newUrl: restOfString,
startUrl: `services/${Net.serviceWinRest}/${Net.controllerCim}`
};
}
return null;
}
static translateJeaRequest(url) {
const matches = url.match(this.translations.jeaMatcher);
if (matches) {
const restOfString = matches[1];
return {
newUrl: restOfString,
startUrl: `services/${Net.serviceWinRest}/${Net.controllerJea}`
};
}
return null;
}
static translateFileTransferRequest(url) {
const matches = url.match(this.translations.fileTransferMatcher);
if (matches) {
const restOfString = matches[1];
return {
newUrl: restOfString,
startUrl: `services/${Net.serviceWinRest}/${Net.controllerFileTransfer}`
};
}
return null;
}
static translateWdacRequest(url) {
const matches = url.match(this.translations.wdacMatcher);
if (matches) {
const restOfString = matches[1];
return {
newUrl: restOfString,
startUrl: `services/${Net.serviceWinRest}/${Net.controllerWdac}`
};
}
return null;
}
static translateCounterRequest(url) {
const matches = url.match(this.translations.counterMatcher);
if (matches) {
const restOfString = matches[1];
return {
newUrl: restOfString,
startUrl: `services/${Net.serviceWinRest}/${Net.controllerPerformanceCounter}`
};
}
return null;
}
}
//# sourceMappingURL=gateway-url-translator.js.map