从javascript访问VSTS服务端点 [英] Accessing VSTS service endpoints from javascript

查看:91
本文介绍了从javascript访问VSTS服务端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用扩展代码访问服务端点设置.

I am trying to access the service endpoint setup in my extension code.

扩展名如下:

{
  "manifestVersion": 1,
  "id": "vsts-extensions-myExtensions",
  "version": "0.5.1",
  "name": "xxx Projects Time Entry",
  "description": "Record time spent in xxx Projects",
  "publisher": "xxx",
  "targets": [
    {
      "id": "Microsoft.VisualStudio.Services"
    }
  ],
  "icons": {
    "default": "img/logo.png"
  },
  "contributions": 
  [
    {
      "id": "xxTimeEntry",
      "type": "ms.vss-dashboards-web.widget",
...
    },

    {
      "id": "service-endpoint",
      "description": "Service Endpoint type for xx connections",
      "type": "ms.vss-endpoint.service-endpoint-type",
      "targets": [ "ms.vss-endpoint.endpoint-types" ],
      "properties": {
        "name": "xxxyyy",
        "displayName": "xx server connection",
        "url": {
          "displayName": "Server Url",
          "helpText": "Url for the xxx server to connect to."
        },
        "dataSources": [
          {
            "name": "xxx Projects",
            "endpointUrl": "{{endpoint.url}}api/timesheetwidgetprojects",
            "resultSelector": "jsonpath:$[*].nm"
          }
        ],
        "authenticationSchemes": [
          {
            "type": "ms.vss-endpoint.endpoint-auth-scheme-basic",
            "inputDescriptors": [
              {
                "id": "username",
                "name": "Username",
                "description": "Username",
                "inputMode": "textbox",
                "validation": {
                  "isRequired": false,
                  "dataType": "string"
                }
              },
              {
                "id": "password",
                "name": "Password",
                "description": "Password",
                "inputMode": "passwordbox",
                "isConfidential": true,
                "validation": {
                  "isRequired": false,
                  "dataType": "string"
                }
              }
            ]
          }
        ]
      }
    }
  ],
...

访问服务端点的代码如下:

The code to access the service endpoint is something like :

VSS.require(["VSS/Service", "VSS/WebApi/RestClient"],
   function (VSS_Service, RestClient) {
       var webContext = VSS.getWebContext();
       var client = VSS_Service.getCollectionClient(DistributedTask.TaskAgentRestClient);
       client.getServiceEndpoints(webContext.project.id).then(
           function (endpoints) {
               alert('endpoints')
           }
       );
   }
);

但是我不使用任务,只是将端点存储在主vss-extension.json中.

however I am not using a task and just have my endpoint in the main vss-extension.json.

有什么想法吗?

谢谢 马丁

推荐答案

基于

Based on the supported scopes, there isn’t the scope for service endpoint, so you can’t do it.

我在此处提交用户声音:

I submit a user voice here: VSTS extension service endpoint scope, you can vote and follow up.

解决方法是您可以通过个人访问令牌.

The workaround is that you can call REST API by using JS code with Personal Access Token in your extension.

调用REST API的简单代码:

Simple code to call REST API:

 $.ajax({
            url: 'https://fabrikam.visualstudio.com/defaultcollection/_apis/projects?api-version=1.0',
            dataType: 'json',
            headers: {
                'Authorization': 'Basic ' + btoa("" + ":" + myPatToken)
            }
        }).done(function( results ) {
            console.log( results.value[0].id + " " + results.value[0].name );
        });

这篇关于从javascript访问VSTS服务端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆