本文整理汇总了TypeScript中azure-pipelines-task-lib/task.getEndpointAuthorization函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getEndpointAuthorization函数的具体用法?TypeScript getEndpointAuthorization怎么用?TypeScript getEndpointAuthorization使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getEndpointAuthorization函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: fetchGenericCredential
public static fetchGenericCredential(endpointName: string): RegistryCredential {
if (!endpointName) {
throw Error(`endpointName or registryName is empty when fetching Generic credential`);
}
let registryAuth: any = tl.getEndpointAuthorization(endpointName, true).parameters;
return new RegistryCredential(registryAuth.username, registryAuth.password, registryAuth.registry);
}
示例2: getAuthToken
function getAuthToken() {
var auth = tl.getEndpointAuthorization('SYSTEMVSSCONNECTION', false);
if (auth.scheme.toLowerCase() === 'oauth') {
return auth.parameters['AccessToken'];
}
else {
throw new Error(tl.loc("CredentialsNotFound"))
}
}
示例3: getSystemAccessToken
export function getSystemAccessToken(): string {
tl.debug('Getting credentials for local feeds');
const auth = tl.getEndpointAuthorization('SYSTEMVSSCONNECTION', false);
if (auth.scheme === 'OAuth') {
tl.debug('Got auth token');
return auth.parameters['AccessToken'];
} else {
tl.warning('Could not determine credentials to use');
}
}
示例4: getExternalAuthInfoArray
export async function getExternalAuthInfoArray(inputKey: string): Promise<AuthInfo[]>
{
let externalAuthArray: AuthInfo[] = [];
let endpointNames = tl.getDelimitedInput(inputKey, ",");
if (!endpointNames || endpointNames.length === 0)
{
return externalAuthArray;
}
tl.debug(tl.loc("Info_AddingExternalFeeds", endpointNames.length));
for (let endpointId of endpointNames)
{
let feedUri = tl.getEndpointUrl(endpointId, false);
let endpointName = tl.getEndpointDataParameter(endpointId, "endpointname", false);
let externalAuth = tl.getEndpointAuthorization(endpointId, true);
let scheme = tl.getEndpointAuthorizationScheme(endpointId, true).toLowerCase();
switch(scheme) {
case "token":
const token = externalAuth.parameters["apitoken"];
tl.debug(tl.loc("Info_AddingTokenAuthEntry", feedUri));
externalAuthArray.push(new AuthInfo({
feedName: endpointName,
feedUri,
isInternalSource: false,
} as IPackageSource,
AuthType.Token,
"build", // fake username, could be anything.
token,
));
break;
case "usernamepassword":
let username = externalAuth.parameters["username"];
let password = externalAuth.parameters["password"];
tl.debug(tl.loc("Info_AddingPasswordAuthEntry", feedUri));
externalAuthArray.push(new AuthInfo({
feedName: endpointName,
feedUri,
isInternalSource: false,
} as IPackageSource,
AuthType.UsernamePassword,
username,
password));
break;
case "none":
default:
break;
}
}
return externalAuthArray;
}
示例5: execute
async function execute() {
const taskProps: { [key: string]: string; } = { state: 'started'};
ci.publishEvent(taskProps);
const enableHydra = await isFeatureFlagEnabled(tl.getVariable('System.TeamFoundationCollectionUri'),
'TestExecution.EnableHydra', tl.getEndpointAuthorization('SystemVssConnection', true).parameters.AccessToken);
const enableApiExecution = await isFeatureFlagEnabled(tl.getVariable('System.TeamFoundationCollectionUri'),
'TestExecution.EnableTranslationApi', tl.getEndpointAuthorization('SystemVssConnection', true).parameters.AccessToken);
try {
utils.Helper.setConsoleCodePage();
const blockRun = isMultiConfigOnDemandRun();
if (blockRun) {
tl.setResult(tl.TaskResult.Failed, tl.loc('MultiConfigNotSupportedWithOnDemand'));
}
const serverBasedRun = isServerBasedRun();
inputParser.setIsServerBasedRun(serverBasedRun);
const enableDiagnostics = await isFeatureFlagEnabled(tl.getVariable('System.TeamFoundationCollectionUri'),
'TestExecution.EnableDiagnostics', tl.getEndpointAuthorization('SystemVssConnection', true).parameters.AccessToken);
inputParser.setEnableDiagnosticsSettings(enableDiagnostics);
if (serverBasedRun) {
ci.publishEvent({
runmode: 'distributedtest', parallelism: tl.getVariable('System.ParallelExecutionType'),
testtype: tl.getInput('testSelector')
});
console.log(tl.loc('distributedTestWorkflow'));
console.log('======================================================');
const inputDataContract = inputParser.parseInputsForDistributedTestRun();
console.log('======================================================');
const test = new distributedTest.DistributedTest(inputDataContract);
test.runDistributedTest();
} else {
ci.publishEvent({ runmode: 'nondistributed' });
console.log(tl.loc('nonDistributedTestWorkflow'));
console.log('======================================================');
const inputDataContract = inputParser.parseInputsForNonDistributedTestRun();
if (enableHydra || inputDataContract.EnableSingleAgentAPIFlow || (inputDataContract.ExecutionSettings
&& inputDataContract.ExecutionSettings.RerunSettings
&& inputDataContract.ExecutionSettings.RerunSettings.RerunFailedTests)) {
if (enableApiExecution) {
console.log('================== API Execution =====================');
inputDataContract.ExecutionSettings.TestPlatformExecutionMode = 'api';
}
const test = new nondistributedtest.NonDistributedTest(inputDataContract);
test.runNonDistributedTest();
} else {
localtest.startTest();
}
console.log('======================================================');
}
} catch (error) {
tl.setResult(tl.TaskResult.Failed, error);
taskProps.result = error.message;
}
finally {
taskProps.state = 'completed';
ci.publishEvent(taskProps);
}
}
示例6: FromServiceEndpoint
public static async FromServiceEndpoint(endpointId: string, authOnly?: boolean): Promise<NpmRegistry> {
const lineEnd = os.EOL;
let endpointAuth: tl.EndpointAuthorization;
let url: string;
let nerfed: string;
let auth: string;
let username: string;
let password: string;
let email: string;
let password64: string;
let isVstsTokenAuth: boolean = false;
try {
endpointAuth = tl.getEndpointAuthorization(endpointId, false);
} catch (exception) {
throw new Error(tl.loc('ServiceEndpointNotDefined'));
}
try {
url = NormalizeRegistry(tl.getEndpointUrl(endpointId, false));
// To the reader, this could be optimized here but it is broken out for readability
if (endpointAuth.scheme === 'Token') {
isVstsTokenAuth = await NpmRegistry.isEndpointInternal(url);
}
nerfed = util.toNerfDart(url);
} catch (exception) {
throw new Error(tl.loc('ServiceEndpointUrlNotDefined'));
}
switch (endpointAuth.scheme) {
case 'UsernamePassword':
username = endpointAuth.parameters['username'];
password = endpointAuth.parameters['password'];
email = username; // npm needs an email to be set in order to publish, this is ignored on npmjs
password64 = (new Buffer(password).toString('base64'));
tl.setSecret(password64);
auth = nerfed + ':username=' + username + lineEnd;
auth += nerfed + ':_password=' + password64 + lineEnd;
auth += nerfed + ':email=' + email + lineEnd;
break;
case 'Token':
const apitoken = endpointAuth.parameters['apitoken'];
if (!isVstsTokenAuth){
// Use Bearer auth as it was intended.
auth = nerfed + ':_authToken=' + apitoken + lineEnd;
} else {
// Azure DevOps does not support PATs+Bearer only JWTs+Bearer
email = 'VssEmail';
username = 'VssToken';
password64 = (new Buffer(apitoken).toString('base64'));
tl.setSecret(password64);
auth = nerfed + ':username=' + username + lineEnd;
auth += nerfed + ':_password=' + password64 + lineEnd;
auth += nerfed + ':email=' + email + lineEnd;
}
break;
}
auth += nerfed + ':always-auth=true';
return new NpmRegistry(url, auth, authOnly);
}
示例7: main
//.........这里部分代码省略.........
versionToUse = "4.0.0";
}
else if (nugetUxOption === "3.5.0.1829") {
nuGetPathSuffix = "NuGet/3.5.0/";
versionToUse = "3.5.0";
}
else if (nugetUxOption === "3.3.0") {
nuGetPathSuffix = "NuGet/3.3.0/";
versionToUse = "3.3.0";
}
else {
throw new Error(tl.loc("NGCommon_UnabletoDetectNuGetVersion"));
}
// save and reset the tool path env var, so this task doesn't act as a tool installer
const tempNuGetPath = tl.getVariable(ngToolGetter.NUGET_EXE_TOOL_PATH_ENV_VAR);
const cachedVersion = await ngToolGetter.cacheBundledNuGet(versionToUse, nuGetPathSuffix);
nuGetPath = await ngToolGetter.getNuGet(cachedVersion);
tl.setVariable(ngToolGetter.NUGET_EXE_TOOL_PATH_ENV_VAR, tempNuGetPath);
}
//find nuget location to use
let credProviderPath = nutil.locateCredentialProvider();
const quirks = await ngToolRunner.getNuGetQuirksAsync(nuGetPath);
// clauses ordered in this way to avoid short-circuit evaluation, so the debug info printed by the functions
// is unconditionally displayed
const useCredProvider = ngToolRunner.isCredentialProviderEnabled(quirks) && credProviderPath;
const useCredConfig = ngToolRunner.isCredentialConfigEnabled(quirks) && !useCredProvider;
let accessToken = pkgLocationUtils.getSystemAccessToken();
let urlPrefixes = packagingLocation.PackagingUris;
tl.debug(`discovered URL prefixes: ${urlPrefixes}`);
// Note to readers: This variable will be going away once we have a fix for the location service for
// customers behind proxies
let testPrefixes = tl.getVariable("NuGetTasks.ExtraUrlPrefixesForTesting");
if (testPrefixes) {
urlPrefixes = urlPrefixes.concat(testPrefixes.split(";"));
tl.debug(`all URL prefixes: ${urlPrefixes}`);
}
const authInfo = new auth.NuGetAuthInfo(urlPrefixes, accessToken);
let environmentSettings: ngToolRunner.NuGetEnvironmentSettings = {
authInfo: authInfo,
credProviderFolder: useCredProvider ? path.dirname(credProviderPath) : null,
extensionsDisabled: !userNuGetProvided
}
let configFile = null;
let apiKey: string;
let feedUri: string;
let credCleanup = () => { return };
if (nuGetFeedType == "internal") {
if (useCredConfig) {
let nuGetConfigHelper = new NuGetConfigHelper(nuGetPath, null, authInfo, environmentSettings);
nuGetConfigHelper.setSources([{ feedName: "internalFeed", feedUri: internalFeedUri }], true);
configFile = nuGetConfigHelper.tempNugetConfigPath;
credCleanup = () => tl.rmRF(nuGetConfigHelper.tempNugetConfigPath);
}
apiKey = "VSTS";
feedUri = internalFeedUri;
}
else {
feedUri = tl.getEndpointUrl(connectedServiceName, false);
let externalAuth = tl.getEndpointAuthorization(connectedServiceName, false);
apiKey = externalAuth.parameters["password"];
}
try {
let publishOptions = new PublishOptions(
nuGetPath,
feedUri,
apiKey,
configFile,
verbosity,
nuGetAdditionalArgs,
environmentSettings);
for (const packageFile of filesList) {
await publishPackageAsync(packageFile, publishOptions);
}
} finally {
credCleanup();
}
tl.setResult(tl.TaskResult.Succeeded, tl.loc("PackagesPublishedSuccessfully"));
} catch (err) {
tl.error(err);
if (buildIdentityDisplayName || buildIdentityAccount) {
tl.warning(tl.loc("BuildIdentityPermissionsHint", buildIdentityDisplayName, buildIdentityAccount));
}
tl.setResult(tl.TaskResult.Failed, tl.loc("PackagesFailedToPublish"));
}
}