Skip to content

Commit

Permalink
feat: bump go-dcp to v1.2.0-rc.2 and tls improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
erayarslan committed Oct 25, 2024
1 parent a8e6db2 commit 76a2289
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 33 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ type Kafka struct {
ProducerBatchBytes any `yaml:"producerBatchBytes"`
CollectionTopicMapping map[string]string `yaml:"collectionTopicMapping"`
InterCAPath string `yaml:"interCAPath"`
InterCA string `yaml:"interCA"`
ScramUsername string `yaml:"scramUsername"`
ScramPassword string `yaml:"scramPassword"`
RootCAPath string `yaml:"rootCAPath"`
RootCA string `yaml:"rootCA"`
ClientID string `yaml:"clientID"`
Balancer string `yaml:"balancer"`
Brokers []string `yaml:"brokers"`
Expand Down
2 changes: 1 addition & 1 deletion example/default-mapper/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ replace github.com/Trendyol/go-dcp-kafka => ./../..
require github.com/Trendyol/go-dcp-kafka v0.0.0

require (
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb // indirect
github.com/Trendyol/go-dcp v1.2.0-rc.2 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/ansrivas/fiberprometheus/v2 v2.7.0 // indirect
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect
Expand Down
4 changes: 2 additions & 2 deletions example/default-mapper/go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb h1:WTud3h2kkzFhIZP1aIo+b2q8FonAjmgi8wZ0lT63Cs4=
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb/go.mod h1:k49rj06gaLt3lLNoWdQFT+KzXb0C5mzaByRwEgeTu20=
github.com/Trendyol/go-dcp v1.2.0-rc.2 h1:7a++gznhbrTKqv8JEx3tCAKhUGD1WIPqeXhPE6Duc/4=
github.com/Trendyol/go-dcp v1.2.0-rc.2/go.mod h1:k49rj06gaLt3lLNoWdQFT+KzXb0C5mzaByRwEgeTu20=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/ansrivas/fiberprometheus/v2 v2.7.0 h1:09XiSzG0J7aZp7RviklngdWdDbSybKjhuWAstp003Gg=
Expand Down
2 changes: 1 addition & 1 deletion example/grafana/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
)

require (
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb // indirect
github.com/Trendyol/go-dcp v1.2.0-rc.2 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/ansrivas/fiberprometheus/v2 v2.7.0 // indirect
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect
Expand Down
4 changes: 2 additions & 2 deletions example/grafana/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb h1:WTud3h2kkzFhIZP1aIo+b2q8FonAjmgi8wZ0lT63Cs4=
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb/go.mod h1:k49rj06gaLt3lLNoWdQFT+KzXb0C5mzaByRwEgeTu20=
github.com/Trendyol/go-dcp v1.2.0-rc.2 h1:7a++gznhbrTKqv8JEx3tCAKhUGD1WIPqeXhPE6Duc/4=
github.com/Trendyol/go-dcp v1.2.0-rc.2/go.mod h1:k49rj06gaLt3lLNoWdQFT+KzXb0C5mzaByRwEgeTu20=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/ansrivas/fiberprometheus/v2 v2.7.0 h1:09XiSzG0J7aZp7RviklngdWdDbSybKjhuWAstp003Gg=
Expand Down
2 changes: 1 addition & 1 deletion example/simple-logger/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
)

require (
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb // indirect
github.com/Trendyol/go-dcp v1.2.0-rc.2 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/ansrivas/fiberprometheus/v2 v2.7.0 // indirect
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect
Expand Down
4 changes: 2 additions & 2 deletions example/simple-logger/go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb h1:WTud3h2kkzFhIZP1aIo+b2q8FonAjmgi8wZ0lT63Cs4=
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb/go.mod h1:k49rj06gaLt3lLNoWdQFT+KzXb0C5mzaByRwEgeTu20=
github.com/Trendyol/go-dcp v1.2.0-rc.2 h1:7a++gznhbrTKqv8JEx3tCAKhUGD1WIPqeXhPE6Duc/4=
github.com/Trendyol/go-dcp v1.2.0-rc.2/go.mod h1:k49rj06gaLt3lLNoWdQFT+KzXb0C5mzaByRwEgeTu20=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/ansrivas/fiberprometheus/v2 v2.7.0 h1:09XiSzG0J7aZp7RviklngdWdDbSybKjhuWAstp003Gg=
Expand Down
2 changes: 1 addition & 1 deletion example/simple/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ replace github.com/Trendyol/go-dcp-kafka => ./../..
require github.com/Trendyol/go-dcp-kafka v0.0.0

require (
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb // indirect
github.com/Trendyol/go-dcp v1.2.0-rc.2 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/ansrivas/fiberprometheus/v2 v2.7.0 // indirect
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect
Expand Down
4 changes: 2 additions & 2 deletions example/simple/go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb h1:WTud3h2kkzFhIZP1aIo+b2q8FonAjmgi8wZ0lT63Cs4=
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb/go.mod h1:k49rj06gaLt3lLNoWdQFT+KzXb0C5mzaByRwEgeTu20=
github.com/Trendyol/go-dcp v1.2.0-rc.2 h1:7a++gznhbrTKqv8JEx3tCAKhUGD1WIPqeXhPE6Duc/4=
github.com/Trendyol/go-dcp v1.2.0-rc.2/go.mod h1:k49rj06gaLt3lLNoWdQFT+KzXb0C5mzaByRwEgeTu20=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/ansrivas/fiberprometheus/v2 v2.7.0 h1:09XiSzG0J7aZp7RviklngdWdDbSybKjhuWAstp003Gg=
Expand Down
2 changes: 1 addition & 1 deletion example/struct-config/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
replace github.com/Trendyol/go-dcp-kafka => ./../..

require (
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb
github.com/Trendyol/go-dcp v1.2.0-rc.2
github.com/Trendyol/go-dcp-kafka v0.0.0
)

Expand Down
4 changes: 2 additions & 2 deletions example/struct-config/go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb h1:WTud3h2kkzFhIZP1aIo+b2q8FonAjmgi8wZ0lT63Cs4=
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb/go.mod h1:k49rj06gaLt3lLNoWdQFT+KzXb0C5mzaByRwEgeTu20=
github.com/Trendyol/go-dcp v1.2.0-rc.2 h1:7a++gznhbrTKqv8JEx3tCAKhUGD1WIPqeXhPE6Duc/4=
github.com/Trendyol/go-dcp v1.2.0-rc.2/go.mod h1:k49rj06gaLt3lLNoWdQFT+KzXb0C5mzaByRwEgeTu20=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/ansrivas/fiberprometheus/v2 v2.7.0 h1:09XiSzG0J7aZp7RviklngdWdDbSybKjhuWAstp003Gg=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Trendyol/go-dcp-kafka
go 1.20

require (
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb
github.com/Trendyol/go-dcp v1.2.0-rc.2
github.com/json-iterator/go v1.1.12
github.com/prometheus/client_golang v1.20.5
github.com/segmentio/kafka-go v0.4.47
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb h1:WTud3h2kkzFhIZP1aIo+b2q8FonAjmgi8wZ0lT63Cs4=
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb/go.mod h1:k49rj06gaLt3lLNoWdQFT+KzXb0C5mzaByRwEgeTu20=
github.com/Trendyol/go-dcp v1.2.0-rc.2 h1:7a++gznhbrTKqv8JEx3tCAKhUGD1WIPqeXhPE6Duc/4=
github.com/Trendyol/go-dcp v1.2.0-rc.2/go.mod h1:k49rj06gaLt3lLNoWdQFT+KzXb0C5mzaByRwEgeTu20=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/ansrivas/fiberprometheus/v2 v2.7.0 h1:09XiSzG0J7aZp7RviklngdWdDbSybKjhuWAstp003Gg=
Expand Down
51 changes: 39 additions & 12 deletions kafka/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,53 @@ func newTLSContent(
scramUsername,
scramPassword,
rootCAPath,
interCAPath string,
interCAPath,
rootCA,
interCA string,
) (*tlsContent, error) {
mechanism, err := scram.Mechanism(scram.SHA512, scramUsername, scramPassword)
if err != nil {
return nil, err
}

caCert, err := os.ReadFile(os.ExpandEnv(rootCAPath))
if err != nil {
logger.Log.Error("an error occurred while reading ca.pem file! Error: %s", err.Error())
return nil, err
certCount := 0
caCertPool := x509.NewCertPool()

if rootCAPath != "" {
caCert, err := os.ReadFile(os.ExpandEnv(rootCAPath))
if err != nil {
logger.Log.Error("an error occurred while reading ca.pem file! Error: %s", err.Error())
return nil, err
}
caCertPool.AppendCertsFromPEM(caCert)
certCount++
}

intCert, err := os.ReadFile(os.ExpandEnv(interCAPath))
if err != nil {
logger.Log.Error("an error occurred while reading int.pem file! Error: %s", err.Error())
return nil, err
if interCAPath != "" {
intCert, err := os.ReadFile(os.ExpandEnv(interCAPath))
if err != nil {
logger.Log.Error("an error occurred while reading int.pem file! Error: %s", err.Error())
return nil, err
}
caCertPool.AppendCertsFromPEM(intCert)
certCount++
}

caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
caCertPool.AppendCertsFromPEM(intCert)
if rootCA != "" {
caCertPool.AppendCertsFromPEM([]byte(rootCA))
certCount++
}

if interCA != "" {
caCertPool.AppendCertsFromPEM([]byte(interCA))
certCount++
}

if certCount == 0 {
err := errors.New("certPool is empty")
logger.Log.Error("an error occurred while creating tls content! Error: %s", err.Error())
return nil, err
}

return &tlsContent{
config: &tls.Config{
Expand Down Expand Up @@ -271,6 +296,8 @@ func NewClient(config *config.Connector) Client {
config.Kafka.ScramPassword,
config.Kafka.RootCAPath,
config.Kafka.InterCAPath,
config.Kafka.RootCA,
config.Kafka.InterCA,
)
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
replace github.com/Trendyol/go-dcp-kafka => ../../.

require (
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb
github.com/Trendyol/go-dcp v1.2.0-rc.2
github.com/Trendyol/go-dcp-kafka v0.0.0
github.com/segmentio/kafka-go v0.4.47
)
Expand Down
4 changes: 2 additions & 2 deletions test/integration/go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb h1:WTud3h2kkzFhIZP1aIo+b2q8FonAjmgi8wZ0lT63Cs4=
github.com/Trendyol/go-dcp v1.1.57-0.20241023075515-0762009134fb/go.mod h1:k49rj06gaLt3lLNoWdQFT+KzXb0C5mzaByRwEgeTu20=
github.com/Trendyol/go-dcp v1.2.0-rc.2 h1:7a++gznhbrTKqv8JEx3tCAKhUGD1WIPqeXhPE6Duc/4=
github.com/Trendyol/go-dcp v1.2.0-rc.2/go.mod h1:k49rj06gaLt3lLNoWdQFT+KzXb0C5mzaByRwEgeTu20=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/ansrivas/fiberprometheus/v2 v2.7.0 h1:09XiSzG0J7aZp7RviklngdWdDbSybKjhuWAstp003Gg=
Expand Down

0 comments on commit 76a2289

Please sign in to comment.