-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
connections.ts
29 lines (26 loc) · 1.19 KB
/
connections.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { BearerCredentialHandler } from "azure-devops-node-api/handlers/bearertoken";
import { WebApi } from "azure-devops-node-api";
import { IRequestOptions } from "azure-devops-node-api/interfaces/common/VsoBaseInterfaces";
import * as tl from 'vsts-task-lib/task';
import * as locationUtility from "packaging-common/locationUtilities";
export function getConnection(areaId: string, collectionUrl: string): Promise<WebApi> {
var accessToken = locationUtility.getSystemAccessToken();
var presignedUrlPatterns: RegExp[] = [
new RegExp('.*blob\.core\.windows\.net.*'), // blobstore redirect
new RegExp('.*vsblob\.vsassets\.io.*') // edge caching enabled blob
];
return locationUtility
.getServiceUriFromAreaId(collectionUrl, accessToken, areaId)
.then(url => {
const options: IRequestOptions = {
proxy: tl.getHttpProxyConfiguration(url),
maxRetries: 5,
allowRetries: true,
presignedUrlPatterns: presignedUrlPatterns
};
return new WebApi(url, new BearerCredentialHandler(accessToken), options);
})
.catch(error => {
throw error;
});
}