Skip to content

Commit

Permalink
fix(auth): Add support for auth flags.
Browse files Browse the repository at this point in the history
chore(root): Full logging on `root.go`

Signed-off-by: spbsoluble <[email protected]>
  • Loading branch information
spbsoluble committed Nov 20, 2024
1 parent 4b1ca60 commit cb81571
Show file tree
Hide file tree
Showing 23 changed files with 909 additions and 515 deletions.
2 changes: 1 addition & 1 deletion cmd/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var certificatesCmd = &cobra.Command{

_, expErr := isExperimentalFeatureEnabled(expEnabled, isExperimental)
if expErr != nil {
fmt.Println(fmt.Sprintf("WARNING this is an expEnabled feature, %s", expErr))
fmt.Println(fmt.Sprintf("WARNING this is an flagEnableExp feature, %s", expErr))
log.Fatalf("[ERROR]: %s", expErr)
}
fmt.Println("NOT IMPLEMENTED: certificates called")
Expand Down
1 change: 1 addition & 0 deletions cmd/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
DebugFuncEnter = "entered: %s"
DebugFuncExit = "exiting: %s"
DebugFuncCall = "calling: %s"
DebugFuncReturn = "returned: %s"
MinHttpTimeout = 3
)

Expand Down
24 changes: 12 additions & 12 deletions cmd/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ var containersCreateCmd = &cobra.Command{
cmd.SilenceUsage = true
isExperimental := true

_, expErr := isExperimentalFeatureEnabled(expEnabled, isExperimental)
_, expErr := isExperimentalFeatureEnabled(flagEnableExp, isExperimental)
if expErr != nil {
fmt.Println(fmt.Sprintf("WARNING this is an expEnabled feature, %s", expErr))
fmt.Println(fmt.Sprintf("WARNING this is an flagEnableExp feature, %s", expErr))
log.Fatalf("[ERROR]: %s", expErr)
}
fmt.Println("Create store containers not implemented.")
Expand All @@ -55,7 +55,7 @@ var containersGetCmd = &cobra.Command{
id := cmd.Flag("id").Value.String()

isExperimental := true
debugErr := warnExperimentalFeature(expEnabled, isExperimental)
debugErr := warnExperimentalFeature(flagEnableExp, isExperimental)
if debugErr != nil {
return debugErr
}
Expand Down Expand Up @@ -86,8 +86,8 @@ var containersUpdateCmd = &cobra.Command{
// Specific flags

isExperimental := true
informDebug(debugFlag)
debugErr := warnExperimentalFeature(expEnabled, isExperimental)
informDebug(flagEnableDebug)
debugErr := warnExperimentalFeature(flagEnableExp, isExperimental)
if debugErr != nil {
return debugErr
}
Expand All @@ -108,17 +108,17 @@ var containersDeleteCmd = &cobra.Command{
cmd.SilenceUsage = true
// Specific flags

// Debug + expEnabled checks
// Debug + flagEnableExp checks
isExperimental := true
informDebug(debugFlag)
debugErr := warnExperimentalFeature(expEnabled, isExperimental)
informDebug(flagEnableDebug)
debugErr := warnExperimentalFeature(flagEnableExp, isExperimental)
if debugErr != nil {
return debugErr
}

// Authenticate
//
//kfClient, _ := initClient(configFile, profile, providerType, providerProfile, noPrompt, authConfig, false)
//kfClient, _ := initClient(flagConfigFile, flagProfile, flagProviderType, flagProviderProfile, flagNoPrompt, authConfig, false)

// CLI Logic
return fmt.Errorf("delete store containers not implemented")
Expand All @@ -133,10 +133,10 @@ var containersListCmd = &cobra.Command{
cmd.SilenceUsage = true
// Specific flags

// Debug + expEnabled checks
// Debug + flagEnableExp checks
isExperimental := true
informDebug(debugFlag)
debugErr := warnExperimentalFeature(expEnabled, isExperimental)
informDebug(flagEnableDebug)
debugErr := warnExperimentalFeature(flagEnableExp, isExperimental)
if debugErr != nil {
return debugErr
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ var exportCmd = &cobra.Command{
log.Debug().Msgf("%s: exportCmd", DebugFuncEnter)
isExperimental := true

informDebug(debugFlag)
debugErr := warnExperimentalFeature(expEnabled, isExperimental)
informDebug(flagEnableDebug)
debugErr := warnExperimentalFeature(flagEnableExp, isExperimental)
if debugErr != nil {
return debugErr
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/helm_uo.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,20 @@ func (f *HelmUoFlags) ToOptions(cmd *cobra.Command, args []string) (*HelmUoOptio
flags.GetDebugFlag(cmd)

// Determine if feature is enabled
expEnabled, _ = cmd.Flags().GetBool("exp")
_, err := isExperimentalFeatureEnabled(expEnabled, true)
flagEnableExp, _ = cmd.Flags().GetBool("exp")
_, err := isExperimentalFeatureEnabled(flagEnableExp, true)
if err != nil {
return nil, fmt.Errorf("feature gate check failed: %s", err)
}

// Get the command config entry from global flags
commandConfig, _ := auth_providers.ReadConfigFromJSON(configFile)
commandConfig, _ := auth_providers.ReadConfigFromJSON(flagConfigFile)

// Get the hostname from the command config
entry, ok := commandConfig.Servers[profile]
entry, ok := commandConfig.Servers[flagProfile]
if ok {
if entry.Host != "" {
options.CommandHostname = commandConfig.Servers[profile].Host
options.CommandHostname = commandConfig.Servers[flagProfile].Host
}
}

Expand Down
54 changes: 31 additions & 23 deletions cmd/helm_uo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ package cmd

import (
"fmt"
"os"
"testing"

"github.com/spf13/pflag"
"gopkg.in/yaml.v3"
"kfutil/pkg/cmdtest"
"kfutil/pkg/cmdutil/extensions"
"kfutil/pkg/helm"
"os"
"testing"
)

var filename = fmt.Sprintf("https://raw.githubusercontent.com/Keyfactor/containerized-uo-deployment-dev/main/universal-orchestrator/values.yaml?token=%s", os.Getenv("TOKEN"))
var filename = fmt.Sprintf(
"https://raw.githubusercontent.com/Keyfactor/containerized-uo-deployment-dev/main/universal-orchestrator/values.yaml?token=%s",
os.Getenv("TOKEN"),
)

func TestHelmUo_SaveAndExit(t *testing.T) {
t.Skip()
Expand All @@ -54,26 +58,30 @@ func TestHelmUo_SaveAndExit(t *testing.T) {
}

for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
var output []byte
var err error

cmdtest.RunTest(t, test.Procedure, func() error {
output, err = cmdtest.TestExecuteCommand(t, RootCmd, test.CommandArguments...)
if err != nil {
return err
t.Run(
test.Name, func(t *testing.T) {
var output []byte
var err error

cmdtest.RunTest(
t, test.Procedure, func() error {
output, err = cmdtest.TestExecuteCommand(t, RootCmd, test.CommandArguments...)
if err != nil {
return err
}

return nil
},
)

if test.CheckProcedure != nil {
err = test.CheckProcedure(output)
if err != nil {
t.Error(err)
}
}

return nil
})

if test.CheckProcedure != nil {
err = test.CheckProcedure(output)
if err != nil {
t.Error(err)
}
}
})
},
)
}
}

Expand All @@ -83,7 +91,7 @@ func TestHelmUo(t *testing.T) {
var profile, config string
uoCmd.Flags().BoolVarP(&debug, "debug", "b", false, "debug")
uoCmd.Flags().BoolVarP(&noPrompt, "no-prompt", "y", false, "no-prompt")
uoCmd.Flags().StringVarP(&profile, "profile", "p", "", "profile")
uoCmd.Flags().StringVarP(&profile, "flagProfile", "p", "", "flagProfile")
uoCmd.Flags().StringVarP(&config, "config", "c", "", "config")
uoCmd.Flags().BoolVarP(&exp, "exp", "", false, "exp")

Expand Down
52 changes: 26 additions & 26 deletions cmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,35 +248,35 @@ func loadJSONFile(filename string) (map[string]interface{}, error) {

func logGlobals() {

if !logInsecure {
log.Debug().Str("configFile", configFile).
Str("profile", profile).
Str("providerType", providerType).
Str("providerProfile", providerProfile).
if !flagLogInsecure {
log.Debug().Str("flagConfigFile", flagConfigFile).
Str("flagProfile", flagProfile).
Str("flagProviderType", flagProviderType).
Str("flagProviderProfile", flagProviderProfile).
//Str("providerConfig", providerConfig).
Bool("noPrompt", noPrompt).
Bool("expEnabled", expEnabled).
Bool("debugFlag", debugFlag).
Str("kfcUsername", kfcUsername).
Str("kfcHostName", kfcHostName).
Str("kfcPassword", hashSecretValue(kfcPassword)).
Str("kfcDomain", kfcDomain).
Str("kfcAPIPath", kfcAPIPath).
Bool("flagNoPrompt", flagNoPrompt).
Bool("flagEnableExp", flagEnableExp).
Bool("flagEnableDebug", flagEnableDebug).
Str("flagUsername", flagUsername).
Str("flagHostName", flagHostName).
Str("flagPassword", hashSecretValue(flagPassword)).
Str("flagDomain", flagDomain).
Str("flagAPIPath", flagAPIPath).
Msg("Global Flags")
} else {
log.Debug().Str("configFile", configFile).
Str("profile", profile).
Str("providerType", providerType).
Str("providerProfile", providerProfile).
log.Debug().Str("flagConfigFile", flagConfigFile).
Str("flagProfile", flagProfile).
Str("flagProviderType", flagProviderType).
Str("flagProviderProfile", flagProviderProfile).
//Str("providerConfig", providerConfig).
Bool("noPrompt", noPrompt).
Bool("expEnabled", expEnabled).
Bool("debugFlag", debugFlag).
Str("kfcUsername", kfcUsername).
Str("kfcHostName", kfcHostName).
Str("kfcPassword", kfcPassword).
Str("kfcDomain", kfcDomain).
Str("kfcAPIPath", kfcAPIPath).
Bool("flagNoPrompt", flagNoPrompt).
Bool("flagEnableExp", flagEnableExp).
Bool("flagEnableDebug", flagEnableDebug).
Str("flagUsername", flagUsername).
Str("flagHostName", flagHostName).
Str("flagPassword", flagPassword).
Str("flagDomain", flagDomain).
Str("flagAPIPath", flagAPIPath).
Msg("Global Flags")
}

Expand Down Expand Up @@ -379,7 +379,7 @@ func storeTypeIdentifierFlagCheck(cmd *cobra.Command) error {
func warnExperimentalFeature(expEnabled bool, isExperimental bool) error {
_, expErr := isExperimentalFeatureEnabled(expEnabled, isExperimental)
if expErr != nil {
//fmt.Println(fmt.Sprintf("WARNING this is an expEnabled feature, %s", expErr))
//fmt.Println(fmt.Sprintf("WARNING this is an flagEnableExp feature, %s", expErr))
log.Error().Err(expErr)
return expErr
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ var importCmd = &cobra.Command{
log.Debug().Msgf("%s: importCmd", DebugFuncEnter)
isExperimental := true

informDebug(debugFlag)
debugErr := warnExperimentalFeature(expEnabled, isExperimental)
informDebug(flagEnableDebug)
debugErr := warnExperimentalFeature(flagEnableExp, isExperimental)
if debugErr != nil {
return debugErr
}
Expand Down
24 changes: 12 additions & 12 deletions cmd/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ var inventoryClearCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
isExperimental := true

_, expErr := isExperimentalFeatureEnabled(expEnabled, isExperimental)
_, expErr := isExperimentalFeatureEnabled(flagEnableExp, isExperimental)
if expErr != nil {
fmt.Println(fmt.Sprintf("WARNING this is an expEnabled feature, %s", expErr))
fmt.Println(fmt.Sprintf("WARNING this is an flagEnableExp feature, %s", expErr))
log.Fatalf("[ERROR]: %s", expErr)
}

debugModeEnabled := checkDebug(debugFlag)
debugModeEnabled := checkDebug(flagEnableDebug)
log.Println("Debug mode enabled: ", debugModeEnabled)
force, _ := cmd.Flags().GetBool("force")
dryRun, _ := cmd.Flags().GetBool("dry-run")
Expand Down Expand Up @@ -220,13 +220,13 @@ attempt to add all the certificate(s) meeting the specified criteria to all stor
Run: func(cmd *cobra.Command, args []string) {
isExperimental := true

_, expErr := isExperimentalFeatureEnabled(expEnabled, isExperimental)
_, expErr := isExperimentalFeatureEnabled(flagEnableExp, isExperimental)
if expErr != nil {
fmt.Println(fmt.Sprintf("WARNING this is an expEnabled feature, %s", expErr))
fmt.Println(fmt.Sprintf("WARNING this is an flagEnableExp feature, %s", expErr))
log.Fatalf("[ERROR]: %s", expErr)
}

debugModeEnabled := checkDebug(debugFlag)
debugModeEnabled := checkDebug(flagEnableDebug)
log.Println("Debug mode enabled: ", debugModeEnabled)
force, _ := cmd.Flags().GetBool("force")
dryRun, _ := cmd.Flags().GetBool("dry-run")
Expand Down Expand Up @@ -409,13 +409,13 @@ var inventoryRemoveCmd = &cobra.Command{

isExperimental := true

_, expErr := isExperimentalFeatureEnabled(expEnabled, isExperimental)
_, expErr := isExperimentalFeatureEnabled(flagEnableExp, isExperimental)
if expErr != nil {
fmt.Println(fmt.Sprintf("WARNING this is an expEnabled feature, %s", expErr))
fmt.Println(fmt.Sprintf("WARNING this is an flagEnableExp feature, %s", expErr))
log.Fatalf("[ERROR]: %s", expErr)
}

debugModeEnabled := checkDebug(debugFlag)
debugModeEnabled := checkDebug(flagEnableDebug)
log.Println("Debug mode enabled: ", debugModeEnabled)
force, _ := cmd.Flags().GetBool("force")
dryRun, _ := cmd.Flags().GetBool("dry-run")
Expand Down Expand Up @@ -611,13 +611,13 @@ var inventoryShowCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
isExperimental := true

_, expErr := isExperimentalFeatureEnabled(expEnabled, isExperimental)
_, expErr := isExperimentalFeatureEnabled(flagEnableExp, isExperimental)
if expErr != nil {
fmt.Println(fmt.Sprintf("WARNING this is an expEnabled feature, %s", expErr))
fmt.Println(fmt.Sprintf("WARNING this is an flagEnableExp feature, %s", expErr))
log.Fatalf("[ERROR]: %s", expErr)
}

debugModeEnabled := checkDebug(debugFlag)
debugModeEnabled := checkDebug(flagEnableDebug)
log.Println("Debug mode enabled: ", debugModeEnabled)
storeIDs, _ := cmd.Flags().GetStringSlice("sid")
clientMachineNames, _ := cmd.Flags().GetStringSlice("client")
Expand Down
Loading

0 comments on commit cb81571

Please sign in to comment.