mirror of
https://github.com/xcat2/confluent.git
synced 2026-09-14 10:13:49 +00:00
Have a draft apiclient in golang
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
module confluentapiclient
|
||||
|
||||
go 1.22
|
||||
|
||||
toolchain go1.23.6
|
||||
@@ -0,0 +1,4 @@
|
||||
github.com/go-crypt/crypt v0.3.2 h1:I4i0u2g8X9bxCXIjvv19BDVXqQbddDQrURCJrOyyJos=
|
||||
github.com/go-crypt/crypt v0.3.2/go.mod h1:U0YhpCizEtaVC4gVfUUN0qGn1Z6+e3at+B5uLYx/sV0=
|
||||
github.com/go-crypt/x v0.3.2 h1:m2wn2+8tp28V4yDiW5NSTiyNSXnCoTs1R1+H+cAJA3M=
|
||||
github.com/go-crypt/x v0.3.2/go.mod h1:uelN9rbD2e2eqE8KA26B9R6OQ0TdM6msWdPsoMM1ZFk=
|
||||
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"net/http"
|
||||
"crypto/x509"
|
||||
"crypto/tls"
|
||||
)
|
||||
|
||||
func main() {
|
||||
certauthority := flag.String("c", "/etc/confluent/ca.pem", "Certificate authorities to use, in PEM format")
|
||||
targurl := flag.String("u", "", "Url to connect to")
|
||||
keyfile := flag.String("k", "/etc/confluent/confluent.apikey", "Confluent API key file")
|
||||
nodename := flag.String("n", "", "Node Name")
|
||||
usejson := flag.Bool("j", false, "Use JSON")
|
||||
flag.Parse()
|
||||
certpool := x509.NewCertPool()
|
||||
currcacerts, err := os.ReadFile(*certauthority)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
confluentapikey, err := os.ReadFile(*keyfile)
|
||||
if confluentapikey[len(confluentapikey) - 1] == 0xa {
|
||||
confluentapikey = confluentapikey[:len(confluentapikey)-1]
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
certpool.AppendCertsFromPEM(currcacerts)
|
||||
|
||||
client := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
RootCAs: certpool,
|
||||
},
|
||||
},
|
||||
}
|
||||
rq, err := http.NewRequest(http.MethodGet, *targurl, nil)
|
||||
if err != nil { panic(err )}
|
||||
if *usejson { rq.Header.Set("Accept", "application/json") }
|
||||
if *nodename == "" {
|
||||
*nodename, err = os.Hostname()
|
||||
}
|
||||
rq.Header.Set("CONFLUENT_NODENAME", *nodename)
|
||||
fmt.Println(string(confluentapikey))
|
||||
rq.Header.Set("CONFLUENT_APIKEY", string(confluentapikey))
|
||||
if err != nil { panic(err )}
|
||||
rsp, err := client.Do(rq)
|
||||
if err != nil { panic(err )}
|
||||
rspdata, err := io.ReadAll(rsp.Body)
|
||||
rsptxt := string(rspdata)
|
||||
fmt.Println(rsptxt)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user