VSTS通过API创建服务连接 [英] VSTS create service connection via API

查看:83
本文介绍了VSTS通过API创建服务连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Azure DevOps API创建服务连接.这是我正在使用的参考:

I'm trying to create a service connection using the Azure DevOps API. This is the reference I'm using:

MS Docs VSTS端点-创建

我已使用指定的此地址类型来构建请求:

I've build the request using this address type as specified:

https://dev .azure.com/organization/project/_apis/serviceendpoint/endpoints?api-version = 5.0-preview.2

这是一个已提交的POST请求,下面的json有效负载已添加到正文中,并使用内容类型application/json进行提交.

It is a POST request that has been submitted and the json payload below has been added to the body and submission made with content-type: application/json.

由于某些原因,我收到以下错误:

For some reason I'm receiving the following error:

The remote server returned an error: (400) Bad Request.

此错误没有具体细节,因此很难知道导致该错误的原因.

There's no specific details with this error, so it's very difficult to know what is causing the error.

{
"data": {
    "authorizationtype": "kubeconfig",
    "acceptUntrustedCerts": "true"
},
"name": "AKS1",
"id": "bbdb1f31-e6cf-4806-ba75-58ae5b52c920",
"type": "kubernetes",
"url": "https://serviceaddress.azmk8s.io",
"authorization": {
    "parameters": {
        "generatePfx": true
    },
    "acceptUntrustedCerts": true,
    "scheme": "none"
},
"isReady": true

}

另外,另一个问题是,文档中没有说明如何或应使用哪个字段将kubeconfig yaml授权数据添加到请求中(请参见下面突出显示的图像).应该如何将其添加到json有效负载中,应使用哪个字段?

Also, another question, the documentation doesn't say how or which field should be used to add the kubeconfig yaml authorization data to the request (see below in the image as highlighted). How should this be added to the json payload, which field should be used?

我正在通过Powershell运行我的代码.

I'm running my code via Powershell.

请注意,我已经成功运行了GET请求,因此能够通过api成功访问我们的项目.这更多是关于POST请求有效负载格式的问题

Just to be clear, I have managed to run a load of GET requests successfully, so am able to access our project via the api successfully. This is more a question about POST request payload formats

谢谢

推荐答案

检查详细请求的简单方法是捕获手动创建目标服务端点(Fiddler或F12开发人员工具)的实际请求

The simple way to check the detail request is capture the actual request of creating target service endpoint manually (Fiddler or F12 developer tool)

创建kubernetes服务端点的示例REST API:

The sample REST API to create kubernetes service endpoint:

Post https://dev.azure.com/{organization}/{project}/_apis/serviceendpoint/endpoints?api-version=5.0-preview.2

身体:

{

    "description": "",
    "administratorsGroup": null,
    "authorization": {
        "parameters": {
            "kubeconfig": "apiVersion: v1
kind: Config
clusters:
- name: local
  cluster:
    insecure-skip-tls-verify: true
    server: https://192.168.43.66:6443
contexts:
- context:
    cluster: local
    user: admin
  name: kubelet-context
current-context: kubelet-context
users:
- name: admin
  user:
    password: admin
    username: admin",
            "username": "admin",
            "password": "admin"
        },
        "scheme": "UsernamePassword"
    },
    "createdBy": null,
    "data": {
        "authorizationType": "Kubeconfig",
        "acceptUntrustedCerts": "false"
    },
    "name": "{endpoint name}",
    "type": "kubernetes",
    "url": "{url}",
    "readersGroup": null,
    "groupScopeId": null,
    "isReady": false,
    "operationStatus": null
}

样本kubeconfig: cni-plugin/kubeconfig.sample

Sample kubeconfig: cni-plugin/kubeconfig.sample

这篇关于VSTS通过API创建服务连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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