From 52bab14a563c8dfcabdc1726d7fc55df0a16b3aa Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 11 Jun 2021 12:27:58 -0300 Subject: [PATCH 1/2] Replace client-id with filter in logs commands --- internal/cli/logs.go | 50 ++++++++++++++++++++++++---------------- internal/cli/users.go | 2 +- internal/display/logs.go | 8 +++---- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/internal/cli/logs.go b/internal/cli/logs.go index d028a652e..48aee3270 100644 --- a/internal/cli/logs.go +++ b/internal/cli/logs.go @@ -10,11 +10,11 @@ import ( ) var ( - logsClientID = Flag{ - Name: "Client ID", - LongForm: "client-id", - ShortForm: "c", - Help: "Client Id of an Auth0 application to filter the logs.", + logsFilter = Flag{ + Name: "Filter", + LongForm: "filter", + ShortForm: "f", + Help: "Filter in Lucene query syntax. See https://auth0.com/docs/logs/log-search-query-syntax for more details.", } logsNum = Flag{ @@ -42,7 +42,7 @@ func logsCmd(cli *cli) *cobra.Command { func listLogsCmd(cli *cli) *cobra.Command { var inputs struct { - ClientID string + Filter string Num int } @@ -51,12 +51,17 @@ func listLogsCmd(cli *cli) *cobra.Command { Aliases: []string{"ls"}, Args: cobra.MaximumNArgs(1), Short: "Show the application logs", - Long: "Show the tenant logs allowing to filter by Client Id.", + Long: "Show the tenant logs allowing to filter using Lucene query syntax.", Example: `auth0 logs list -auth0 logs list --client-id +auth0 logs list --filter "client_id:" +auth0 logs list --filter "client_name:" +auth0 logs list --filter "user_id:" +auth0 logs list --filter "user_name:" +auth0 logs list --filter "ip:" +auth0 logs list --filter "type:f" # See the full list of type codes at https://auth0.com/docs/logs/log-event-type-codes auth0 logs ls -n 100`, RunE: func(cmd *cobra.Command, args []string) error { - list, err := getLatestLogs(cli, inputs.Num, inputs.ClientID) + list, err := getLatestLogs(cli, inputs.Num, inputs.Filter) if err != nil { return fmt.Errorf("An unexpected error occurred while getting logs: %v", err) } @@ -67,14 +72,14 @@ auth0 logs ls -n 100`, }, } - logsClientID.RegisterString(cmd, &inputs.ClientID, "") + logsFilter.RegisterString(cmd, &inputs.Filter, "") logsNum.RegisterInt(cmd, &inputs.Num, 100) return cmd } func tailLogsCmd(cli *cli) *cobra.Command { var inputs struct { - ClientID string + Filter string Num int } @@ -82,13 +87,18 @@ func tailLogsCmd(cli *cli) *cobra.Command { Use: "tail", Args: cobra.MaximumNArgs(1), Short: "Tail the tenant logs", - Long: "Tail the tenant logs allowing to filter by Client ID.", + Long: "Tail the tenant logs allowing to filter using Lucene query syntax.", Example: `auth0 logs tail -auth0 logs tail --client-id +auth0 logs tail --filter "client_id:" +auth0 logs tail --filter "client_name:" +auth0 logs tail --filter "user_id:" +auth0 logs tail --filter "user_name:" +auth0 logs tail --filter "ip:" +auth0 logs tail --filter "type:f" # See the full list of type codes at https://auth0.com/docs/logs/log-event-type-codes auth0 logs tail -n 100`, RunE: func(cmd *cobra.Command, args []string) error { lastLogID := "" - list, err := getLatestLogs(cli, inputs.Num, inputs.ClientID) + list, err := getLatestLogs(cli, inputs.Num, inputs.Filter) if err != nil { return fmt.Errorf("An unexpected error occurred while getting logs: %v", err) } @@ -119,8 +129,8 @@ auth0 logs tail -n 100`, management.Parameter("sort", "date:-1"), } - if inputs.ClientID != "" { - queryParams = append(queryParams, management.Query(fmt.Sprintf(`client_id:"%s"`, inputs.ClientID))) + if inputs.Filter != "" { + queryParams = append(queryParams, management.Query(inputs.Filter)) } list, err = cli.api.Log.List(queryParams...) @@ -147,12 +157,12 @@ auth0 logs tail -n 100`, }, } - logsClientID.RegisterString(cmd, &inputs.ClientID, "") + logsFilter.RegisterString(cmd, &inputs.Filter, "") logsNum.RegisterInt(cmd, &inputs.Num, 100) return cmd } -func getLatestLogs(cli *cli, n int, clientID string) ([]*management.Log, error) { +func getLatestLogs(cli *cli, n int, filter string) ([]*management.Log, error) { page := 0 perPage := n @@ -167,8 +177,8 @@ func getLatestLogs(cli *cli, n int, clientID string) ([]*management.Log, error) management.Parameter("page", fmt.Sprintf("%d", page)), management.Parameter("per_page", fmt.Sprintf("%d", perPage))} - if clientID != "" { - queryParams = append(queryParams, management.Query(fmt.Sprintf(`client_id:"%s"`, clientID))) + if filter != "" { + queryParams = append(queryParams, management.Query(filter)) } return cli.api.Log.List(queryParams...) diff --git a/internal/cli/users.go b/internal/cli/users.go index 03772155f..92da287a6 100644 --- a/internal/cli/users.go +++ b/internal/cli/users.go @@ -56,7 +56,7 @@ var ( Name: "Query", LongForm: "query", ShortForm: "q", - Help: "Query in Lucene query string syntax. See https://auth0.com/docs/users/user-search/user-search-query-syntax for more details.", + Help: "Query in Lucene query syntax. See https://auth0.com/docs/users/user-search/user-search-query-syntax for more details.", IsRequired: true, } userSort = Flag{ diff --git a/internal/display/logs.go b/internal/display/logs.go index 5a811b5f8..cd2e4b618 100644 --- a/internal/display/logs.go +++ b/internal/display/logs.go @@ -65,14 +65,14 @@ func (v *logView) AsTableRow() []string { conn := v.getConnection() if conn == notApplicable { - conn = ansi.Faint(truncate(conn, 25)) + conn = ansi.Faint(truncate(conn, 20)) } else { - conn = truncate(conn, 25) + conn = truncate(conn, 20) } return []string{ typ, - truncate(desc, 50), + truncate(desc, 54), ansi.Faint(truncate(timeAgo(v.GetDate()), 17)), conn, clientName, @@ -118,7 +118,7 @@ func (v *logView) typeDesc() (typ, desc string) { typ = "..." } - typ = truncate(chunks[0], 22) + typ = truncate(chunks[0], 23) if len(chunks) == 2 { desc = strings.TrimSuffix(chunks[1], ")") From 046c34392f8bb1db6da0f350ebef9f93a98502c5 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 11 Jun 2021 12:39:38 -0300 Subject: [PATCH 2/2] Re-generate docs --- docs/auth0_logs_list.md | 15 ++++++++++----- docs/auth0_logs_tail.md | 15 ++++++++++----- docs/auth0_users_search.md | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/docs/auth0_logs_list.md b/docs/auth0_logs_list.md index d0216d42a..d2d1755cf 100644 --- a/docs/auth0_logs_list.md +++ b/docs/auth0_logs_list.md @@ -1,6 +1,6 @@ ## auth0 logs list -Show the tenant logs allowing to filter by Client Id. +Show the tenant logs allowing to filter using Lucene query syntax. ``` auth0 logs list [flags] @@ -10,16 +10,21 @@ auth0 logs list [flags] ``` auth0 logs list -auth0 logs list --client-id +auth0 logs list --filter "client_id:" +auth0 logs list --filter "client_name:" +auth0 logs list --filter "user_id:" +auth0 logs list --filter "user_name:" +auth0 logs list --filter "ip:" +auth0 logs list --filter "type:f" # See the full list of type codes at https://auth0.com/docs/logs/log-event-type-codes auth0 logs ls -n 100 ``` ### Flags ``` - -c, --client-id string Client Id of an Auth0 application to filter the logs. - -h, --help help for list - -n, --number int Number of log entries to show. (default 100) + -f, --filter string Filter in Lucene query syntax. See https://auth0.com/docs/logs/log-search-query-syntax for more details. + -h, --help help for list + -n, --number int Number of log entries to show. (default 100) ``` ### Flags inherited from parent commands diff --git a/docs/auth0_logs_tail.md b/docs/auth0_logs_tail.md index 176e02d99..296b3fffa 100644 --- a/docs/auth0_logs_tail.md +++ b/docs/auth0_logs_tail.md @@ -1,6 +1,6 @@ ## auth0 logs tail -Tail the tenant logs allowing to filter by Client ID. +Tail the tenant logs allowing to filter using Lucene query syntax. ``` auth0 logs tail [flags] @@ -10,16 +10,21 @@ auth0 logs tail [flags] ``` auth0 logs tail -auth0 logs tail --client-id +auth0 logs tail --filter "client_id:" +auth0 logs tail --filter "client_name:" +auth0 logs tail --filter "user_id:" +auth0 logs tail --filter "user_name:" +auth0 logs tail --filter "ip:" +auth0 logs tail --filter "type:f" # See the full list of type codes at https://auth0.com/docs/logs/log-event-type-codes auth0 logs tail -n 100 ``` ### Flags ``` - -c, --client-id string Client Id of an Auth0 application to filter the logs. - -h, --help help for tail - -n, --number int Number of log entries to show. (default 100) + -f, --filter string Filter in Lucene query syntax. See https://auth0.com/docs/logs/log-search-query-syntax for more details. + -h, --help help for tail + -n, --number int Number of log entries to show. (default 100) ``` ### Flags inherited from parent commands diff --git a/docs/auth0_users_search.md b/docs/auth0_users_search.md index 1117cf24d..35aed5275 100644 --- a/docs/auth0_users_search.md +++ b/docs/auth0_users_search.md @@ -20,7 +20,7 @@ auth0 users search -q name -s "name:1" ``` -h, --help help for search - -q, --query string Query in Lucene query string syntax. See https://auth0.com/docs/users/user-search/user-search-query-syntax for more details. + -q, --query string Query in Lucene query syntax. See https://auth0.com/docs/users/user-search/user-search-query-syntax for more details. -s, --sort string Field to sort by. Use 'field:order' where 'order' is '1' for ascending and '-1' for descending. e.g. 'created_at:1'. ```