How to use the artifact-engine/Providers/typed-rest-client/Handlers.PersonalAccessTokenCredentialHandler function in artifact-engine

To help you get started, we’ve selected a few artifact-engine examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / azure-pipelines-tasks / Tasks / DownloadBuildArtifactsV0 / main.ts View on Github external
artifacts.forEach(async function (artifact, index, artifacts) {
                let downloaderOptions = configureDownloaderOptions();

                if (artifact.resource.type.toLowerCase() === "container") {
                    var handler = new webHandlers.PersonalAccessTokenCredentialHandler(accessToken);
                    var isPullRequestFork = tl.getVariable("SYSTEM.PULLREQUEST.ISFORK");
                    var isPullRequestForkBool = isPullRequestFork ? isPullRequestFork.toLowerCase() == 'true' : false;
                    var isWin = process.platform === "win32";
                    var isZipDownloadDisabled = tl.getVariable("SYSTEM.DisableZipDownload");
                    var isZipDownloadDisabledBool = isZipDownloadDisabled ? isZipDownloadDisabled.toLowerCase() != 'false' : false;

                    // Disable zip download if selective itemPattern provided
                    if (downloaderOptions.itemPattern !== "**") {
                        isZipDownloadDisabledBool = true;
                    }

                    if (!isZipDownloadDisabledBool && isWin && isPullRequestForkBool) {
                        const archiveUrl: string = endpointUrl + "/" + projectId + "/_apis/build/builds/" + buildId + "/artifacts?artifactName=" + artifact.name + "&$format=zip";
                        console.log(tl.loc("DownloadArtifacts", artifact.name, archiveUrl));

                        var zipLocation = path.join(downloadPath, artifact.name + ".zip");
github microsoft / azure-pipelines-tasks / Tasks / DownloadBuildArtifacts / main.ts View on Github external
if (artifact.resource.type.toLowerCase() === "container") {
                    let downloader = new engine.ArtifactEngine();
                    var containerParts: string[] = artifact.resource.data.split('/', 3);
                    if (containerParts.length !== 3) {
                        throw new Error(tl.loc("FileContainerInvalidArtifactData"));
                    }

                    var containerId: number = parseInt(containerParts[1]);
                    var containerPath: string = containerParts[2];

                    var itemsUrl = endpointUrl + "/_apis/resources/Containers/" + containerId + "?itemPath=" + encodeURIComponent(containerPath) + "&isShallow=true&api-version=4.1-preview.4";
                    console.log(tl.loc("DownloadArtifacts", itemsUrl));

                    var variables = {};
                    var handler = new webHandlers.PersonalAccessTokenCredentialHandler(accessToken);
                    var webProvider = new providers.WebProvider(itemsUrl, templatePath, variables, handler);
                    var fileSystemProvider = new providers.FilesystemProvider(downloadPath);

                    downloadPromises.push(downloader.processItems(webProvider, fileSystemProvider, downloaderOptions).catch((reason) => {
                        reject(reason);
                    }));
                }
                else if (artifact.resource.type.toLowerCase() === "filepath") {
                    let downloader = new engine.ArtifactEngine();
                    let downloadUrl = artifact.resource.data;
                    let artifactLocation = downloadUrl + '/' + artifact.name;
                    if (!fs.existsSync(artifactLocation)) {
                        console.log(tl.loc("ArtifactNameDirectoryNotFound", artifactLocation, downloadUrl));
                        artifactLocation = downloadUrl;
                    }