Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta prep #364

Merged
merged 16 commits into from
Nov 24, 2024
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PKG=github.com/rusq/slackdump/v3

LDFLAGS="-s -w -X 'main.commit=$(COMMIT)' -X 'main.version=$(BUILD)' -X 'main.date=$(BUILD_DATE)'"
OSES=linux darwin windows
DISTFILES=README.rst LICENSE
DISTFILES=README.md LICENSE
ZIPFILES=$(foreach s,$(OSES),$(OUTPUT)-$s.zip)


Expand Down Expand Up @@ -61,11 +61,6 @@ aurtest:
docker_test:
docker build .

man: slackdump.1

slackdump.1: README.rst
rst2man.py $< $@ --syntax-highlight=none

callvis:
go-callvis -group pkg,type -limit $(PKG) $(PKG)/cmd/slackdump

Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ If you were using `logger.Silent` before, you would need to
[slog-handler-guide]: https://github.com/golang/example/blob/master/slog-handler-guide/README.md
[godoc-slog-handler]: https://pkg.go.dev/log/slog#Handler

```go

## FAQ

#### Do I need to create a Slack application?
Expand Down
3 changes: 2 additions & 1 deletion cmd/slackdump/internal/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (
)

func RunArchive(ctx context.Context, cmd *base.Command, args []string) error {
start := time.Now()
list, err := structures.NewEntityList(args)
if err != nil {
base.SetExitStatus(base.SUserError)
Expand Down Expand Up @@ -84,7 +85,7 @@ func RunArchive(ctx context.Context, cmd *base.Command, args []string) error {
base.SetExitStatus(base.SApplicationError)
return err
}
lg.Info("Recorded workspace data", "filename", cd.Name())
lg.Info("Recorded workspace data", "filename", cd.Name(), "took", time.Since(start))

return nil
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/slackdump/internal/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ const (
)

var (
TraceFile string
LogFile string
JsonHandler bool
Verbose bool
AccessibleMode = (os.Getenv("ACCESSIBLE") != "" && os.Getenv("ACCESSIBLE") != "0")
TraceFile string
LogFile string
JsonHandler bool
Verbose bool

Output string
ConfigFile string
Expand Down
33 changes: 26 additions & 7 deletions cmd/slackdump/internal/diag/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package diag
import (
"context"
"encoding/json"
"log/slog"
"os"

"github.com/rusq/slackdump/v3/auth"
Expand All @@ -11,7 +12,7 @@ import (
"github.com/rusq/slackdump/v3/internal/edge"
)

var CmdEdge = &base.Command{
var cmdEdge = &base.Command{
Run: runEdge,
UsageLine: "slack tools edge",
Short: "Edge test",
Expand All @@ -29,7 +30,7 @@ var edgeParams = struct {
}{}

func init() {
CmdEdge.Flag.StringVar(&edgeParams.channel, "channel", "CHY5HUESG", "channel to get users from")
cmdEdge.Flag.StringVar(&edgeParams.channel, "channel", "CHY5HUESG", "channel to get users from")
}

func runEdge(ctx context.Context, cmd *base.Command, args []string) error {
Expand All @@ -49,12 +50,30 @@ func runEdge(ctx context.Context, cmd *base.Command, args []string) error {
defer cl.Close()
lg.Info("connected")

lg.Info("*** Search for Channels test ***")
channels, err := cl.SearchChannels(ctx, "")
if err != nil {
return err
// lg.Info("*** Search for Channels test ***")
// channels, err := cl.SearchChannels(ctx, "")
// if err != nil {
// return err
// }
// if err := save("channels.json", channels); err != nil {
// return err
// }

lg.Info("*** AdminEmojiList test ***")
var allEmoji edge.EmojiResult

var iter = 0
for res, err := range cl.AdminEmojiList(ctx) {
if err != nil {
return err
}
slog.Info("got emojis", "count", len(res.Emoji), "disabled", len(res.DisabledEmoji), "iter", iter)
iter++
allEmoji.Emoji = append(allEmoji.Emoji, res.Emoji...)
allEmoji.DisabledEmoji = append(allEmoji.DisabledEmoji, res.DisabledEmoji...)
}
if err := save("channels.json", channels); err != nil {

if err := save("emoji.json", allEmoji); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/slackdump/internal/diag/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ DKOKJRTJslrewS0MeTopOa/NUI5zC1z9GsqWBAzrbUU=
-----END PGP PUBLIC KEY BLOCK-----
`

var CmdEncrypt = &base.Command{
var cmdEncrypt = &base.Command{
Run: runEncrypt,
UsageLine: "slackdump tools encrypt [flags] file",
Short: "encrypts a file to post in github issues",
Expand Down Expand Up @@ -111,8 +111,8 @@ func init() {
if err := initRecipient(); err != nil {
panic(err)
}
CmdEncrypt.Flag.BoolVar(&gArm, "a", false, "shorthand for -armor")
CmdEncrypt.Flag.BoolVar(&gArm, "armor", false, "armor the output")
cmdEncrypt.Flag.BoolVar(&gArm, "a", false, "shorthand for -armor")
cmdEncrypt.Flag.BoolVar(&gArm, "armor", false, "armor the output")
}

func initRecipient() error {
Expand Down
12 changes: 6 additions & 6 deletions cmd/slackdump/internal/diag/eztest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base"
)

var CmdEzTest = &base.Command{
var cmdEzTest = &base.Command{
Run: runEzLoginTest,
UsageLine: "slack tools eztest",
Short: "EZ-Login 3000 test",
Expand Down Expand Up @@ -57,13 +57,13 @@ type eztestOpts struct {
var eztestFlags eztestOpts

func init() {
CmdEzTest.Flag.Usage = func() {
cmdEzTest.Flag.Usage = func() {
fmt.Fprint(os.Stdout, "usage: slackdump tools eztest [flags]\n\nFlags:\n")
CmdEzTest.Flag.PrintDefaults()
cmdEzTest.Flag.PrintDefaults()
}
CmdEzTest.Flag.BoolVar(&eztestFlags.printCreds, "p", false, "print credentials")
CmdEzTest.Flag.BoolVar(&eztestFlags.legacy, "legacy-browser", false, "run with playwright")
CmdEzTest.Flag.StringVar(&eztestFlags.wsp, "w", "", "Slack `workspace` to login to.")
cmdEzTest.Flag.BoolVar(&eztestFlags.printCreds, "p", false, "print credentials")
cmdEzTest.Flag.BoolVar(&eztestFlags.legacy, "legacy-browser", false, "run with playwright")
cmdEzTest.Flag.StringVar(&eztestFlags.wsp, "w", "", "Slack `workspace` to login to.")
}

func runEzLoginTest(ctx context.Context, cmd *base.Command, args []string) error {
Expand Down
6 changes: 3 additions & 3 deletions cmd/slackdump/internal/diag/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base"
)

// CmdInfo is the information command.
var CmdInfo = &base.Command{
// cmdInfo is the information command.
var cmdInfo = &base.Command{
UsageLine: "slackdump tools info",
Short: "show information about Slackdump environment",
Run: runInfo,
Expand All @@ -29,7 +29,7 @@ var infoParams = struct {
}

func init() {
CmdInfo.Flag.BoolVar(&infoParams.auth, "auth", false, "show authentication diagnostic information")
cmdInfo.Flag.BoolVar(&infoParams.auth, "auth", false, "show authentication diagnostic information")
}

func runInfo(ctx context.Context, cmd *base.Command, args []string) error {
Expand Down
22 changes: 11 additions & 11 deletions cmd/slackdump/internal/diag/obfuscate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"github.com/rusq/slackdump/v3/internal/chunk/obfuscate"
)

// CmdObfuscate is the command to obfuscate sensitive data in a slackdump
// cmdObfuscate is the command to obfuscate sensitive data in a slackdump
// recording.
var CmdObfuscate = &base.Command{
var cmdObfuscate = &base.Command{
UsageLine: "slackdump tools obfuscate [options] [input] [output]",
Short: "obfuscate sensitive data in a slackdump recording",
Long: `
Expand All @@ -36,10 +36,10 @@ var obfparam struct {
}

func init() {
CmdObfuscate.Run = runObfuscate
cmdObfuscate.Run = runObfuscate

CmdObfuscate.Flag.BoolVar(&obfparam.overwrite, "f", false, "force overwrite")
CmdObfuscate.Flag.Int64Var(&obfparam.seed, "seed", time.Now().UnixNano(), "seed for the random number generator")
cmdObfuscate.Flag.BoolVar(&obfparam.overwrite, "f", false, "force overwrite")
cmdObfuscate.Flag.Int64Var(&obfparam.seed, "seed", time.Now().UnixNano(), "seed for the random number generator")
}

const (
Expand Down Expand Up @@ -68,15 +68,15 @@ func objtype(name string) int {
}

func runObfuscate(ctx context.Context, cmd *base.Command, args []string) error {
if err := CmdObfuscate.Flag.Parse(args); err != nil {
if err := cmdObfuscate.Flag.Parse(args); err != nil {
return err
}

if CmdObfuscate.Flag.NArg() == 2 {
obfparam.input = CmdObfuscate.Flag.Arg(0)
obfparam.output = CmdObfuscate.Flag.Arg(1)
} else if CmdObfuscate.Flag.NArg() == 1 {
obfparam.input = CmdObfuscate.Flag.Arg(0)
if cmdObfuscate.Flag.NArg() == 2 {
obfparam.input = cmdObfuscate.Flag.Arg(0)
obfparam.output = cmdObfuscate.Flag.Arg(1)
} else if cmdObfuscate.Flag.NArg() == 1 {
obfparam.input = cmdObfuscate.Flag.Arg(0)
obfparam.output = "-"
} else {
obfparam.input = "-"
Expand Down
6 changes: 3 additions & 3 deletions cmd/slackdump/internal/diag/rawoutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/rusq/slackdump/v3/internal/structures"
)

var CmdRawOutput = &base.Command{
var cmdRawOutput = &base.Command{
Run: nil, // populated by init to break the init cycle
UsageLine: "slackdump tools rawoutput [flags] <id>",
Short: "record raw API output",
Expand Down Expand Up @@ -50,8 +50,8 @@ type rawOutputParams struct {
var p rawOutputParams

func init() {
CmdRawOutput.Run = runRawOutput
CmdRawOutput.Flag.StringVar(&p.output, "o", "slackdump_raw.log", "output file")
cmdRawOutput.Run = runRawOutput
cmdRawOutput.Flag.StringVar(&p.output, "o", "slackdump_raw.log", "output file")
}

func runRawOutput(ctx context.Context, cmd *base.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/slackdump/internal/diag/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/rusq/slackdump/v3/internal/chunk"
)

var CmdRecord = &base.Command{
var cmdRecord = &base.Command{
UsageLine: "slackdump tools record",
Short: "chunk record commands",
Commands: []*base.Command{cmdRecordStream, cmdRecordState},
Expand Down
16 changes: 8 additions & 8 deletions cmd/slackdump/internal/diag/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

var _ = godotenv.Load()

var CmdThread = &base.Command{
var cmdThread = &base.Command{
Run: nil,
UsageLine: "slackdump tools thread [flags]",
Short: "thread utilities",
Expand All @@ -33,19 +33,19 @@ testing, i.e. deletion of the threads, or generation of large threads.
}

func init() {
CmdThread.Run = runThread
CmdThread.Flag.Usage = func() {
cmdThread.Run = runThread
cmdThread.Flag.Usage = func() {
fmt.Fprint(os.Stdout, "usage: slackdump diag thread [flags]\n\nFlags:\n")
CmdThread.Flag.PrintDefaults()
cmdThread.Flag.PrintDefaults()
}
}

var (
// TODO: test with client auth.
token = CmdThread.Flag.String("app-token", os.Getenv("APP_TOKEN"), "Slack application or bot token")
channel = CmdThread.Flag.String("channel", osenv.Value("CHANNEL", ""), "channel to operate on")
numThreadMsg = CmdThread.Flag.Int("num", 2, "number of messages to generate in the thread")
delThread = CmdThread.Flag.String("del", "", "`URL` of the thread to delete")
token = cmdThread.Flag.String("app-token", os.Getenv("APP_TOKEN"), "Slack application or bot token")
channel = cmdThread.Flag.String("channel", osenv.Value("CHANNEL", ""), "channel to operate on")
numThreadMsg = cmdThread.Flag.Int("num", 2, "number of messages to generate in the thread")
delThread = cmdThread.Flag.String("del", "", "`URL` of the thread to delete")
)

func runThread(ctx context.Context, cmd *base.Command, args []string) error {
Expand Down
22 changes: 11 additions & 11 deletions cmd/slackdump/internal/diag/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ Tools command contains different tools, running which may be requested if you op
PrintFlags: false,
RequireAuth: false,
Commands: []*base.Command{
CmdEdge,
CmdEncrypt,
CmdEzTest,
CmdInfo,
CmdObfuscate,
CmdRawOutput,
CmdUninstall,
CmdRecord,
cmdSearch,
CmdThread,
CmdWizDebug,
// cmdEdge,
cmdEncrypt,
cmdEzTest,
cmdInfo,
cmdObfuscate,
// cmdRawOutput,
cmdUninstall,
// cmdRecord,
// cmdSearch,
cmdThread,
// cmdWizDebug,
},
}
Loading