Skip to content

Added the fuctionality for publish with conditional flag #4900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion client/events/EventClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ import (
)

type EventClientConfig struct {
DestinationURL string `env:"EVENT_URL" envDefault:"http://localhost:3000/notify"`
DestinationURL string `env:"EVENT_URL" envDefault:"http://localhost:3000/notify"`
NotificationMedium NotificationMedium `env:"NOTIFICATION_MEDIUM" envDefault:"rest"`
}
type NotificationMedium string

const PUB_SUB NotificationMedium = "nats"

func GetEventClientConfig() (*EventClientConfig, error) {
cfg := &EventClientConfig{}
Expand Down Expand Up @@ -240,6 +244,17 @@ func (impl *EventRESTClientImpl) WriteNotificationEvent(event Event) (bool, erro
return true, err
}

func (impl *EventRESTClientImpl) sendEventsOnNats(body []byte) error {

err := impl.pubsubClient.Publish(pubsub.NOTIFICATION_EVENT_TOPIC, string(body))
if err != nil {
impl.logger.Errorw("err while publishing msg for testing topic", "msg", body, "err", err)
return err
}
return nil

}

// do not call this method if notification module is not installed
func (impl *EventRESTClientImpl) sendEvent(event Event) (bool, error) {
impl.logger.Debugw("event before send", "event", event)
Expand All @@ -248,7 +263,18 @@ func (impl *EventRESTClientImpl) sendEvent(event Event) (bool, error) {
impl.logger.Errorw("error while marshaling event request ", "err", err)
return false, err
}
//sending events on nats

if impl.config.NotificationMedium == PUB_SUB {
err = impl.sendEventsOnNats(body)
if err != nil {
impl.logger.Errorw("error while publishing event ", "err", err)
return false, err
}
return true, nil
}
var reqBody = []byte(body)

req, err := http.NewRequest(http.MethodPost, impl.config.DestinationURL, bytes.NewBuffer(reqBody))
if err != nil {
impl.logger.Errorw("error while writing event", "err", err)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/deckarep/golang-set v1.8.0
github.com/devtron-labs/authenticator v0.4.35-0.20240216091211-80e10a80ce7b
github.com/devtron-labs/common-lib v0.0.16-0.20240320102218-5807b1301538
github.com/devtron-labs/common-lib v0.0.16-0.16de0a44221fca9f859a9b559842af5462a353a3
github.com/devtron-labs/protos v0.0.3-0.20240130061723-7b2e12ab0abb
github.com/evanphx/json-patch v5.6.0+incompatible
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
Expand Down Expand Up @@ -71,7 +71,7 @@ require (
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
golang.org/x/oauth2 v0.11.0
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
google.golang.org/protobuf v1.33.0
gopkg.in/go-playground/validator.v9 v9.30.0
gopkg.in/igm/sockjs-go.v3 v3.0.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4 h1:YcpmyvADG
github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM=
github.com/devtron-labs/authenticator v0.4.35-0.20240216091211-80e10a80ce7b h1:aHKsdB4ghsp+x8167W8MZyF3WQOixTSJFyARrU+qR6s=
github.com/devtron-labs/authenticator v0.4.35-0.20240216091211-80e10a80ce7b/go.mod h1:a5gxST+HNmJReXE2TkCicFQFWtlhp8eqBRwS23GydNE=
github.com/devtron-labs/common-lib v0.0.16-0.20240320102218-5807b1301538 h1:KG/XRlhT3Mc066fE5qOk02kybqtnWTIsJhsUZ3gzDHc=
github.com/devtron-labs/common-lib v0.0.16-0.20240320102218-5807b1301538/go.mod h1:95/DizzVXu1kHap/VwEvdxwgd+BvPVYc0bJzt8yqGDU=
github.com/devtron-labs/common-lib v0.0.16-0.20240328120458-16de0a44221f h1:Q6/KUxMdIuzcGU7+MpF1LCWCvAqH4tmWPfKQOaXzOVQ=
github.com/devtron-labs/common-lib v0.0.16-0.20240328120458-16de0a44221f/go.mod h1:6QrrtLoLnuEdHkrx5HqkEVwMxEmnhAH1R/SJVMswuCc=
github.com/devtron-labs/protos v0.0.3-0.20240130061723-7b2e12ab0abb h1:CkfQQgZc950/hTPqtQSiHV2RmZgkBLGCzwR02FZYjAU=
github.com/devtron-labs/protos v0.0.3-0.20240130061723-7b2e12ab0abb/go.mod h1:pjLjgoa1GzbkOkvbMyP4SAKsaiK7eG6GoQCNauG03JA=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
Expand Down Expand Up @@ -1476,8 +1476,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20160105164936-4f90aeace3a2/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
10 changes: 10 additions & 0 deletions vendor/github.com/Microsoft/go-winio/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

149 changes: 149 additions & 0 deletions vendor/github.com/Microsoft/go-winio/.golangci.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions vendor/github.com/Microsoft/go-winio/SECURITY.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/github.com/Microsoft/go-winio/internal/fs/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading