Commit 7e310ee2 authored by Xiaowu Zhang's avatar Xiaowu Zhang

plugin: use certificate instead of user/password

parent c5f4e4dd
......@@ -10,8 +10,8 @@
name fluentbit_wendelin
match *
streamtool_uri %WENDELIN_URL%
user %WENDELIN_USER%
password %WENDELIN_PWD%
key %KEY%
certificate %CERTIFICATE%
buffer_type memory
flush_interval 60s
disable_retry_limit true
......
......@@ -22,16 +22,16 @@ func FLBPluginRegister(def unsafe.Pointer) int {
// plugin (context) pointer to fluentbit context (state/ c code)
func FLBPluginInit(plugin unsafe.Pointer) int {
streamtool_uri := output.FLBPluginConfigKey(plugin, "streamtool_uri")
user := output.FLBPluginConfigKey(plugin, "user")
password := output.FLBPluginConfigKey(plugin, "password")
key := output.FLBPluginConfigKey(plugin, "key")
certificate := output.FLBPluginConfigKey(plugin, "certificate")
buffer_type := output.FLBPluginConfigKey(plugin, "buffer_type")
flush_interval := output.FLBPluginConfigKey(plugin, "flush_interval")
disable_retry_limit := output.FLBPluginConfigKey(plugin, "disable_retry_limit")
reference := output.FLBPluginConfigKey(plugin, "reference")
dict := map[string]string{
"streamtool_uri": streamtool_uri,
"user": user,
"password": password,
"key": key,
"certificate": certificate,
"buffer_type": buffer_type,
"flush_interval": flush_interval,
"disable_retry_limit": disable_retry_limit,
......@@ -81,10 +81,17 @@ func FLBPluginFlushCtx(ctx, data unsafe.Pointer, length C.int, tag *C.char) int
//body result
// content type "application/octet-stream"
var b = []byte(result)
uri := fmt.Sprintf("%s/ingest?reference=%s", dict["streamtool_uri"], dict["reference"])
cert, err := tls.LoadX509KeyPair(dict["certificate"], dict["key"])
if err != nil {
fmt.Fprintf(os.Stderr, "server: loadkey %s", err.Error())
}
uri := fmt.Sprintf("%s/uploadComputerFileMetadata?reference=%s", dict["streamtool_uri"], dict["reference"])
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
Certificates: []tls.Certificate{cert},
},
},
}
req, err := http.NewRequest("POST", uri, bytes.NewReader(b))
......@@ -92,7 +99,6 @@ func FLBPluginFlushCtx(ctx, data unsafe.Pointer, length C.int, tag *C.char) int
fmt.Fprintf(os.Stderr, "Got error %s", err.Error())
return output.FLB_RETRY
}
req.SetBasicAuth(dict["user"], dict["password"])
req.Header.Set("Content-Type", "application/octet-stream")
rsp, err := client.Do(req)
if err != nil {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment