Skip to content

Commit

Permalink
Fixed DownloadPackageV0 task to be able to download AFD enabled packa…
Browse files Browse the repository at this point in the history
…ges (#11897)
  • Loading branch information
aasim authored Dec 4, 2019
1 parent ee3e666 commit f36e3fc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 28 deletions.
33 changes: 8 additions & 25 deletions Tasks/DownloadPackageV0/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,22 @@ import { IRequestOptions } from "azure-devops-node-api/interfaces/common/VsoBase
import * as tl from 'vsts-task-lib/task';
import * as locationUtility from "packaging-common/locationUtilities";

// TODO Remove this once this bug is resolved: https://github.com/Microsoft/typed-rest-client/issues/126
export class BearerHandlerForPresignedUrls extends BearerCredentialHandler {
prepareRequest(options) {
// If we have a presigned blobstore url, don't add auth header
if (this.isPreSignedUrl(options)) {
delete options.headers["Authorization"];
delete options.headers["X-TFS-FedAuthRedirect"];
} else {
options.headers["Authorization"] = "Bearer " + this.token;
options.headers["X-TFS-FedAuthRedirect"] = "Suppress";
}
}

isPreSignedUrl(options: any): boolean {
return (
options.host &&
options.host.endsWith("blob.core.windows.net") &&
options.path &&
options.path.includes("&sig=")
);
}
}

export function getConnection(areaId: string, collectionUrl: string, accessToken: string): Promise<WebApi> {
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
allowRetries: true,
presignedUrlPatterns: presignedUrlPatterns
};
return new WebApi(url, new BearerHandlerForPresignedUrls(accessToken), options);
return new WebApi(url, new BearerCredentialHandler(accessToken), options);
})
.catch(error => {
throw error;
Expand Down
1 change: 1 addition & 0 deletions Tasks/DownloadPackageV0/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"homepage": "https://github.com/Microsoft/azure-pipelines-tasks#readme",
"dependencies": {
"@types/node": "^6.14.2",
"azure-devops-node-api": "9.0.1",
"azure-pipelines-task-lib": "2.8.0",
"decompress-zip": "0.3.0",
"packaging-common": "file:../../_build/Tasks/Common/packaging-common-1.0.1.tgz",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DownloadPackageV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"version": {
"Major": 0,
"Minor": 161,
"Patch": 0
"Patch": 1
},
"demands": [],
"minimumAgentVersion": "1.99.0",
Expand Down
4 changes: 2 additions & 2 deletions Tasks/DownloadPackageV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"version": {
"Major": 0,
"Minor": 161,
"Patch": 0
"Patch": 1
},
"demands": [],
"minimumAgentVersion": "1.99.0",
Expand Down Expand Up @@ -107,4 +107,4 @@
"OperationFailed": "ms-resource:loc.messages.OperationFailed",
"UnsupportedProjectScopedFeeds": "ms-resource:loc.messages.UnsupportedProjectScopedFeeds"
}
}
}

0 comments on commit f36e3fc

Please sign in to comment.