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

plugin: use certificate instead of user/password

parent c5f4e4dd
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
name fluentbit_wendelin name fluentbit_wendelin
match * match *
streamtool_uri %WENDELIN_URL% streamtool_uri %WENDELIN_URL%
user %WENDELIN_USER% key %KEY%
password %WENDELIN_PWD% certificate %CERTIFICATE%
buffer_type memory buffer_type memory
flush_interval 60s flush_interval 60s
disable_retry_limit true disable_retry_limit true
......
...@@ -22,16 +22,16 @@ func FLBPluginRegister(def unsafe.Pointer) int { ...@@ -22,16 +22,16 @@ func FLBPluginRegister(def unsafe.Pointer) int {
// plugin (context) pointer to fluentbit context (state/ c code) // plugin (context) pointer to fluentbit context (state/ c code)
func FLBPluginInit(plugin unsafe.Pointer) int { func FLBPluginInit(plugin unsafe.Pointer) int {
streamtool_uri := output.FLBPluginConfigKey(plugin, "streamtool_uri") streamtool_uri := output.FLBPluginConfigKey(plugin, "streamtool_uri")
user := output.FLBPluginConfigKey(plugin, "user") key := output.FLBPluginConfigKey(plugin, "key")
password := output.FLBPluginConfigKey(plugin, "password") certificate := output.FLBPluginConfigKey(plugin, "certificate")
buffer_type := output.FLBPluginConfigKey(plugin, "buffer_type") buffer_type := output.FLBPluginConfigKey(plugin, "buffer_type")
flush_interval := output.FLBPluginConfigKey(plugin, "flush_interval") flush_interval := output.FLBPluginConfigKey(plugin, "flush_interval")
disable_retry_limit := output.FLBPluginConfigKey(plugin, "disable_retry_limit") disable_retry_limit := output.FLBPluginConfigKey(plugin, "disable_retry_limit")
reference := output.FLBPluginConfigKey(plugin, "reference") reference := output.FLBPluginConfigKey(plugin, "reference")
dict := map[string]string{ dict := map[string]string{
"streamtool_uri": streamtool_uri, "streamtool_uri": streamtool_uri,
"user": user, "key": key,
"password": password, "certificate": certificate,
"buffer_type": buffer_type, "buffer_type": buffer_type,
"flush_interval": flush_interval, "flush_interval": flush_interval,
"disable_retry_limit": disable_retry_limit, "disable_retry_limit": disable_retry_limit,
...@@ -81,10 +81,17 @@ func FLBPluginFlushCtx(ctx, data unsafe.Pointer, length C.int, tag *C.char) int ...@@ -81,10 +81,17 @@ func FLBPluginFlushCtx(ctx, data unsafe.Pointer, length C.int, tag *C.char) int
//body result //body result
// content type "application/octet-stream" // content type "application/octet-stream"
var b = []byte(result) 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{ client := &http.Client{
Transport: &http.Transport{ 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)) 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 ...@@ -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()) fmt.Fprintf(os.Stderr, "Got error %s", err.Error())
return output.FLB_RETRY return output.FLB_RETRY
} }
req.SetBasicAuth(dict["user"], dict["password"])
req.Header.Set("Content-Type", "application/octet-stream") req.Header.Set("Content-Type", "application/octet-stream")
rsp, err := client.Do(req) rsp, err := client.Do(req)
if err != nil { 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