diff --git a/README.md b/README.md index 0f5b0d30b..eda3822f3 100644 --- a/README.md +++ b/README.md @@ -114,11 +114,9 @@ You can always override the defaults or config file with CLI flags. To get the default config params run `mizu config`
To generate a new config file with default values use `mizu config -r` -Mizu has several undocumented flags which can be set by using --set flag (e.g., `mizu tap --set dump-logs=true`) -* **mizu-resources-namespace**: Type - String, See [Namespace-Restricted Mode](#namespace-restricted-mode) -* **telemetry**: Type - Boolean, Reports telemetry -* **dump-logs**: Type - Boolean, At the end of the execution it creates a zip file with logs (in .mizu folder) -* **kube-config-path**: Type - String, Setting the path to kube config (which isn't in standard path) +### Telemetry + +By default, mizu reports usage telemetry. It can be disabled by adding a line of telemetry: false in the ${HOME}/.mizu/config.yaml file ## Advanced Usage diff --git a/cli/cmd/tap.go b/cli/cmd/tap.go index 6e0da4a7a..a213d7f2e 100644 --- a/cli/cmd/tap.go +++ b/cli/cmd/tap.go @@ -60,10 +60,10 @@ func init() { defaults.Set(&defaultTapConfig) tapCmd.Flags().Uint16P(configStructs.GuiPortTapName, "p", defaultTapConfig.GuiPort, "Provide a custom port for the web interface webserver") - tapCmd.Flags().StringArrayP(configStructs.NamespacesTapName, "n", defaultTapConfig.Namespaces, "Namespaces selector") + tapCmd.Flags().StringSliceP(configStructs.NamespacesTapName, "n", defaultTapConfig.Namespaces, "Namespaces selector") tapCmd.Flags().Bool(configStructs.AnalysisTapName, defaultTapConfig.Analysis, "Uploads traffic to UP9 for further analysis (Beta)") tapCmd.Flags().BoolP(configStructs.AllNamespacesTapName, "A", defaultTapConfig.AllNamespaces, "Tap all namespaces") - tapCmd.Flags().StringArrayP(configStructs.PlainTextFilterRegexesTapName, "r", defaultTapConfig.PlainTextFilterRegexes, "List of regex expressions that are used to filter matching values from text/plain http bodies") + tapCmd.Flags().StringSliceP(configStructs.PlainTextFilterRegexesTapName, "r", defaultTapConfig.PlainTextFilterRegexes, "List of regex expressions that are used to filter matching values from text/plain http bodies") tapCmd.Flags().Bool(configStructs.DisableRedactionTapName, defaultTapConfig.DisableRedaction, "Disables redaction of potentially sensitive request/response headers and body values") tapCmd.Flags().String(configStructs.HumanMaxEntriesDBSizeTapName, defaultTapConfig.HumanMaxEntriesDBSize, "Override the default max entries db size") tapCmd.Flags().String(configStructs.DirectionTapName, defaultTapConfig.Direction, "Record traffic that goes in this direction (relative to the tapped pod): in/any") diff --git a/cli/cmd/tapRunner.go b/cli/cmd/tapRunner.go index 7325fcba5..43756cf59 100644 --- a/cli/cmd/tapRunner.go +++ b/cli/cmd/tapRunner.go @@ -70,7 +70,7 @@ func RunMizuTap() { targetNamespaces := getNamespaces(kubernetesProvider) var namespacesStr string - if targetNamespaces[0] != mizu.K8sAllNamespaces { + if !mizu.Contains(targetNamespaces, mizu.K8sAllNamespaces) { namespacesStr = fmt.Sprintf("namespaces \"%s\"", strings.Join(targetNamespaces, "\", \"")) } else { namespacesStr = "all namespaces" @@ -85,7 +85,7 @@ func RunMizuTap() { if len(state.currentlyTappedPods) == 0 { var suggestionStr string - if targetNamespaces[0] != mizu.K8sAllNamespaces { + if !mizu.Contains(targetNamespaces, mizu.K8sAllNamespaces) { suggestionStr = ". Select a different namespace with -n or tap all namespaces with -A" } mizu.Log.Warningf(uiUtils.Warning, fmt.Sprintf("Did not find any pods matching the regex argument%s", suggestionStr)) diff --git a/cli/mizu/config.go b/cli/mizu/config.go index bb6b9d65a..e8cbeea92 100644 --- a/cli/mizu/config.go +++ b/cli/mizu/config.go @@ -120,23 +120,36 @@ func initFlag(f *pflag.Flag) { } func mergeSetFlag(configElem reflect.Value, setValues []string) { + setMap := map[string][]string{} + for _, setValue := range setValues { if !strings.Contains(setValue, Separator) { Log.Warningf(uiUtils.Warning, fmt.Sprintf("Ignoring set argument %s (set argument format: =)", setValue)) + continue } split := strings.SplitN(setValue, Separator, 2) if len(split) != 2 { Log.Warningf(uiUtils.Warning, fmt.Sprintf("Ignoring set argument %s (set argument format: =)", setValue)) + continue } argumentKey, argumentValue := split[0], split[1] + setMap[argumentKey] = append(setMap[argumentKey], argumentValue) + } + + for argumentKey, argumentValues := range setMap { if !Contains(allowedSetFlags, argumentKey) { - Log.Warningf(uiUtils.Warning, fmt.Sprintf("Ignoring set argument %s, flag name must be one of the following: \"%s\"", setValue, strings.Join(allowedSetFlags, "\", \""))) + Log.Warningf(uiUtils.Warning, fmt.Sprintf("Ignoring set argument name \"%s\", flag name must be one of the following: \"%s\"", argumentKey, strings.Join(allowedSetFlags, "\", \""))) + continue } - mergeFlagValue(configElem, argumentKey, argumentValue) + if len(argumentValues) > 1 { + mergeFlagValues(configElem, argumentKey, argumentValues) + } else { + mergeFlagValue(configElem, argumentKey, argumentValues[0]) + } } } @@ -144,8 +157,9 @@ func mergeFlagValue(currentElem reflect.Value, flagKey string, flagValue string) for i := 0; i < currentElem.NumField(); i++ { currentField := currentElem.Type().Field(i) currentFieldByName := currentElem.FieldByName(currentField.Name) + currentFieldKind := currentField.Type.Kind() - if currentField.Type.Kind() == reflect.Struct { + if currentFieldKind == reflect.Struct { mergeFlagValue(currentFieldByName, flagKey, flagValue) continue } @@ -154,11 +168,14 @@ func mergeFlagValue(currentElem reflect.Value, flagKey string, flagValue string) continue } - flagValueKind := currentField.Type.Kind() + if currentFieldKind == reflect.Slice { + mergeFlagValues(currentElem, flagKey, []string{flagValue}) + return + } - parsedValue, err := getParsedValue(flagValueKind, flagValue) + parsedValue, err := getParsedValue(currentFieldKind, flagValue) if err != nil { - Log.Warningf(uiUtils.Red, fmt.Sprintf("Invalid value %v for flag name %s, expected %s", flagValue, flagKey, flagValueKind)) + Log.Warningf(uiUtils.Warning, fmt.Sprintf("Invalid value %s for flag name %s, expected %s", flagValue, flagKey, currentFieldKind)) return } @@ -170,8 +187,9 @@ func mergeFlagValues(currentElem reflect.Value, flagKey string, flagValues []str for i := 0; i < currentElem.NumField(); i++ { currentField := currentElem.Type().Field(i) currentFieldByName := currentElem.FieldByName(currentField.Name) + currentFieldKind := currentField.Type.Kind() - if currentField.Type.Kind() == reflect.Struct { + if currentFieldKind == reflect.Struct { mergeFlagValues(currentFieldByName, flagKey, flagValues) continue } @@ -180,13 +198,18 @@ func mergeFlagValues(currentElem reflect.Value, flagKey string, flagValues []str continue } + if currentFieldKind != reflect.Slice { + Log.Warningf(uiUtils.Warning, fmt.Sprintf("Invalid values %s for flag name %s, expected %s", strings.Join(flagValues, ","), flagKey, currentFieldKind)) + return + } + flagValueKind := currentField.Type.Elem().Kind() parsedValues := reflect.MakeSlice(reflect.SliceOf(currentField.Type.Elem()), 0, 0) for _, flagValue := range flagValues { parsedValue, err := getParsedValue(flagValueKind, flagValue) if err != nil { - Log.Warningf(uiUtils.Red, fmt.Sprintf("Invalid value %v for flag name %s, expected %s", flagValue, flagKey, flagValueKind)) + Log.Warningf(uiUtils.Warning, fmt.Sprintf("Invalid value %s for flag name %s, expected %s", flagValue, flagKey, flagValueKind)) return }