Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed DownloadPackageV0 task to be able to download AFD enabled packages #11897

Merged
merged 1 commit into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we removing this check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the updated library for this task that uses Regex to match the urls. The regex using just the hostname works as well, and its too complicated with additional options.

);
}
}

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though you already made this 161.2? shouldn't this be more than that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is DownloadPackageV0. The 161.2 was for DownloadPackageV1

"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"
}
}
}