diff --git a/internal/logger/config.go b/internal/logger/config.go index 478e61b37..df2c1b402 100644 --- a/internal/logger/config.go +++ b/internal/logger/config.go @@ -43,6 +43,7 @@ const ( ClientCert = "client_cert" ClientKey = "client_key" QueueSize = "queue_size" + Proxy = "proxy" KafkaBrokers = "brokers" KafkaTopic = "topic" @@ -62,6 +63,7 @@ const ( EnvLoggerWebhookAuthToken = "MINIO_LOGGER_WEBHOOK_AUTH_TOKEN" EnvLoggerWebhookClientCert = "MINIO_LOGGER_WEBHOOK_CLIENT_CERT" EnvLoggerWebhookClientKey = "MINIO_LOGGER_WEBHOOK_CLIENT_KEY" + EnvLoggerWebhookProxy = "MINIO_LOGGER_WEBHOOK_PROXY" EnvLoggerWebhookQueueSize = "MINIO_LOGGER_WEBHOOK_QUEUE_SIZE" EnvAuditWebhookEnable = "MINIO_AUDIT_WEBHOOK_ENABLE" @@ -109,6 +111,10 @@ var ( Key: ClientKey, Value: "", }, + config.KV{ + Key: Proxy, + Value: "", + }, config.KV{ Key: QueueSize, Value: "100000", @@ -441,6 +447,7 @@ func lookupLoggerWebhookConfig(scfg config.Config, cfg Config) (Config, error) { if err != nil { return cfg, err } + proxyEnv := EnvLoggerWebhookProxy queueSizeEnv := EnvAuditWebhookQueueSize if target != config.Default { queueSizeEnv = EnvAuditWebhookQueueSize + config.Default + target @@ -458,6 +465,7 @@ func lookupLoggerWebhookConfig(scfg config.Config, cfg Config) (Config, error) { AuthToken: env.Get(authTokenEnv, ""), ClientCert: env.Get(clientCertEnv, ""), ClientKey: env.Get(clientKeyEnv, ""), + Proxy: env.Get(proxyEnv, ""), QueueSize: queueSize, Name: target, } @@ -501,6 +509,7 @@ func lookupLoggerWebhookConfig(scfg config.Config, cfg Config) (Config, error) { AuthToken: kv.Get(AuthToken), ClientCert: kv.Get(ClientCert), ClientKey: kv.Get(ClientKey), + Proxy: kv.Get(Proxy), QueueSize: queueSize, Name: starget, } diff --git a/internal/logger/help.go b/internal/logger/help.go index cf2121b18..3bc1419ff 100644 --- a/internal/logger/help.go +++ b/internal/logger/help.go @@ -57,6 +57,12 @@ var ( Optional: true, Type: "number", }, + config.HelpKV{ + Key: Proxy, + Description: "proxy url endpoint e.g. http(s)://proxy", + Optional: true, + Type: "string", + }, config.HelpKV{ Key: config.Comment, Description: config.DefaultComment, diff --git a/internal/logger/target/http/http.go b/internal/logger/target/http/http.go index 4bb7b6105..ce9576ad3 100644 --- a/internal/logger/target/http/http.go +++ b/internal/logger/target/http/http.go @@ -24,6 +24,7 @@ import ( "errors" "fmt" "net/http" + "net/url" "strings" "sync" "sync/atomic" @@ -51,6 +52,7 @@ type Config struct { ClientCert string `json:"clientCert"` ClientKey string `json:"clientKey"` QueueSize int `json:"queueSize"` + Proxy string `json:"string"` Transport http.RoundTripper `json:"-"` // Custom logger @@ -127,6 +129,15 @@ func (h *Target) Init() error { req.Header.Set("Authorization", h.config.AuthToken) } + // If proxy available, set the same + if h.config.Proxy != "" { + proxyURL, _ := url.Parse(h.config.Proxy) + transport := h.config.Transport + ctransport := transport.(*http.Transport).Clone() + ctransport.Proxy = http.ProxyURL(proxyURL) + h.config.Transport = ctransport + } + client := http.Client{Transport: h.config.Transport} resp, err := client.Do(req) if err != nil {