Skip to content

Commit

Permalink
support others
Browse files Browse the repository at this point in the history
Signed-off-by: yisaer <[email protected]>
  • Loading branch information
Yisaer committed Jan 10, 2024
1 parent 8c510a3 commit 792e793
Show file tree
Hide file tree
Showing 9 changed files with 586 additions and 280 deletions.
45 changes: 0 additions & 45 deletions extensions/kafka/kafkaConf.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,51 +30,6 @@ const (
SASL_SCRAM = "scram"
)

//func (c *TLSConf) TlsConfigLog(typ string) {
// if c == nil {
// conf.Log.Infof("kafka %s tls not configured", typ)
// return
// }
// if c.InsecureSkipVerify {
// conf.Log.Infof("kafka %s tls enable insecure skip verify", typ)
// return
// }
// b := bytes.NewBufferString("kafka ")
// b.WriteString(typ)
// b.WriteString(" tls enabled")
// if len(c.CertificationPath) > 0 {
// b.WriteString(", crt configured")
// } else {
// b.WriteString(", crt not configured")
// }
// if len(c.PrivateKeyPath) > 0 {
// b.WriteString(", key configured")
// } else {
// b.WriteString(", key not configured")
// }
// if len(c.RootCaPath) > 0 {
// b.WriteString(", root ca configured")
// } else {
// b.WriteString(", root ca not configured")
// }
// conf.Log.Info(b.String())
//}

//
//func (c *TLSConf) GetTlsConfig() (*tls.Config, error) {
// if len(c.CertificationPath) == 0 && len(c.PrivateKeyPath) == 0 && len(c.RootCaPath) == 0 {
// return nil, nil
// }
// return cert.GenerateTLSForClient(cert.TlsConfigurationOptions{
// SkipCertVerify: c.InsecureSkipVerify,
// CertFile: c.CertificationPath,
// KeyFile: c.PrivateKeyPath,
// CaFile: c.RootCaPath,
// TLSMinVersion: c.TLSMinVersion,
// RenegotiationSupport: c.RenegotiationSupport,
// })
//}

type SaslConf struct {
SaslAuthType string `json:"saslAuthType"`
SaslUserName string `json:"saslUserName"`
Expand Down
504 changes: 451 additions & 53 deletions go.work.sum

Large diffs are not rendered by default.

44 changes: 18 additions & 26 deletions internal/io/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,14 @@ type ClientConf struct {
}

type RawConf struct {
Url string `json:"url"`
Method string `json:"method"`
Body string `json:"body"`
BodyType string `json:"bodyType"`
Headers interface{} `json:"headers"`
InsecureSkipVerify bool `json:"insecureSkipVerify"`
CertificationPath string `json:"certificationPath"`
PrivateKeyPath string `json:"privateKeyPath"`
RootCaPath string `json:"rootCaPath"`
TLSMinVersion string `json:"tlsMinVersion"`
RenegotiationSupport string `json:"renegotiationSupport"`
Timeout int `json:"timeout"`
DebugResp bool `json:"debugResp"`
Url string `json:"url"`
Method string `json:"method"`
Body string `json:"body"`
BodyType string `json:"bodyType"`
Headers interface{} `json:"headers"`
*cert.TlsConfigurationOptions
Timeout int `json:"timeout"`
DebugResp bool `json:"debugResp"`
// Could be code or body
ResponseType string `json:"responseType"`
OAuth map[string]map[string]interface{} `json:"oauth"`
Expand Down Expand Up @@ -114,13 +109,13 @@ func (cc *ClientConf) InitConf(device string, props map[string]interface{}, with
withOption(option)
}
c := &RawConf{
Url: "http://localhost",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
InsecureSkipVerify: true,
ResponseType: "code",
Url: "http://localhost",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
ResponseType: "code",
}

if err := cast.MapToStruct(props, c); err != nil {
return fmt.Errorf("fail to parse the properties: %v", err)
}
Expand Down Expand Up @@ -177,14 +172,11 @@ func (cc *ClientConf) InitConf(device string, props map[string]interface{}, with
return fmt.Errorf("headers must be a map or a string")
}
}
tlsOpts := cert.TlsConfigurationOptions{
SkipCertVerify: c.InsecureSkipVerify,
CertFile: c.CertificationPath,
KeyFile: c.PrivateKeyPath,
CaFile: c.RootCaPath,
TLSMinVersion: c.TLSMinVersion,
RenegotiationSupport: c.RenegotiationSupport,
tlsOpts, err := cert.GenTlsConfigurationOptions(props)
if err != nil {
return err
}
c.TlsConfigurationOptions = tlsOpts

tlscfg, err := cert.GenerateTLSForClient(tlsOpts)
if err != nil {
Expand Down
60 changes: 28 additions & 32 deletions internal/io/http/httppull_lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ func TestConfigureLookup(t *testing.T) {
},
},
config: &RawConf{
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
InsecureSkipVerify: true,
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
Headers: map[string]interface{}{
"Authorization": "Bearer {{.token}}",
},
Expand Down Expand Up @@ -104,14 +103,13 @@ func TestConfigureLookup(t *testing.T) {
},
},
config: &RawConf{
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
InsecureSkipVerify: true,
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
Headers: map[string]interface{}{
"Authorization": "Bearer {{.token}}",
},
Expand Down Expand Up @@ -162,14 +160,13 @@ func TestConfigureLookup(t *testing.T) {
},
},
config: &RawConf{
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
InsecureSkipVerify: true,
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
Headers: map[string]interface{}{
"Authorization": "Bearer {{.token}}",
},
Expand Down Expand Up @@ -218,14 +215,13 @@ func TestConfigureLookup(t *testing.T) {
"url": "http://localhost:9090/",
},
config: &RawConf{
Url: "http://localhost:9090/",
ResendUrl: "http://localhost:9090/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
InsecureSkipVerify: true,
Url: "http://localhost:9090/",
ResendUrl: "http://localhost:9090/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
},
},
}
Expand Down
107 changes: 50 additions & 57 deletions internal/io/http/httppull_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,14 @@ func TestConfigure(t *testing.T) {
"url": "http://localhost:9090/",
},
config: &RawConf{
Incremental: true,
Url: "http://localhost:9090/",
ResendUrl: "http://localhost:9090/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
InsecureSkipVerify: true,
Incremental: true,
Url: "http://localhost:9090/",
ResendUrl: "http://localhost:9090/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
},
},
// Test wrong properties
Expand Down Expand Up @@ -422,14 +421,13 @@ func TestConfigure(t *testing.T) {
},
},
config: &RawConf{
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
InsecureSkipVerify: true,
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
Headers: map[string]interface{}{
"Authorization": "Bearer {{.token}}",
},
Expand Down Expand Up @@ -473,14 +471,13 @@ func TestConfigure(t *testing.T) {
},
},
config: &RawConf{
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
InsecureSkipVerify: true,
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
Headers: map[string]interface{}{
"Authorization": "Bearer {{.token}}",
},
Expand Down Expand Up @@ -531,14 +528,13 @@ func TestConfigure(t *testing.T) {
},
},
config: &RawConf{
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
InsecureSkipVerify: true,
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
Headers: map[string]interface{}{
"Authorization": "Bearer {{.token}}",
},
Expand Down Expand Up @@ -612,14 +608,13 @@ func TestConfigure(t *testing.T) {
},
},
config: &RawConf{
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
InsecureSkipVerify: true,
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
Headers: map[string]interface{}{
"Authorization": "Bearer {{.token}}",
},
Expand Down Expand Up @@ -685,14 +680,13 @@ func TestConfigure(t *testing.T) {
},
},
config: &RawConf{
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
InsecureSkipVerify: true,
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "none",
ResponseType: "code",
Headers: map[string]interface{}{
"Authorization": "Bearer {{.token}}",
},
Expand Down Expand Up @@ -737,14 +731,13 @@ func TestConfigure(t *testing.T) {
},
},
config: &RawConf{
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "json",
ResponseType: "code",
InsecureSkipVerify: true,
Url: "http://localhost:52345/",
ResendUrl: "http://localhost:52345/",
Method: http.MethodGet,
Interval: DefaultInterval,
Timeout: DefaultTimeout,
BodyType: "json",
ResponseType: "code",
Headers: map[string]string{
"Authorization": "Bearer {{.token}}",
},
Expand Down
Loading

0 comments on commit 792e793

Please sign in to comment.