-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmdConnectorUpdate.go
45 lines (40 loc) · 914 Bytes
/
cmdConnectorUpdate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"log"
"fmt"
"bytes"
"net/http"
"encoding/json"
"github.com/spf13/cobra"
)
var cmdConnectorUpdate = &cobra.Command{
Use: "update [name] [file(.json|.properties)]",
Short: "Update connector",
Run: func(cmd *cobra.Command, args []string) {
if len(args) <= 1{
fmt.Println(cmd.Use)
return
}
name, filename := args[0], args[1]
url := GetKafkaConnectUrl("connectors", name, "config")
config, err := GetConfigFromFile(name, filename)
if err != nil {
log.Fatal(err)
return
}
jsonBytes, _ := json.Marshal(&config.Config)
req, err := http.NewRequest("PUT", url, bytes.NewBuffer(jsonBytes))
if err != nil {
log.Fatal(err)
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Accept", "application/json")
resp, err := httpClient.Do(req)
if err != nil {
log.Fatal(err)
return
}
HandleResponse(resp)
},
}