From 394d0cf429fd9c10a183744f34cb2968778ae849 Mon Sep 17 00:00:00 2001 From: "Kenan H.Hasanovic" Date: Tue, 19 Mar 2024 01:46:51 +0000 Subject: [PATCH 1/3] Default flag values for fastedge app logs and sort parameter sanitization --- internal/commands/fastedge/logs.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/internal/commands/fastedge/logs.go b/internal/commands/fastedge/logs.go index af00f3e..5be0b64 100644 --- a/internal/commands/fastedge/logs.go +++ b/internal/commands/fastedge/logs.go @@ -18,11 +18,11 @@ import ( ) func appLogsFilterFlags(cmd *cobra.Command) { - cmd.Flags().StringP("from", "", "", "From time") - cmd.Flags().StringP("to", "", "", "To time") - cmd.Flags().StringP("sort", "", "asc", "Sort order") - cmd.Flags().StringP("edge", "", "", "Edge name") - cmd.Flags().StringP("client-ip", "", "", "Client IP") + cmd.Flags().String("from", "today", "Reporting period start, UTC") + cmd.Flags().String("to", "now", "Reporting period end, UTC") + cmd.Flags().String("sort", "asc", "Log sort order, asc or desc") + cmd.Flags().String("edge", "", "Edge name filter") + cmd.Flags().String("client-ip", "", "Client IP filter") } // logs-related commands @@ -86,6 +86,9 @@ This command allows you filtering by edge name, client ip and time range.`, if sortFlag != "" { logParamSort := sdk.GetV1AppsIdLogsParamsSort(sortFlag) + if logParamSort != sdk.Asc && logParamSort != sdk.Desc { + return errors.New("invalid value for `sort` expected asc or desc") + } sort = &logParamSort } From bb5b7bb084d732bfbf1717d156727da980651003 Mon Sep 17 00:00:00 2001 From: "Kenan H.Hasanovic" Date: Tue, 19 Mar 2024 08:28:08 +0000 Subject: [PATCH 2/3] Mark fastedge apps flag as hidden --- internal/commands/fastedge/logs.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/commands/fastedge/logs.go b/internal/commands/fastedge/logs.go index 5be0b64..358f728 100644 --- a/internal/commands/fastedge/logs.go +++ b/internal/commands/fastedge/logs.go @@ -23,6 +23,7 @@ func appLogsFilterFlags(cmd *cobra.Command) { cmd.Flags().String("sort", "asc", "Log sort order, asc or desc") cmd.Flags().String("edge", "", "Edge name filter") cmd.Flags().String("client-ip", "", "Client IP filter") + cmd.Flags().MarkHidden("client-ip") } // logs-related commands From cedbc14c904b082d58dd3cfd9592465e44b016ee Mon Sep 17 00:00:00 2001 From: "Kenan H.Hasanovic" Date: Tue, 19 Mar 2024 09:09:20 +0000 Subject: [PATCH 3/3] Imporing proper packages for errors --- internal/commands/fastedge/logs.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/commands/fastedge/logs.go b/internal/commands/fastedge/logs.go index 9fd489d..809f012 100644 --- a/internal/commands/fastedge/logs.go +++ b/internal/commands/fastedge/logs.go @@ -3,6 +3,7 @@ package fastedge import ( "bufio" "context" + "errors" "fmt" "net/http" "os"