github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/_dmctl_tools/check_master_http_apis.go (about)

     1  // Copyright 2020 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package main
    15  
    16  import (
    17  	"fmt"
    18  	"io"
    19  	"net/http"
    20  	"os"
    21  
    22  	toolutils "github.com/pingcap/tidb-tools/pkg/utils"
    23  	"github.com/pingcap/tiflow/dm/tests/utils"
    24  )
    25  
    26  // use show-ddl-locks request to test DM-master is online
    27  func main() {
    28  	addr := os.Args[1]
    29  	sslCA := ""
    30  	sslCert := ""
    31  	sslKey := ""
    32  	transport := http.DefaultTransport.(*http.Transport).Clone()
    33  
    34  	if len(os.Args) == 5 {
    35  		sslCA = os.Args[2]
    36  		sslCert = os.Args[3]
    37  		sslKey = os.Args[4]
    38  
    39  		tls, err := toolutils.NewTLS(sslCA, sslCert, sslKey, "", nil)
    40  		if err != nil {
    41  			utils.ExitWithError(err)
    42  		}
    43  
    44  		tlsCfg := tls.TLSConfig()
    45  		tlsCfg.InsecureSkipVerify = true
    46  		transport.TLSClientConfig = tlsCfg
    47  	}
    48  
    49  	client := &http.Client{Transport: transport}
    50  
    51  	resp, err := client.Get("https://" + addr + "/apis/v1alpha1/members")
    52  	if err != nil {
    53  		utils.ExitWithError(err)
    54  	}
    55  	defer resp.Body.Close()
    56  	body, err := io.ReadAll(resp.Body)
    57  	if err != nil {
    58  		utils.ExitWithError(err)
    59  	}
    60  	fmt.Println(string(body))
    61  }