Skip to content

Commit

Permalink
fix: correct order of precedence to gate Konnect mode
Browse files Browse the repository at this point in the history
Right now decK runs against Konnect if some Konnect
credentials are around, either via command flags or via
environment variables. In the case of having a `kong-addr`
different from the default value and some lingering Konnect
credentials environment variables set, decK would still
decide to run against Konnect instead of Kong.

This PR is reworking the order of precedence gating Konnect:
1. if the config file contains the `_konnect` entry, run
   against Konnect
2. if the `kong-addr` is set to a non-default value, run
   against Kong
3. if some Konnect credentials are set, run against Konnect
4. otherwise run against Kong
  • Loading branch information
GGabriele committed Aug 19, 2022
1 parent 49d2f98 commit 5065a7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,11 @@ func sendAnalytics(cmd, kongVersion string, mode mode) error {
}

func inKonnectMode(targetContent *file.Content) bool {
if (targetContent != nil && targetContent.Konnect != nil) ||
konnectConfig.Email != "" ||
if targetContent != nil && targetContent.Konnect != nil {
return true
} else if rootConfig.Address != defaultKongURL {
return false
} else if konnectConfig.Email != "" ||
konnectConfig.Password != "" ||
konnectConfig.Token != "" {
return true
Expand Down
10 changes: 7 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import (
"github.com/spf13/viper"
)

const defaultKonnectURL = "https://us.api.konghq.com"
const (
defaultKongURL = "http://localhost:8001"
defaultKonnectURL = "https://us.api.konghq.com"
)

var (
cfgFile string
Expand All @@ -27,8 +30,9 @@ var (
konnectRuntimeGroup string
)

//nolint:errcheck
// NewRootCmd represents the base command when called without any subcommands
//
//nolint:errcheck
func NewRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "deck",
Expand All @@ -50,7 +54,7 @@ It can be used to export, import, or sync entities to Kong.`,
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "",
"Config file (default is $HOME/.deck.yaml).")

rootCmd.PersistentFlags().String("kong-addr", "http://localhost:8001",
rootCmd.PersistentFlags().String("kong-addr", defaultKongURL,
"HTTP address of Kong's Admin API.\n"+
"This value can also be set using the environment variable DECK_KONG_ADDR\n"+
" environment variable.")
Expand Down

0 comments on commit 5065a7d

Please sign in to comment.