當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript task.getEndpointAuthorization函數代碼示例

本文整理匯總了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);
 }
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:7,代碼來源:registrycredentialfactory.ts

示例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"))
	}
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:9,代碼來源:download.ts

示例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');
    }
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:10,代碼來源:locationUtilities.ts

示例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;
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:51,代碼來源:authentication.ts

示例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);
    }
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:62,代碼來源:runvstest.ts

示例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);
    }
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:63,代碼來源:npmregistry.ts

示例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"));
    }
}
開發者ID:Microsoft,項目名稱:vsts-tasks,代碼行數:101,代碼來源:nugetpublisher.ts


注:本文中的azure-pipelines-task-lib/task.getEndpointAuthorization函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。