VSTS通过API创建服务连接

问题描述 投票:0回答:1

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

MS Docs VSTS Endpoints - Create

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

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

它是一个已提交的POST请求,并且下面的json有效负载已添加到正文并使用content-type:application / json进行提交。

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

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

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

{
"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有效负载中,应该使用哪个字段?

我通过Powershell运行我的代码。

为了清楚起见,我成功地运行了大量的GET请求,因此能够通过api成功访问我们的项目。这是关于POST请求有效载荷格式的更多问题

谢谢

Add service connection via a browser

azure-devops
1个回答
2
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.