Skip to content

Commit 85616f8

Browse files
authored
Users/aamallad/afd download packages fix (#11900)
* Updated auth token filter to skip sending auth headers for blobstore and AFD (#11896) * Fixed DownloadPackageV0 task to be able to download AFD enabled packages (#11897)
1 parent b48b9e5 commit 85616f8

File tree

8 files changed

+24
-57
lines changed

8 files changed

+24
-57
lines changed

Tasks/DownloadPackageV0/connections.ts

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,22 @@ import { IRequestOptions } from "azure-devops-node-api/interfaces/common/VsoBase
55
import * as tl from 'vsts-task-lib/task';
66
import * as locationUtility from "packaging-common/locationUtilities";
77

8-
// TODO Remove this once this bug is resolved: https://github.com/Microsoft/typed-rest-client/issues/126
9-
export class BearerHandlerForPresignedUrls extends BearerCredentialHandler {
10-
prepareRequest(options) {
11-
// If we have a presigned blobstore url, don't add auth header
12-
if (this.isPreSignedUrl(options)) {
13-
delete options.headers["Authorization"];
14-
delete options.headers["X-TFS-FedAuthRedirect"];
15-
} else {
16-
options.headers["Authorization"] = "Bearer " + this.token;
17-
options.headers["X-TFS-FedAuthRedirect"] = "Suppress";
18-
}
19-
}
20-
21-
isPreSignedUrl(options: any): boolean {
22-
return (
23-
options.host &&
24-
options.host.endsWith("blob.core.windows.net") &&
25-
options.path &&
26-
options.path.includes("&sig=")
27-
);
28-
}
29-
}
30-
318
export function getConnection(areaId: string, collectionUrl: string, accessToken: string): Promise<WebApi> {
9+
var presignedUrlPatterns: RegExp[] = [
10+
new RegExp('.*blob\.core\.windows\.net.*'), // blobstore redirect
11+
new RegExp('.*vsblob\.vsassets\.io.*') // edge caching enabled blob
12+
];
13+
3214
return locationUtility
3315
.getServiceUriFromAreaId(collectionUrl, accessToken, areaId)
3416
.then(url => {
3517
const options: IRequestOptions = {
3618
proxy: tl.getHttpProxyConfiguration(url),
3719
maxRetries: 5,
38-
allowRetries: true
20+
allowRetries: true,
21+
presignedUrlPatterns: presignedUrlPatterns
3922
};
40-
return new WebApi(url, new BearerHandlerForPresignedUrls(accessToken), options);
23+
return new WebApi(url, new BearerCredentialHandler(accessToken), options);
4124
})
4225
.catch(error => {
4326
throw error;

Tasks/DownloadPackageV0/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"homepage": "https://github.com/Microsoft/azure-pipelines-tasks#readme",
1919
"dependencies": {
2020
"@types/node": "^6.14.2",
21+
"azure-devops-node-api": "9.0.1",
2122
"azure-pipelines-task-lib": "2.8.0",
2223
"decompress-zip": "0.3.0",
2324
"packaging-common": "file:../../_build/Tasks/Common/packaging-common-1.0.1.tgz",

Tasks/DownloadPackageV0/task.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"author": "ms-vscs-rm",
1010
"version": {
1111
"Major": 0,
12-
"Minor": 160,
13-
"Patch": 0
12+
"Minor": 161,
13+
"Patch": 1
1414
},
1515
"demands": [],
1616
"minimumAgentVersion": "1.99.0",

Tasks/DownloadPackageV0/task.loc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"author": "ms-vscs-rm",
1010
"version": {
1111
"Major": 0,
12-
"Minor": 160,
13-
"Patch": 0
12+
"Minor": 161,
13+
"Patch": 1
1414
},
1515
"demands": [],
1616
"minimumAgentVersion": "1.99.0",

Tasks/DownloadPackageV1/connections.ts

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,23 @@ import { IRequestOptions } from "azure-devops-node-api/interfaces/common/VsoBase
55
import * as tl from 'vsts-task-lib/task';
66
import * as locationUtility from "packaging-common/locationUtilities";
77

8-
// TODO Remove this once this bug is resolved: https://github.com/Microsoft/typed-rest-client/issues/126
9-
export class BearerHandlerForPresignedUrls extends BearerCredentialHandler {
10-
prepareRequest(options) {
11-
// If we have a presigned blobstore url, don't add auth header
12-
if (this.isPreSignedUrl(options)) {
13-
delete options.headers["Authorization"];
14-
delete options.headers["X-TFS-FedAuthRedirect"];
15-
} else {
16-
options.headers["Authorization"] = "Bearer " + this.token;
17-
options.headers["X-TFS-FedAuthRedirect"] = "Suppress";
18-
}
19-
}
20-
21-
isPreSignedUrl(options: any): boolean {
22-
return (
23-
options.host &&
24-
options.host.endsWith("blob.core.windows.net") &&
25-
options.path &&
26-
options.path.includes("&sig=")
27-
);
28-
}
29-
}
30-
318
export function getConnection(areaId: string, collectionUrl: string): Promise<WebApi> {
329
var accessToken = locationUtility.getSystemAccessToken();
10+
var presignedUrlPatterns: RegExp[] = [
11+
new RegExp('.*blob\.core\.windows\.net.*'), // blobstore redirect
12+
new RegExp('.*vsblob\.vsassets\.io.*') // edge caching enabled blob
13+
];
14+
3315
return locationUtility
3416
.getServiceUriFromAreaId(collectionUrl, accessToken, areaId)
3517
.then(url => {
3618
const options: IRequestOptions = {
3719
proxy: tl.getHttpProxyConfiguration(url),
3820
maxRetries: 5,
39-
allowRetries: true
21+
allowRetries: true,
22+
presignedUrlPatterns: presignedUrlPatterns
4023
};
41-
return new WebApi(url, new BearerHandlerForPresignedUrls(accessToken), options);
24+
return new WebApi(url, new BearerCredentialHandler(accessToken), options);
4225
})
4326
.catch(error => {
4427
throw error;

Tasks/DownloadPackageV1/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"dependencies": {
2020
"@types/mocha": "^2.2.5",
2121
"@types/node": "^6.14.2",
22-
"azure-devops-node-api": "8.0.0",
22+
"azure-devops-node-api": "9.0.1",
2323
"azure-pipelines-task-lib": "2.8.0",
2424
"decompress-zip": "0.3.0",
2525
"packaging-common": "file:../../_build/Tasks/Common/packaging-common-1.0.1.tgz",

Tasks/DownloadPackageV1/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"version": {
1111
"Major": 1,
1212
"Minor": 161,
13-
"Patch": 0
13+
"Patch": 2
1414
},
1515
"demands": [],
1616
"releaseNotes": "Adds support to download Maven, Python, Universal and Npm packages.",

Tasks/DownloadPackageV1/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"version": {
1111
"Major": 1,
1212
"Minor": 161,
13-
"Patch": 0
13+
"Patch": 2
1414
},
1515
"demands": [],
1616
"releaseNotes": "ms-resource:loc.releaseNotes",

0 commit comments

Comments
 (0)