Skip to content

Commit

Permalink
feat(validation): Add validation for couchbase config
Browse files Browse the repository at this point in the history
Signed-off-by: Ritesh Rai <[email protected]>
  • Loading branch information
ritesh089 authored and vados-cosmonic committed Jul 10, 2024
1 parent 0661807 commit 5ffe536
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package main

import (
"errors"
"log"
"os"
"os/signal"
Expand Down Expand Up @@ -81,10 +82,31 @@ func run() error {
func handleNewTargetLink(handler *Handler, link provider.InterfaceLinkDefinition) error {
handler.Logger.Info("Handling new target link", "link", link)
handler.linkedFrom[link.SourceID] = link.TargetConfig
err := ValidateCouchbaseConfig(link.TargetConfig)
if err != nil {
handler.Logger.Error("Invalid couchbase target config", "error", err)
return err
}
handler.updateCouchbaseCluster(handler, link.SourceID, link.TargetConfig)
return nil
}

func ValidateCouchbaseConfig(config map[string]string) error {
if config["username"] == "" {
return errors.New("username is required")
}
if config["password"] == "" {
return errors.New("password is required")
}
if config["bucket"] == "" {
return errors.New("bucket is required")
}
if config["host"] == "" {
return errors.New("host is required")
}
return nil
}

func handleDelTargetLink(handler *Handler, link provider.InterfaceLinkDefinition) error {
handler.Logger.Info("Handling del target link", "link", link)
delete(handler.linkedFrom, link.Target)
Expand Down

0 comments on commit 5ffe536

Please sign in to comment.