Skip to content

Commit

Permalink
config: return error if plugin type is empty (#4235)
Browse files Browse the repository at this point in the history
  • Loading branch information
fatedier committed May 23, 2024
1 parent 301515d commit 522e2c9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/config/v1/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package v1
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"reflect"
)
Expand All @@ -42,7 +43,7 @@ func (c *TypedClientPluginOptions) UnmarshalJSON(b []byte) error {

c.Type = typeStruct.Type
if c.Type == "" {
return nil
return errors.New("plugin type is empty")
}

v, ok := clientPluginOptionsTypeMap[typeStruct.Type]
Expand All @@ -63,6 +64,10 @@ func (c *TypedClientPluginOptions) UnmarshalJSON(b []byte) error {
return nil
}

func (c *TypedClientPluginOptions) MarshalJSON() ([]byte, error) {
return json.Marshal(c.ClientPluginOptions)
}

const (
PluginHTTP2HTTPS = "http2https"
PluginHTTPProxy = "http_proxy"
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/v1/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ func (c *TypedProxyConfig) UnmarshalJSON(b []byte) error {
return nil
}

func (c *TypedProxyConfig) MarshalJSON() ([]byte, error) {
return json.Marshal(c.ProxyConfigurer)
}

type ProxyConfigurer interface {
Complete(namePrefix string)
GetBaseConfig() *ProxyBaseConfig
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/v1/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (c *TypedVisitorConfig) UnmarshalJSON(b []byte) error {
return nil
}

func (c *TypedVisitorConfig) MarshalJSON() ([]byte, error) {
return json.Marshal(c.VisitorConfigurer)
}

func NewVisitorConfigurerByType(t VisitorType) VisitorConfigurer {
v, ok := visitorConfigTypeMap[t]
if !ok {
Expand Down

0 comments on commit 522e2c9

Please sign in to comment.