Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function run() {
cm.banner('Handler Samples');
const username = "";
const password = "";
const workstation = "";
const domain = "";
const url = "";
const basicHandler: hm.BasicCredentialHandler = new hm.BasicCredentialHandler(username, password);
const patHandler: hm.PersonalAccessTokenCredentialHandler = new hm.PersonalAccessTokenCredentialHandler('scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs');
const ntlmHandler: hm.NtlmCredentialHandler = new hm.NtlmCredentialHandler(username, password, workstation, domain);
// These handlers would then be passed to the constructors of the http or rest modules
// const httpClient: httpm.HttpClient = new httpm.HttpClient('vsts-node-api', [ntlmHandler]);
// const response: httpm.HttpClientResponse = await httpClient.get(url);
// console.log("response code: " + response.message.statusCode);
}
export async function run() {
cm.banner('Handler Samples');
const username = "";
const password = "";
const workstation = "";
const domain = "";
const url = "";
const basicHandler: hm.BasicCredentialHandler = new hm.BasicCredentialHandler(username, password);
const patHandler: hm.PersonalAccessTokenCredentialHandler = new hm.PersonalAccessTokenCredentialHandler('scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs');
const ntlmHandler: hm.NtlmCredentialHandler = new hm.NtlmCredentialHandler(username, password, workstation, domain);
// These handlers would then be passed to the constructors of the http or rest modules
// const httpClient: httpm.HttpClient = new httpm.HttpClient('vsts-node-api', [ntlmHandler]);
// const response: httpm.HttpClientResponse = await httpClient.get(url);
// console.log("response code: " + response.message.statusCode);
}
var getTasksToBuildForCI = async function() {
// Returns a list of tasks that have different version numbers than their current published version.
var packageInfo;
try {
var packageToken = process.env['PACKAGE_TOKEN'];
if (!packageToken) {
console.log(`##vso[task.logissue type=warning;sourcepath=ci/filter-task.js;linenumber=21;]Failed to get info from package endpoint because no token was provided. Try setting the PACKAGE_TOKEN environment variable.`);
return makeOptions.tasks;
}
var handler = new httpHandler.PersonalAccessTokenCredentialHandler(packageToken);
var client = new restClient.RestClient('azure-pipelines-tasks-ci', '', [handler]);
var packageEndpoint = process.env['PACKAGE_ENDPOINT'];
if (!packageEndpoint) {
console.log(`##vso[task.logissue type=warning;sourcepath=ci/filter-task.js;linenumber=28;]Failed to get info from package endpoint because no endpoint was specified. Try setting the PACKAGE_ENDPOINT environment variable.`);
return makeOptions.tasks;
}
packageInfo = await client.get(packageEndpoint);
if (packageInfo.statusCode !== 200) {
console.log(`##vso[task.logissue type=warning;sourcepath=ci/filter-task.js;linenumber=33;]Failed to get info from package endpoint, returned with status code ${packageInfo.statusCode}`);
return makeOptions.tasks;
}
}
catch (err) {
// If unable to reach rest client, build everything.
console.log(`##vso[task.logissue type=warning;sourcepath=ci/filter-task.js;linenumber=39;]Failed to get info from package endpoint, client failed with error ${err.message}`);
return makeOptions.tasks;
export async function run() {
cm.banner('Handler Samples');
const username = "";
const password = "";
const workstation = "";
const domain = "";
const url = "";
const basicHandler: hm.BasicCredentialHandler = new hm.BasicCredentialHandler(username, password);
const patHandler: hm.PersonalAccessTokenCredentialHandler = new hm.PersonalAccessTokenCredentialHandler('scbfb44vxzku5l4xgc3qfazn3lpk4awflfryc76esaiq7aypcbhs');
const ntlmHandler: hm.NtlmCredentialHandler = new hm.NtlmCredentialHandler(username, password, workstation, domain);
// These handlers would then be passed to the constructors of the http or rest modules
// const httpClient: httpm.HttpClient = new httpm.HttpClient('vsts-node-api', [ntlmHandler]);
// const response: httpm.HttpClientResponse = await httpClient.get(url);
// console.log("response code: " + response.message.statusCode);
}
async function queryLatestMatch(versionSpec: string): Promise {
//
// Hopefully your tool supports an easy way to get a version list.
// Node offers a json list of versions.
//
let dataFileName: string;
switch (osPlat) {
case "linux": dataFileName = "linux-" + osArch; break;
case "darwin": dataFileName = "osx-" + osArch + '-tar'; break;
case "win32": dataFileName = "win-" + osArch + '-exe'; break;
default: throw new Error(`Unexpected OS '${osPlat}'`);
}
let versions: string[] = [];
let dataUrl = "https://nodejs.org/dist/index.json";
let rest: restm.RestClient = new restm.RestClient('vsts-node-tool');
let nodeVersions: INodeVersion[] = (await rest.get(dataUrl)).result;
nodeVersions.forEach((nodeVersion:INodeVersion) => {
//
// Ensure this version supports your os and platform.
//
if (nodeVersion.files.indexOf(dataFileName) >= 0) {
versions.push(nodeVersion.version);
}
});
//
// If there is no data driven way to get versions supported,
// a last option is to tool.scrape() with a regex.
//
// For example:
// let scrapeUrl = 'https://nodejs.org/dist/';
async function queryLatestMatch(versionSpec: string): Promise {
// node offers a json list of versions
let dataFileName: string;
switch (osPlat) {
case "linux": dataFileName = "linux-" + osArch; break;
case "darwin": dataFileName = "osx-" + osArch + '-tar'; break;
case "win32": dataFileName = "win-" + osArch + '-exe'; break;
default: throw new Error(`Unexpected OS '${osPlat}'`);
}
let versions: string[] = [];
let dataUrl = "https://nodejs.org/dist/index.json";
let rest: restm.RestClient = new restm.RestClient('vsts-node-tool');
let nodeVersions: INodeVersion[] = (await rest.get(dataUrl)).result;
nodeVersions.forEach((nodeVersion:INodeVersion) => {
// ensure this version supports your os and platform
if (nodeVersion.files.indexOf(dataFileName) >= 0) {
versions.push(nodeVersion.version);
}
});
// get the latest version that matches the version spec
let version: string = toolLib.evaluateVersions(versions, versionSpec);
return version;
}
case 'linux':
dataFileName = 'linux-' + osArch;
break;
case 'darwin':
dataFileName = 'osx-' + osArch + '-tar';
break;
case 'win32':
dataFileName = 'win-' + osArch + '-exe';
break;
default:
throw new Error(`Unexpected OS '${osPlat}'`);
}
let versions: string[] = [];
let dataUrl = 'https://nodejs.org/dist/index.json';
let rest: restm.RestClient = new restm.RestClient('vsts-node-tool');
let nodeVersions: INodeVersion[] =
(await rest.get(dataUrl)).result || [];
nodeVersions.forEach((nodeVersion: INodeVersion) => {
// ensure this version supports your os and platform
if (nodeVersion.files.indexOf(dataFileName) >= 0) {
versions.push(nodeVersion.version);
}
});
// get the latest version that matches the version spec
let version: string = evaluateVersions(versions, versionSpec);
return version;
}
export async function downloadCache(
cacheEntry: ArtifactCacheEntry,
archivePath: string
): Promise {
const stream = fs.createWriteStream(archivePath);
const httpClient = new HttpClient("actions/cache");
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const downloadResponse = await httpClient.get(cacheEntry.archiveLocation!);
await pipeResponseToStream(downloadResponse, stream);
}
function createAuthHandlers(artifactoryService) {
let artifactoryUser = tl.getEndpointAuthorizationParameter(artifactoryService, "username", true);
let artifactoryPassword = tl.getEndpointAuthorizationParameter(artifactoryService, "password", true);
let artifactoryAccessToken = tl.getEndpointAuthorizationParameter(artifactoryService, "apitoken", true);
// Check if Artifactory should be accessed using access-token.
if (artifactoryAccessToken) {
return [new clientHandlers.BearerCredentialHandler(artifactoryAccessToken)]
}
// Check if Artifactory should be accessed anonymously.
if (artifactoryUser === "") {
return [];
}
// Use basic authentication.
return [new clientHandlers.BasicCredentialHandler(artifactoryUser, artifactoryPassword)];
}
let artifactoryUser = tl.getEndpointAuthorizationParameter(artifactoryService, "username", true);
let artifactoryPassword = tl.getEndpointAuthorizationParameter(artifactoryService, "password", true);
let artifactoryAccessToken = tl.getEndpointAuthorizationParameter(artifactoryService, "apitoken", true);
// Check if Artifactory should be accessed using access-token.
if (artifactoryAccessToken) {
return [new clientHandlers.BearerCredentialHandler(artifactoryAccessToken)]
}
// Check if Artifactory should be accessed anonymously.
if (artifactoryUser === "") {
return [];
}
// Use basic authentication.
return [new clientHandlers.BasicCredentialHandler(artifactoryUser, artifactoryPassword)];
}