From 88ffd0bb7330eabf43de10eb810e934e5e1955b5 Mon Sep 17 00:00:00 2001 From: Rustam Gilyazov <16064414+rusq@users.noreply.github.com> Date: Sat, 21 Dec 2024 11:52:18 +1000 Subject: [PATCH] fixing the cookie display and add unwrap to oserr --- cmd/slackdump/internal/diag/info.go | 9 ++++++--- cmd/slackdump/internal/diag/info/auth.go | 9 +++------ internal/edge/edge_test.go | 6 ++++-- internal/osext/osext.go | 4 ++++ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/cmd/slackdump/internal/diag/info.go b/cmd/slackdump/internal/diag/info.go index f2c2c64c..d0d38e6a 100644 --- a/cmd/slackdump/internal/diag/info.go +++ b/cmd/slackdump/internal/diag/info.go @@ -6,15 +6,18 @@ import ( "io" "os" + "github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/diag/info" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base" ) // cmdInfo is the information command. var cmdInfo = &base.Command{ - UsageLine: "slackdump tools info", - Short: "show information about Slackdump environment", - Run: runInfo, + UsageLine: "slackdump tools info", + Short: "show information about Slackdump environment", + Run: runInfo, + FlagMask: cfg.OmitAll, + PrintFlags: true, Long: `# Info Command diff --git a/cmd/slackdump/internal/diag/info/auth.go b/cmd/slackdump/internal/diag/info/auth.go index b5814877..7e03092b 100644 --- a/cmd/slackdump/internal/diag/info/auth.go +++ b/cmd/slackdump/internal/diag/info/auth.go @@ -8,9 +8,9 @@ import ( "os" "path/filepath" "strings" - "text/tabwriter" "github.com/rusq/encio" + "github.com/rusq/slackdump/v3/auth" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg" "github.com/rusq/slackdump/v3/internal/cache" @@ -43,6 +43,7 @@ func CollectAuth(ctx context.Context, w io.Writer) error { if err != nil { return fmt.Errorf("cache error: %w", err) } + fmt.Fprintf(w, "TOKEN=%s\n", prov.Token) if err := dumpCookiesMozilla(ctx, w, prov.Cookies()); err != nil { return err } @@ -51,12 +52,8 @@ func CollectAuth(ctx context.Context, w io.Writer) error { // dumpCookiesMozilla dumps cookies in Mozilla format. func dumpCookiesMozilla(_ context.Context, w io.Writer, cookies []*http.Cookie) error { - tw := tabwriter.NewWriter(w, 0, 8, 0, '\t', 0) - defer tw.Flush() - fmt.Fprintf(tw, "# name@domain\tvalue_len\tflag\tpath\tsecure\texpiration\n") for _, c := range cookies { - fmt.Fprintf(tw, "%s\t%9d\t%s\t%s\t%s\t%d\n", - c.Name+"@"+c.Domain, len(c.Value), "TRUE", c.Path, strings.ToUpper(fmt.Sprintf("%v", c.Secure)), c.Expires.Unix()) + fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\t%s\t%s\n", c.Domain, "TRUE", c.Path, strings.ToUpper(fmt.Sprintf("%v", c.Secure)), c.Expires.Unix(), c.Name, c.Value) } return nil } diff --git a/internal/edge/edge_test.go b/internal/edge/edge_test.go index b222a730..7ff1bf07 100644 --- a/internal/edge/edge_test.go +++ b/internal/edge/edge_test.go @@ -11,14 +11,16 @@ import ( "testing" "github.com/joho/godotenv" - "github.com/rusq/slackdump/v3/auth" "github.com/stretchr/testify/assert" + + "github.com/rusq/slackdump/v3/auth" ) var _ = godotenv.Load() var ( - testToken = os.Getenv("EDGE_TOKEN)") + // preferrably guest workspace token. + testToken = os.Getenv("EDGE_TOKEN") testCookie = os.Getenv("EDGE_COOKIE") ) diff --git a/internal/osext/osext.go b/internal/osext/osext.go index 2b8ebfca..a1cde33a 100644 --- a/internal/osext/osext.go +++ b/internal/osext/osext.go @@ -16,6 +16,10 @@ func (e *Error) Error() string { return fmt.Sprintf("%s: %s", e.Err, e.File) } +func (e *Error) Unwrap() error { + return e.Err +} + // Namer is an interface that allows us to get the name of the file. type Namer interface { // Name should return the name of the file. *os.File implements this