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

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

问题描述

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

解决方案

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

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

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

身体:

<代码>{描述": "",管理员组":空,授权": {参数": {"kubeconfig": "apiVersion: v1种类:配置集群:- 名称:本地簇:insecure-skip-tls-verify: 真服务器:https://192.168.43.66:6443上下文:- 语境:集群:本地用户:管理员名称:kubelet-上下文当前上下文:kubelet 上下文用户:- 姓名:管理员用户:密码:管理员用户名:admin",用户名":管理员",密码":管理员"},"scheme": "用户名密码"},createdBy":空,数据": {"authorizationType": "Kubeconfig","acceptUntrustedCerts": "false"},"name": "{端点名称}","type": "kubernetes","url": "{url}",读者组":空,groupScopeId":空,isReady":假,操作状态":空}

示例 kubeconfig:cni-plugin/kubeconfig.sample

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

MS Docs VSTS Endpoints - Create

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

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

}

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?

I'm running my code via Powershell.

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

thanks

解决方案

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

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

Body:

{

    "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
}

Sample kubeconfig: cni-plugin/kubeconfig.sample

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

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