当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript locationUtilities.getSystemAccessToken函数代码示例

本文整理汇总了TypeScript中utility-common/packaging/locationUtilities.getSystemAccessToken函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getSystemAccessToken函数的具体用法?TypeScript getSystemAccessToken怎么用?TypeScript getSystemAccessToken使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getSystemAccessToken函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: getWebApiWithProxy

function getWebApiWithProxy(serviceUri: string, accessToken?: string): vsts.WebApi {
    if (!accessToken) {
        accessToken = pkgLocationUtils.getSystemAccessToken();
    }

    const credentialHandler = vsts.getBasicHandler("vsts", accessToken);
    const options: IRequestOptions = {
        proxy: tl.getHttpProxyConfiguration(serviceUri),
    };
    return new vsts.WebApi(serviceUri, credentialHandler, options);
}
开发者ID:shubham90,项目名称:vsts-tasks,代码行数:11,代码来源:ArtifactToolUtilities.ts

示例2: main

async function main(): Promise<void> {
    tl.setResourcePath(path.join(__dirname, "task.json"));

    // Getting artifact tool
    tl.debug("Getting artifact tool");
    let artifactToolPath: string;

    try {
        const localAccessToken = pkgLocationUtils.getSystemAccessToken();
        const serviceUri = tl.getEndpointUrl("SYSTEMVSSCONNECTION", false);
        const blobUri = await pkgLocationUtils.getBlobstoreUriFromBaseServiceUri(
            serviceUri,
            localAccessToken);

        // Finding the artifact tool directory
        artifactToolPath = await artifactToolUtilities.getArtifactToolFromService(
            blobUri,
            localAccessToken,
            "artifacttool");
    }
    catch (error) {
        tl.setResult(tl.TaskResult.Failed, error.message);
        return;
    } finally{
        _logUniversalStartupVariables(artifactToolPath);
    }

    // Calling the command. download/publish
    const universalPackageCommand = tl.getInput("command", true);
    switch (universalPackageCommand) {
        case "download":
            universalDownload.run(artifactToolPath);
            break;
        case "publish":
            universalPublish.run(artifactToolPath);
            break;
        default:
            tl.setResult(tl.TaskResult.Failed, tl.loc("Error_CommandNotRecognized", universalPackageCommand));
            break;
    }
}
开发者ID:shubham90,项目名称:vsts-tasks,代码行数:41,代码来源:universalmain.ts

示例3: getInternalAuthInfoArray

export async function getInternalAuthInfoArray(inputKey: string): Promise<AuthInfo[]> {
    let internalAuthArray: AuthInfo[] = [];
    const feedList  = tl.getDelimitedInput(inputKey, ",");
    if (!feedList || feedList.length === 0)
    {
        return internalAuthArray;
    }
    tl.debug(tl.loc("Info_AddingInternalFeeds", feedList.length));

    let packagingLocation: string;
    const serviceUri = tl.getEndpointUrl("SYSTEMVSSCONNECTION", false);
    const localAccessToken = pkgLocationUtils.getSystemAccessToken();
    try {
        // This call is to get the packaging URI(abc.pkgs.vs.com) which is same for all protocols.
        packagingLocation = await pkgLocationUtils.getNuGetUriFromBaseServiceUri(
            serviceUri,
            localAccessToken);
    } catch (error) {
        tl.debug(tl.loc("FailedToGetPackagingUri"));
        tl.debug(JSON.stringify(error));
        packagingLocation = serviceUri;
    }
    const globalWebApi = utils.getWebApi(packagingLocation, localAccessToken);
    internalAuthArray = await Promise.all(feedList.map(async (feedName: string) => {
        const feedUri = await utils.getPyPiUploadApiFromFeedName(globalWebApi, feedName);
        return new AuthInfo({
            feedName,
            feedUri,
            isInternalSource: true,
            } as IPackageSource,
            AuthType.Token,
            "build",
            localAccessToken,
        );
    }));

    return internalAuthArray;
}
开发者ID:shubham90,项目名称:vsts-tasks,代码行数:38,代码来源:authentication.ts

示例4: run

export async function run(artifactToolPath: string): Promise<void> {
    let buildIdentityDisplayName: string = null;
    let buildIdentityAccount: string = null;
    try {
        // Get directory to publish
        let downloadDir: string = tl.getInput("downloadDirectory");
        if (downloadDir.length < 1)
        {
            tl.warning(tl.loc("Info_DownloadDirectoryNotFound"));
            return;
        }

        let serviceUri: string;
        let feedId: string;
        let packageName: string;
        let version: string;

        // Feed Auth
        let feedType = tl.getInput("internalOrExternalDownload") || "internal";

        const normalizedFeedType = ["internal", "external"].find((x) =>
            feedType.toUpperCase() === x.toUpperCase());
        if (!normalizedFeedType) {
            throw new Error(tl.loc("UnknownFeedType", feedType));
        }
        feedType = normalizedFeedType;

        let internalAuthInfo: auth.InternalAuthInfo;

        let toolRunnerOptions = artifactToolRunner.getOptions();

        if (feedType === "internal")
        {
            // getting inputs
            serviceUri = tl.getEndpointUrl("SYSTEMVSSCONNECTION", false);

            feedId = tl.getInput("feedListDownload");

            // Getting package name from package Id
            const packageId = tl.getInput("packageListDownload");
            const accessToken = pkgLocationUtils.getSystemAccessToken();

            internalAuthInfo = new auth.InternalAuthInfo([], accessToken);

            const feedUri = await pkgLocationUtils.getFeedUriFromBaseServiceUri(serviceUri, accessToken);
            packageName = await artifactToolUtilities.getPackageNameFromId(feedUri, accessToken, feedId, packageId);

            version = tl.getInput("versionListDownload");

            toolRunnerOptions.env.UNIVERSAL_DOWNLOAD_PAT = internalAuthInfo.accessToken;
        }
        else {
            let externalAuthInfo = auth.GetExternalAuthInfo("externalEndpoint");

            if (!externalAuthInfo)
            {
                tl.setResult(tl.TaskResult.Failed, tl.loc("Error_NoSourceSpecifiedForDownload"));
                return;
            }

            serviceUri = externalAuthInfo.packageSource.accountUrl;
            feedId = tl.getInput("feedDownloadExternal");
            packageName = tl.getInput("packageDownloadExternal");
            version = tl.getInput("versionDownloadExternal");

            // Assuming only auth via PAT works for now
            const tokenAuth = externalAuthInfo as auth.TokenExternalAuthInfo;
            toolRunnerOptions.env.UNIVERSAL_DOWNLOAD_PAT = tokenAuth.token;
        }

        tl.debug(tl.loc("Info_UsingArtifactToolDownload"));

        const downloadOptions = {
            artifactToolPath,
            feedId,
            accountUrl: serviceUri,
            packageName,
            packageVersion: version,
        } as artifactToolRunner.IArtifactToolOptions;

        downloadPackageUsingArtifactTool(downloadDir, downloadOptions, toolRunnerOptions);

        tl.setResult(tl.TaskResult.Succeeded, tl.loc("PackagesDownloadedSuccessfully"));

    } catch (err) {
        tl.error(err);

        if (buildIdentityDisplayName || buildIdentityAccount) {
            tl.warning(tl.loc("BuildIdentityPermissionsHint", buildIdentityDisplayName, buildIdentityAccount));
        }

        tl.setResult(tl.TaskResult.Failed, tl.loc("PackagesFailedToDownload"));
    }
}
开发者ID:shubham90,项目名称:vsts-tasks,代码行数:94,代码来源:universaldownload.ts

示例5: run

export async function run(artifactToolPath: string): Promise<void> {
    let buildIdentityDisplayName: string = null;
    let buildIdentityAccount: string = null;
    try {
        // Get directory to publish
        let publishDir: string = tl.getInput("publishDirectory");
        if (publishDir.length < 1)
        {
            tl.debug(tl.loc("Info_PublishDirectoryNotFound"));
            return;
        }

        let serviceUri: string;
        let feedId: string;
        let packageName: string;
        let version: string;
        let accessToken: string;
        let feedUri: string;
        const versionRadio = tl.getInput("versionPublishSelector");

        // Feed Auth
        let feedType = tl.getInput("internalOrExternalPublish") || "internal";

        const normalizedFeedType = ["internal", "external"].find((x) =>
            feedType.toUpperCase() === x.toUpperCase());
        if (!normalizedFeedType) {
            throw new Error(tl.loc("UnknownFeedType", feedType));
        }
        feedType = normalizedFeedType;

        let internalAuthInfo: auth.InternalAuthInfo;

        let toolRunnerOptions = artifactToolRunner.getOptions();

        if (feedType === "internal")
        {
            // getting inputs
            serviceUri = tl.getEndpointUrl("SYSTEMVSSCONNECTION", false);

            packageName = tl.getInput("packageListPublish");
            feedId = tl.getInput("feedListPublish");
            // Setting up auth info
            accessToken = pkgLocationUtils.getSystemAccessToken();
            internalAuthInfo = new auth.InternalAuthInfo([], accessToken);

            toolRunnerOptions.env.UNIVERSAL_PUBLISH_PAT = internalAuthInfo.accessToken;
        }
        else {
            const externalAuthInfo = auth.GetExternalAuthInfo("externalEndpoints");
            if (!externalAuthInfo)
            {
                tl.setResult(tl.TaskResult.Failed, tl.loc("Error_NoSourceSpecifiedForPublish"));
                return;
            }

            serviceUri = externalAuthInfo.packageSource.accountUrl;

            feedId = tl.getInput("feedPublishExternal");
            packageName = tl.getInput("packagePublishExternal");

            // Assuming only auth via PAT works for now
            accessToken = (externalAuthInfo as auth.TokenExternalAuthInfo).token;
            toolRunnerOptions.env.UNIVERSAL_PUBLISH_PAT = accessToken;
        }

        if (versionRadio === "custom"){
            version = tl.getInput("versionPublish");
        }
        else{
            feedUri = await pkgLocationUtils.getFeedUriFromBaseServiceUri(serviceUri, accessToken);

            let highestVersion = await artifactToolUtilities.getHighestPackageVersionFromFeed(feedUri, accessToken, feedId, packageName);

            version = artifactToolUtilities.getVersionUtility(tl.getInput("versionPublishSelector"), highestVersion);
        }
        tl.debug(tl.loc("Info_UsingArtifactToolPublish"));

        // tslint:disable-next-line:no-object-literal-type-assertion
        const publishOptions = {
            artifactToolPath,
            feedId,
            accountUrl: serviceUri,
            packageName,
            packageVersion: version,
        } as artifactToolRunner.IArtifactToolOptions;

        publishPackageUsingArtifactTool(publishDir, publishOptions, toolRunnerOptions);

        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:shubham90,项目名称:vsts-tasks,代码行数:99,代码来源:universalpublish.ts

示例6: main

async function main(): Promise<void> {
    tl.setResourcePath(path.join(__dirname, "task.json"));

    try {
        let packagingLocation: string;

        let pipEnvVar: string = "";
        if (tl.getVariable("PIP_EXTRA_INDEX_URL")) {
            pipEnvVar = tl.getVariable("PIP_EXTRA_INDEX_URL");
        }

        const feedIds  = tl.getDelimitedInput("feedList", ",");

        // Local feeds
        if (feedIds)
        {
            tl.debug(tl.loc("Info_AddingInternalFeeds", feedIds.length));
            const serviceUri = tl.getEndpointUrl("SYSTEMVSSCONNECTION", false);
            const localAccessToken = pkgLocationUtils.getSystemAccessToken();
            try {
                // This call is to get the packaging URI(abc.pkgs.vs.com) which is same for all protocols.
                packagingLocation = await pkgLocationUtils.getNuGetUriFromBaseServiceUri(
                    serviceUri,
                    localAccessToken);
            } catch (error) {
                tl.debug(tl.loc("FailedToGetPackagingUri"));
                tl.debug(JSON.stringify(error));
                packagingLocation = serviceUri;
            }
            const globalWebApi = utils.getWebApi(packagingLocation, localAccessToken);
            for (const feedId of feedIds) {
                const feedUri = await utils.getPyPiSimpleApiFromFeedId(globalWebApi, feedId);
                const pipUri = utils.formPipCompatibleUri("build", localAccessToken, feedUri);
                pipEnvVar = pipEnvVar + " " + pipUri;
            }
        }

        // external service endpoints
        let endpointNames = tl.getDelimitedInput("externalSources", ',');

        const externalEndpoints = auth.getExternalAuthInfoArray(endpointNames);
        externalEndpoints.forEach((id) => {
            const externalPipUri = utils.formPipCompatibleUri(id.username, id.password, id.packageSource.feedUri);
            pipEnvVar = pipEnvVar + " " + externalPipUri;
        });

        // Setting variable
        tl.setVariable("PIP_EXTRA_INDEX_URL", pipEnvVar, false);
        console.log(tl.loc("Info_SuccessAddingAuth", feedIds.length, externalEndpoints.length));

        const pipauthvar = tl.getVariable("PIP_EXTRA_INDEX_URL");
        if (pipauthvar.length < pipEnvVar.length){
            tl.warning(tl.loc("Warn_TooManyFeedEntries"));
        }
        tl.debug(pipEnvVar);
    }
    catch (error) {
        tl.error(error);
        tl.setResult(tl.TaskResult.Failed, tl.loc("FailedToAddAuthentication"));
        return;
    } finally{
        _logPipAuthStartupVariables();
    }
}
开发者ID:shubham90,项目名称:vsts-tasks,代码行数:64,代码来源:pipauthenticatemain.ts


注:本文中的utility-common/packaging/locationUtilities.getSystemAccessToken函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。