Skip to content

Commit

Permalink
fix issue where guac.yaml was not being read for backend configuration
Browse files Browse the repository at this point in the history
Signed-off-by: pxp928 <parth.psu@gmail.com>
  • Loading branch information
pxp928 committed Dec 19, 2024
1 parent c277250 commit 5e951bf
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pkg/assembler/backends/arangodb/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ func registerFlags(cmd *cobra.Command) error {
return fmt.Errorf("failed to bind flags: %w", err)
}

// set values from guac.yaml if present
flags.user = viper.GetString("arango-user")
flags.pass = viper.GetString("arango-pass")
flags.addr = viper.GetString("arango-addr")

return nil
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/assembler/backends/ent/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ func registerFlags(cmd *cobra.Command) error {
return fmt.Errorf("failed to bind flags: %w", err)
}

// set values from guac.yaml if present
flags.dbAddress = viper.GetString("db-address")
flags.dbDriver = viper.GetString("db-driver")
flags.dbDebug = viper.GetBool("db-debug")
flags.dbMigrate = viper.GetBool("db-migrate")
flags.dbConnTime = viper.GetString("db-conn-time")

return nil
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/assembler/backends/keyvalue/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func registerFlags(cmd *cobra.Command) error {
return fmt.Errorf("failed to bind flags: %w", err)
}

// set values from guac.yaml if present
flags.kvStore = viper.GetString("kv-store")
flags.kvRedis = viper.GetString("kv-redis")
flags.kvTiKV = viper.GetString("kv-tikv")

return nil
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/assembler/backends/neo4j/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ func registerFlags(cmd *cobra.Command) error {
return fmt.Errorf("failed to bind flags: %w", err)
}

// set values from guac.yaml if present
flags.user = viper.GetString("neo4j-user")
flags.pass = viper.GetString("neo4j-pass")
flags.addr = viper.GetString("neo4j-addr")
flags.realm = viper.GetString("neo4j-realm")

return nil
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/assembler/backends/neptune/neptune.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ func registerFlags(cmd *cobra.Command) error {
return fmt.Errorf("failed to bind flags: %w", err)
}

// set values from guac.yaml if present
flags.endpoint = viper.GetString("neptune-endpoint")
flags.port = viper.GetInt("neptune-port")
flags.region = viper.GetString("neptune-region")
flags.user = viper.GetString("neptune-user")
flags.realm = viper.GetString("neptune-realm")

return nil
}

Expand Down
27 changes: 24 additions & 3 deletions pkg/assembler/backends/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ package backends
import (
"context"
"fmt"
"os"
"strings"

"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"golang.org/x/exp/maps"
)

Expand Down Expand Up @@ -48,10 +52,27 @@ func Register(name string, gb GBFunc, fr FlagRegistrarFunc, fp FlagParserFunc) {

// RegisterFlags registers all backend-specific flags to the given command
func RegisterFlags(cmd *cobra.Command) error {
var err error
// read in guac.yaml configuration into viper key/value store
home, err := homedir.Dir()
if err != nil {
fmt.Fprintf(os.Stderr, "failed to get user home directory: %v\n", err)
os.Exit(1)
}

viper.AddConfigPath(home)
viper.AddConfigPath(".")
viper.SetConfigName("guac")
viper.SetConfigType("yaml")

viper.AutomaticEnv()
viper.SetEnvPrefix("guac")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))

if err := viper.ReadInConfig(); err != nil {
return fmt.Errorf("failed to read viper config with error: %w", err)
}
for _, register := range flagRegistrar {
err = register(cmd)
if err != nil {
if err := register(cmd); err != nil {
return err
}
}
Expand Down

0 comments on commit 5e951bf

Please sign in to comment.