Skip to content

Commit

Permalink
fixing the cookie display and add unwrap to oserr
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Dec 21, 2024
1 parent e949d68 commit 88ffd0b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
9 changes: 6 additions & 3 deletions cmd/slackdump/internal/diag/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions cmd/slackdump/internal/diag/info/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
6 changes: 4 additions & 2 deletions internal/edge/edge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

Expand Down
4 changes: 4 additions & 0 deletions internal/osext/osext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 88ffd0b

Please sign in to comment.