From 3baf38f823f3f071a3b1503f73f250e1a1175d57 Mon Sep 17 00:00:00 2001 From: isan_rivkin Date: Mon, 13 Feb 2023 10:08:07 +0200 Subject: [PATCH] Feature/ddb scan all keys (#21) enable match all in ddb --- cmd/ddb.go | 17 ++++++++++++++--- cmd/root.go | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/ddb.go b/cmd/ddb.go index 54f33f4..b322577 100644 --- a/cmd/ddb.go +++ b/cmd/ddb.go @@ -32,6 +32,7 @@ var ( tableNamePattern string ddbQuery string ddbOutputType string + ddbMatchAll *bool ddbIncludeGlobalTables *bool ddbListTables *bool ddbAllowAllTables *bool @@ -77,8 +78,12 @@ Search free text patterns inside Bytes, Binary, Protobuf, Base64 and Json format Run: func(cmd *cobra.Command, args []string) { if !*ddbListTables { - if ddbQuery == "" { - log.Fatalf("invalid output type %s only valid %v, use --help", ddbOutputType, validDDBOutputs) + if !*ddbMatchAll && ddbQuery == "" { + log.Fatalf("invalid query input empty, use --help or --all") + } + + if *ddbMatchAll && ddbQuery != "" { + log.Fatalf("invalid query input %s not empty used with --all, use --help", ddbQuery) } if _, exist := validDDBOutputs[ddbOutputType]; !exist { @@ -87,6 +92,7 @@ Search free text patterns inside Bytes, Binary, Protobuf, Base64 and Json format if !*ddbAllowAllTables && tableNamePattern == "" { log.Fatal("must use --all-tables explicitly or --table flag, use --help") } + } tui := buildTUI() // MARSHAL ATTRIBUTES UTILITY https://docs.aws.amazon.com/sdk-for-go/api/service/dynamodb/dynamodbattribute/ @@ -111,6 +117,10 @@ Search free text patterns inside Bytes, Binary, Protobuf, Base64 and Json format return } else { + if *ddbMatchAll { + ddbQuery = "\\..*" + } + parallel := 30 m := common.NewDefaultRegexMatcher() p := search.NewParserFactory() @@ -239,11 +249,12 @@ func init() { ddbCmd.PersistentFlags().StringVarP(&awsProfile, "profile", "p", getDefaultProfileEnvVar(), "~/.aws/credentials chosen account") ddbCmd.PersistentFlags().StringVarP(&awsRegion, "region", "r", "", "~/.aws/config default region if empty") - ddbCmd.PersistentFlags().StringVarP(&ddbQuery, "query", "q", "", "filter query regex supported") + ddbCmd.PersistentFlags().StringVarP(&ddbQuery, "query", "q", "", "filter query regex supported (if used with --all will error)") ddbCmd.PersistentFlags().StringVarP(&tableNamePattern, "table", "t", "", "regex table pattern name to match") ddbCmd.PersistentFlags().StringVarP(&ddbOutputType, "out", "o", "pretty", "output format [json, pretty]") ddbFailFast = ddbCmd.Flags().Bool("fail-fast", false, "fail on first error seen") ddbListTables = ddbCmd.Flags().Bool("list-tables", false, "list all available tables") + ddbMatchAll = ddbCmd.Flags().Bool("all", false, "match all data (same as using -q '\\\\..*') if used with --query will error") ddbIncludeGlobalTables = ddbCmd.Flags().Bool("include-global-tables", true, "if true will include global tables during search") ddbStopOnFirstMatch = ddbCmd.Flags().Bool("stop-first-match", false, "if true stop stop searching on first match found") sanitizeOutput = ddbCmd.Flags().Bool("sanitize", true, "if true will remove all non-ascii charts from outputs") diff --git a/cmd/root.go b/cmd/root.go index 55f6b6d..e975463 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -31,7 +31,7 @@ import ( ) const ( - AppVersion = "2.1.1" + AppVersion = "2.1.2" AppName = "surf" )