2015-07-24 00:18:52 +03:00
|
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
import VsoBaseInterfaces = require('./interfaces/common/VsoBaseInterfaces');
|
|
|
|
import basem = require('./ClientApiBases');
|
|
|
|
import buildm = require('./BuildApi');
|
|
|
|
import corem = require('./CoreApi');
|
2017-03-23 22:52:28 +03:00
|
|
|
import dashboardm = require('./DashboardApi');
|
2016-09-02 19:38:29 +03:00
|
|
|
import extmgmtm = require("./ExtensionManagementApi");
|
|
|
|
import featuremgmtm = require("./FeatureManagementApi");
|
2015-07-24 00:18:52 +03:00
|
|
|
import filecontainerm = require('./FileContainerApi');
|
2019-01-07 19:27:34 +03:00
|
|
|
import gallerym = require('./GalleryApi');
|
2015-07-24 00:18:52 +03:00
|
|
|
import gitm = require('./GitApi');
|
2017-03-23 22:52:28 +03:00
|
|
|
import locationsm = require('./LocationsApi');
|
|
|
|
import notificationm = require('./NotificationApi');
|
|
|
|
import policym = require('./PolicyApi');
|
|
|
|
import profilem = require('./ProfileApi');
|
2018-02-12 21:13:37 +03:00
|
|
|
import projectm = require('./ProjectAnalysisApi');
|
2017-03-23 22:52:28 +03:00
|
|
|
import releasem = require('./ReleaseApi');
|
|
|
|
import securityrolesm = require('./SecurityRolesApi');
|
2015-07-24 00:18:52 +03:00
|
|
|
import taskagentm = require('./TaskAgentApi');
|
|
|
|
import taskm = require('./TaskApi');
|
|
|
|
import testm = require('./TestApi');
|
|
|
|
import tfvcm = require('./TfvcApi');
|
2018-06-13 21:33:03 +03:00
|
|
|
import wikim = require('./WikiApi');
|
2017-03-23 22:52:28 +03:00
|
|
|
import workm = require('./WorkApi');
|
2015-07-24 00:18:52 +03:00
|
|
|
import workitemtrackingm = require('./WorkItemTrackingApi');
|
2018-03-26 15:24:50 +03:00
|
|
|
import workitemtrackingprocessm = require('./WorkItemTrackingProcessApi');
|
|
|
|
import workitemtrackingprocessdefinitionm = require('./WorkItemTrackingProcessDefinitionsApi');
|
2015-07-24 00:18:52 +03:00
|
|
|
import basicm = require('./handlers/basiccreds');
|
|
|
|
import bearm = require('./handlers/bearertoken');
|
2016-07-06 16:54:51 +03:00
|
|
|
import ntlmm = require('./handlers/ntlm');
|
2016-07-28 05:16:44 +03:00
|
|
|
import patm = require('./handlers/personalaccesstoken');
|
2015-07-24 00:18:52 +03:00
|
|
|
|
2017-04-06 05:19:47 +03:00
|
|
|
import * as rm from 'typed-rest-client/RestClient';
|
|
|
|
import vsom = require('./VsoClient');
|
2017-04-06 05:31:59 +03:00
|
|
|
import lim = require("./interfaces/LocationsInterfaces");
|
2017-04-06 05:19:47 +03:00
|
|
|
|
2017-08-29 17:37:00 +03:00
|
|
|
import crypto = require('crypto');
|
2018-09-21 16:50:38 +03:00
|
|
|
import fs = require('fs');
|
|
|
|
import os = require('os');
|
2018-10-08 03:04:05 +03:00
|
|
|
import url = require('url');
|
2018-10-12 18:38:47 +03:00
|
|
|
import path = require('path');
|
2017-08-29 17:37:00 +03:00
|
|
|
|
2019-06-04 22:14:04 +03:00
|
|
|
const isBrowser: boolean = typeof window !== 'undefined';
|
2015-08-04 18:54:10 +03:00
|
|
|
/**
|
|
|
|
* Methods to return handler objects (see handlers folder)
|
|
|
|
*/
|
|
|
|
|
2017-06-15 23:40:58 +03:00
|
|
|
export function getBasicHandler(username: string, password: string): VsoBaseInterfaces.IRequestHandler {
|
2015-08-04 18:54:10 +03:00
|
|
|
return new basicm.BasicCredentialHandler(username, password);
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:40:58 +03:00
|
|
|
export function getNtlmHandler(username: string, password: string, workstation?: string, domain?: string): VsoBaseInterfaces.IRequestHandler {
|
2016-07-06 16:54:51 +03:00
|
|
|
return new ntlmm.NtlmCredentialHandler(username, password, workstation, domain);
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:40:58 +03:00
|
|
|
export function getBearerHandler(token: string): VsoBaseInterfaces.IRequestHandler {
|
2015-08-04 18:54:10 +03:00
|
|
|
return new bearm.BearerCredentialHandler(token);
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:40:58 +03:00
|
|
|
export function getPersonalAccessTokenHandler(token: string): VsoBaseInterfaces.IRequestHandler {
|
2016-07-28 05:16:44 +03:00
|
|
|
return new patm.PersonalAccessTokenCredentialHandler(token);
|
|
|
|
}
|
|
|
|
|
2017-06-15 23:40:58 +03:00
|
|
|
export function getHandlerFromToken(token: string): VsoBaseInterfaces.IRequestHandler {
|
|
|
|
if (token.length === 52) {
|
|
|
|
return getPersonalAccessTokenHandler(token);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return getBearerHandler(token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-21 16:50:38 +03:00
|
|
|
export interface IWebApiRequestSettings {
|
|
|
|
productName: string,
|
|
|
|
productVersion: string
|
|
|
|
};
|
|
|
|
|
2015-07-24 00:18:52 +03:00
|
|
|
// ---------------------------------------------------------------------------
|
2015-07-24 00:34:31 +03:00
|
|
|
// Factory to return client apis
|
2017-06-05 21:59:40 +03:00
|
|
|
// When new APIs are added, a method must be added here to instantiate the API
|
2015-07-24 00:18:52 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
export class WebApi {
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public serverUrl: string;
|
|
|
|
public authHandler: VsoBaseInterfaces.IRequestHandler;
|
|
|
|
public rest: rm.RestClient;
|
|
|
|
public vsoClient: vsom.VsoClient;
|
|
|
|
public options: VsoBaseInterfaces.IRequestOptions;
|
|
|
|
|
|
|
|
private _resourceAreas: lim.ResourceAreaInfo[];
|
2015-07-24 00:18:52 +03:00
|
|
|
|
|
|
|
/*
|
2015-07-24 00:34:31 +03:00
|
|
|
* Factory to return client apis and handlers
|
2017-03-09 16:11:52 +03:00
|
|
|
* @param defaultUrl default server url to use when creating new apis from factory methods
|
|
|
|
* @param authHandler default authentication credentials to use when creating new apis from factory methods
|
2015-07-24 00:18:52 +03:00
|
|
|
*/
|
2018-09-21 16:50:38 +03:00
|
|
|
constructor(defaultUrl: string, authHandler: VsoBaseInterfaces.IRequestHandler, options?: VsoBaseInterfaces.IRequestOptions, requestSettings?: IWebApiRequestSettings) {
|
2017-03-09 16:11:52 +03:00
|
|
|
this.serverUrl = defaultUrl;
|
2015-07-24 00:18:52 +03:00
|
|
|
this.authHandler = authHandler;
|
2017-08-29 17:37:00 +03:00
|
|
|
this.options = options || {};
|
|
|
|
|
2018-10-08 03:04:05 +03:00
|
|
|
if (!this.isNoProxyHost(this.serverUrl)) {
|
|
|
|
// try to get proxy setting from environment variable set by VSTS-Task-Lib if there is no proxy setting in the options
|
|
|
|
if (!this.options.proxy || !this.options.proxy.proxyUrl) {
|
|
|
|
if (global['_vsts_task_lib_proxy']) {
|
|
|
|
let proxyFromEnv: VsoBaseInterfaces.IProxyConfiguration = {
|
|
|
|
proxyUrl: global['_vsts_task_lib_proxy_url'],
|
|
|
|
proxyUsername: global['_vsts_task_lib_proxy_username'],
|
|
|
|
proxyPassword: this._readTaskLibSecrets(global['_vsts_task_lib_proxy_password']),
|
|
|
|
proxyBypassHosts: JSON.parse(global['_vsts_task_lib_proxy_bypass'] || "[]"),
|
|
|
|
};
|
|
|
|
|
|
|
|
this.options.proxy = proxyFromEnv;
|
|
|
|
}
|
2017-08-29 17:37:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// try get cert setting from environment variable set by VSTS-Task-Lib if there is no cert setting in the options
|
|
|
|
if (!this.options.cert) {
|
|
|
|
if (global['_vsts_task_lib_cert']) {
|
|
|
|
let certFromEnv: VsoBaseInterfaces.ICertConfiguration = {
|
|
|
|
caFile: global['_vsts_task_lib_cert_ca'],
|
|
|
|
certFile: global['_vsts_task_lib_cert_clientcert'],
|
|
|
|
keyFile: global['_vsts_task_lib_cert_key'],
|
|
|
|
passphrase: this._readTaskLibSecrets(global['_vsts_task_lib_cert_passphrase']),
|
|
|
|
};
|
|
|
|
|
|
|
|
this.options.cert = certFromEnv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 17:41:32 +03:00
|
|
|
// try get ignore SSL error setting from environment variable set by VSTS-Task-Lib if there is no ignore SSL error setting in the options
|
|
|
|
if (!this.options.ignoreSslError) {
|
|
|
|
this.options.ignoreSslError = !!global['_vsts_task_lib_skip_cert_validation'];
|
|
|
|
}
|
|
|
|
|
2018-09-21 16:50:38 +03:00
|
|
|
let userAgent: string;
|
|
|
|
const nodeApiName: string = 'azure-devops-node-api';
|
2019-04-01 16:47:17 +03:00
|
|
|
if(isBrowser) {
|
|
|
|
if(requestSettings) {
|
|
|
|
userAgent = `${requestSettings.productName}/${requestSettings.productVersion} (${nodeApiName}; ${window.navigator.userAgent})`
|
|
|
|
} else {
|
|
|
|
userAgent = `${nodeApiName} (${window.navigator.userAgent})`;
|
|
|
|
}
|
|
|
|
} else {
|
2019-10-07 16:34:54 +03:00
|
|
|
let nodeApiVersion: string = 'unknown';
|
|
|
|
const packageJsonPath: string = path.resolve(__dirname, 'package.json');
|
|
|
|
if (fs.existsSync(packageJsonPath)) {
|
|
|
|
nodeApiVersion = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')).version;
|
|
|
|
}
|
2019-04-01 16:47:17 +03:00
|
|
|
const osName: string = os.platform();
|
|
|
|
const osVersion: string = os.release();
|
2018-09-21 16:50:38 +03:00
|
|
|
|
2019-04-01 16:47:17 +03:00
|
|
|
if (requestSettings) {
|
|
|
|
userAgent = `${requestSettings.productName}/${requestSettings.productVersion} (${nodeApiName} ${nodeApiVersion}; ${osName} ${osVersion})`;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
userAgent = `${nodeApiName}/${nodeApiVersion} (${osName} ${osVersion})`;
|
|
|
|
}
|
2018-09-21 16:50:38 +03:00
|
|
|
}
|
|
|
|
this.rest = new rm.RestClient(userAgent, null, [this.authHandler], this.options);
|
2017-07-14 05:22:04 +03:00
|
|
|
this.vsoClient = new vsom.VsoClient(defaultUrl, this.rest);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 16:11:52 +03:00
|
|
|
/**
|
|
|
|
* Convenience factory to create with a bearer token.
|
|
|
|
* @param defaultServerUrl default server url to use when creating new apis from factory methods
|
|
|
|
* @param defaultAuthHandler default authentication credentials to use when creating new apis from factory methods
|
2017-07-14 05:22:04 +03:00
|
|
|
*/
|
|
|
|
public static createWithBearerToken(defaultUrl: string, token: string, options?: VsoBaseInterfaces.IRequestOptions) {
|
2017-03-09 16:11:52 +03:00
|
|
|
let bearerHandler = getBearerHandler(token);
|
2017-07-14 05:22:04 +03:00
|
|
|
return new this(defaultUrl, bearerHandler, options);
|
|
|
|
}
|
2017-03-09 16:11:52 +03:00
|
|
|
|
2017-07-14 05:22:04 +03:00
|
|
|
public async connect(): Promise<lim.ConnectionData> {
|
2017-04-06 05:31:59 +03:00
|
|
|
return new Promise<lim.ConnectionData>(async (resolve, reject) => {
|
2017-04-06 05:19:47 +03:00
|
|
|
try {
|
2017-04-06 05:31:59 +03:00
|
|
|
let res: rm.IRestResponse<lim.ConnectionData>;
|
|
|
|
res = await this.rest.get<lim.ConnectionData>(this.vsoClient.resolveUrl('/_apis/connectionData'));
|
2017-04-06 05:19:47 +03:00
|
|
|
resolve(res.result);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
reject(err);
|
|
|
|
}
|
|
|
|
});
|
2017-07-14 05:22:04 +03:00
|
|
|
}
|
2017-04-06 05:19:47 +03:00
|
|
|
|
2015-07-24 00:34:31 +03:00
|
|
|
/**
|
|
|
|
* Each factory method can take a serverUrl and a list of handlers
|
|
|
|
* if these aren't provided, the default url and auth handler given to the constructor for this class will be used
|
|
|
|
*/
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getBuildApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<buildm.IBuildApi> {
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, buildm.BuildApi.RESOURCE_AREA_ID);
|
2017-03-09 16:11:52 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
2017-07-14 05:22:04 +03:00
|
|
|
return new buildm.BuildApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getCoreApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<corem.ICoreApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "79134c72-4a58-4b42-976c-04e7115f32bf");
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new corem.CoreApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getDashboardApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<dashboardm.IDashboardApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "31c84e0a-3ece-48fd-a29d-100849af99ba");
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new dashboardm.DashboardApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getExtensionManagementApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<extmgmtm.IExtensionManagementApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "6c2b0933-3600-42ae-bf8b-93d4f7e83594");
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new extmgmtm.ExtensionManagementApi(serverUrl, handlers, this.options);
|
2016-09-02 19:38:29 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getFeatureManagementApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<featuremgmtm.IFeatureManagementApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "");
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new featuremgmtm.FeatureManagementApi(serverUrl, handlers, this.options);
|
2016-09-02 19:38:29 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getFileContainerApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<filecontainerm.IFileContainerApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "");
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new filecontainerm.FileContainerApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2019-01-07 19:27:34 +03:00
|
|
|
public async getGalleryApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<gallerym.IGalleryApi> {
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, gallerym.GalleryApi.RESOURCE_AREA_ID);
|
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new gallerym.GalleryApi(serverUrl, handlers, this.options);
|
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getGitApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<gitm.IGitApi> {
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, gitm.GitApi.RESOURCE_AREA_ID);
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new gitm.GitApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
// TODO: Don't call resource area here? Will cause infinite loop?
|
|
|
|
public async getLocationsApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<locationsm.ILocationsApi> {
|
2019-03-21 17:33:47 +03:00
|
|
|
let optionsClone: VsoBaseInterfaces.IRequestOptions = Object.assign({}, this.options);
|
|
|
|
optionsClone.allowRetries = true;
|
|
|
|
optionsClone.maxRetries = 5;
|
2018-02-12 21:13:37 +03:00
|
|
|
serverUrl = await serverUrl || this.serverUrl;
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
2019-03-21 17:33:47 +03:00
|
|
|
return new locationsm.LocationsApi(serverUrl, handlers, optionsClone);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getNotificationApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<notificationm.INotificationApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "");
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new notificationm.NotificationApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getPolicyApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<policym.IPolicyApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "fb13a388-40dd-4a04-b530-013a739c72ef");
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new policym.PolicyApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getProfileApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<profilem.IProfileApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "8ccfef3d-2b87-4e99-8ccb-66e343d2daa8");
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new profilem.ProfileApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getProjectAnalysisApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<projectm.IProjectAnalysisApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "7658fa33-b1bf-4580-990f-fac5896773d3");
|
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new projectm.ProjectAnalysisApi(serverUrl, handlers, this.options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async getSecurityRolesApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<securityrolesm.ISecurityRolesApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "");
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new securityrolesm.SecurityRolesApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getReleaseApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<releasem.IReleaseApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "efc2f575-36ef-48e9-b672-0c6fb4a48ac5");
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new releasem.ReleaseApi(serverUrl, handlers, this.options);
|
2017-03-23 22:52:28 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getTaskApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<taskm.ITaskApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "");
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new taskm.TaskApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getTaskAgentApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<taskagentm.ITaskAgentApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "a85b8835-c1a1-4aac-ae97-1c3d0ba72dbd");
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new taskagentm.TaskAgentApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getTestApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<testm.ITestApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "c2aa639c-3ccc-4740-b3b6-ce2a1e1d984e");
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new testm.TestApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getTfvcApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<tfvcm.ITfvcApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "8aa40520-446d-40e6-89f6-9c9f9ce44c48");
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new tfvcm.TfvcApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2018-06-13 21:33:03 +03:00
|
|
|
public async getWikiApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<wikim.IWikiApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "bf7d82a0-8aa5-4613-94ef-6172a5ea01f3");
|
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new wikim.WikiApi(serverUrl, handlers, this.options);
|
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getWorkApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<workm.IWorkApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "1d4f49f9-02b9-4e26-b826-2cdb6195f2a9");
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new workm.WorkApi(serverUrl, handlers, this.options);
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|
|
|
|
|
2018-02-12 21:13:37 +03:00
|
|
|
public async getWorkItemTrackingApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<workitemtrackingm.IWorkItemTrackingApi> {
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, workitemtrackingm.WorkItemTrackingApi.RESOURCE_AREA_ID);
|
2017-07-14 05:22:04 +03:00
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new workitemtrackingm.WorkItemTrackingApi(serverUrl, handlers, this.options);
|
2015-08-20 18:55:10 +03:00
|
|
|
}
|
2017-08-29 17:37:00 +03:00
|
|
|
|
2018-03-26 17:13:41 +03:00
|
|
|
public async getWorkItemTrackingProcessApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<workitemtrackingprocessm.IWorkItemTrackingProcessApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "5264459e-e5e0-4bd8-b118-0985e68a4ec5");
|
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new workitemtrackingprocessm.WorkItemTrackingProcessApi(serverUrl, handlers, this.options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async getWorkItemTrackingProcessDefinitionApi(serverUrl?: string, handlers?: VsoBaseInterfaces.IRequestHandler[]): Promise<workitemtrackingprocessdefinitionm.IWorkItemTrackingProcessDefinitionsApi> {
|
|
|
|
// TODO: Load RESOURCE_AREA_ID correctly.
|
|
|
|
serverUrl = await this._getResourceAreaUrl(serverUrl || this.serverUrl, "5264459e-e5e0-4bd8-b118-0985e68a4ec5");
|
|
|
|
handlers = handlers || [this.authHandler];
|
|
|
|
return new workitemtrackingprocessdefinitionm.WorkItemTrackingProcessDefinitionsApi(serverUrl, handlers, this.options);
|
|
|
|
}
|
|
|
|
|
2018-10-08 03:04:05 +03:00
|
|
|
/**
|
|
|
|
* Determines if the domain is exluded for proxy via the no_proxy env var
|
|
|
|
* @param url: the server url
|
|
|
|
*/
|
|
|
|
public isNoProxyHost = function(_url: string) {
|
2018-10-10 23:14:01 +03:00
|
|
|
if (!process.env.no_proxy) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-08 03:04:05 +03:00
|
|
|
const noProxyDomains = (process.env.no_proxy || '')
|
|
|
|
.split(',')
|
|
|
|
.map(v => v.toLowerCase());
|
|
|
|
const serverUrl = url.parse(_url).host.toLowerCase();
|
|
|
|
// return true if the no_proxy includes the host
|
|
|
|
return noProxyDomains.indexOf(serverUrl) !== -1;
|
|
|
|
}
|
|
|
|
|
2018-03-26 15:24:50 +03:00
|
|
|
private async _getResourceAreaUrl(serverUrl: string, resourceId: string): Promise<string> {
|
2018-02-12 21:13:37 +03:00
|
|
|
if (!resourceId) {
|
|
|
|
return serverUrl;
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:02:59 +03:00
|
|
|
// This must be of type any, see comment just below.
|
|
|
|
const resourceAreas: any = await this._getResourceAreas();
|
2018-02-12 21:13:37 +03:00
|
|
|
|
|
|
|
if (resourceAreas === undefined) {
|
|
|
|
throw new Error((`Failed to retrieve resource areas ' + 'from server: ${serverUrl}`));
|
|
|
|
}
|
|
|
|
|
2018-02-15 20:02:59 +03:00
|
|
|
// The response type differs based on whether or not there are resource areas. When we are on prem we get:
|
|
|
|
// {"count":0,"value":null} and when we are on VSTS we get an array of resource areas.
|
|
|
|
// Due to this strangeness the type of resourceAreas needs to be any and we need to check .count
|
|
|
|
// When going against vsts count will be undefined. On prem it will be 0
|
|
|
|
if (!resourceAreas || resourceAreas.length === 0 || resourceAreas.count === 0) {
|
2018-02-12 21:13:37 +03:00
|
|
|
// For on prem environments we get an empty list
|
|
|
|
return serverUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var resourceArea of resourceAreas) {
|
|
|
|
if (resourceArea.id.toLowerCase() === resourceId.toLowerCase()) {
|
|
|
|
return resourceArea.locationUrl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error((`Could not find information for resource area ${resourceId} ' + 'from server: ${serverUrl}`));
|
|
|
|
}
|
|
|
|
|
|
|
|
private async _getResourceAreas(): Promise<lim.ResourceAreaInfo[]> {
|
|
|
|
if (!this._resourceAreas) {
|
|
|
|
const locationClient: locationsm.ILocationsApi = await this.getLocationsApi();
|
|
|
|
this._resourceAreas = await locationClient.getResourceAreas();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._resourceAreas;
|
|
|
|
}
|
|
|
|
|
2017-08-29 17:37:00 +03:00
|
|
|
private _readTaskLibSecrets(lookupKey: string): string {
|
2019-04-01 16:47:17 +03:00
|
|
|
if(isBrowser) {
|
|
|
|
throw new Error("Browsers can't securely keep secrets");
|
|
|
|
}
|
2017-08-29 17:37:00 +03:00
|
|
|
// the lookupKey should has following format
|
|
|
|
// base64encoded<keyFilePath>:base64encoded<encryptedContent>
|
|
|
|
if (lookupKey && lookupKey.indexOf(':') > 0) {
|
|
|
|
let lookupInfo: string[] = lookupKey.split(':', 2);
|
|
|
|
|
|
|
|
// file contains encryption key
|
|
|
|
let keyFile = new Buffer(lookupInfo[0], 'base64').toString('utf8');
|
|
|
|
let encryptKey = new Buffer(fs.readFileSync(keyFile, 'utf8'), 'base64');
|
|
|
|
|
|
|
|
let encryptedContent: string = new Buffer(lookupInfo[1], 'base64').toString('utf8');
|
|
|
|
|
|
|
|
let decipher = crypto.createDecipher("aes-256-ctr", encryptKey)
|
|
|
|
let decryptedContent = decipher.update(encryptedContent, 'hex', 'utf8')
|
|
|
|
decryptedContent += decipher.final('utf8');
|
|
|
|
|
|
|
|
return decryptedContent;
|
|
|
|
}
|
|
|
|
}
|
2015-07-24 00:18:52 +03:00
|
|
|
}
|