-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
148 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Workspace Import Command | ||
|
||
**Import** allows you to import credentials from a .env or secrets.txt file. | ||
|
||
It requires the file to have the following format: | ||
``` | ||
SLACK_TOKEN=xoxc-... | ||
SLACK_COOKIE=xoxd-... | ||
``` | ||
|
||
`SLACK_TOKEN` can be one of the following: | ||
|
||
- xoxa-...: app token | ||
- xoxb-...: bot token | ||
- xoxc-...: client token | ||
- xoxe-...: export token | ||
- xoxp-...: legacy user token | ||
|
||
`SLACK_COOKIE` is only required, if the `SLACK_TOKEN` is a client type token | ||
(starts with `xoxc-`). | ||
|
||
It will test the provided credentials, and if successful, encrypt and save | ||
them to the to the slackdump credential storage. It is recommended to delete | ||
the .env file afterwards. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Workspace List Command | ||
|
||
**List** allows to list Slack Workspaces, that you have previously | ||
authenticated in. It supports several output formats: | ||
- full (default): outputs workspace names, filenames, and last modification. | ||
- bare: outputs just workspace names, with the current workspace marked with | ||
an asterisk. | ||
- all: outputs all information, including the team name and the user name for | ||
each workspace. | ||
|
||
If the "all" listing is requested, Slackdump will interrogate the Slack API to | ||
get the team name and the user name for each workspace. This may take some | ||
time, as it involves multiple network requests, depending on your network | ||
speed and the number of workspaces. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package workspace | ||
|
||
import ( | ||
"context" | ||
_ "embed" | ||
"errors" | ||
|
||
"github.com/rusq/slackdump/v3/auth" | ||
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg" | ||
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base" | ||
"github.com/rusq/slackdump/v3/internal/cache" | ||
) | ||
|
||
//go:embed assets/import.md | ||
var importMd string | ||
|
||
var CmdImport = &base.Command{ | ||
UsageLine: baseCommand + " import [flags] filename", | ||
Short: "import credentials from .env or secrets.txt file", | ||
Long: importMd, | ||
FlagMask: flagmask, | ||
PrintFlags: true, | ||
Run: cmdRunImport, | ||
RequireAuth: false, | ||
} | ||
|
||
func cmdRunImport(ctx context.Context, cmd *base.Command, args []string) error { | ||
if len(args) != 1 { | ||
base.SetExitStatus(base.SInvalidParameters) | ||
return errors.New("missing filename") | ||
} | ||
|
||
filename := args[0] | ||
|
||
if err := importFile(ctx, filename); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func importFile(ctx context.Context, filename string) error { | ||
token, cookies, err := auth.ParseDotEnv(filename) | ||
if err != nil { | ||
base.SetExitStatus(base.SUserError) | ||
return err | ||
} | ||
m, err := cache.NewManager(cfg.CacheDir()) | ||
if err != nil { | ||
base.SetExitStatus(base.SCacheError) | ||
return err | ||
} | ||
prov, err := auth.NewValueAuth(token, cookies) | ||
if err != nil { | ||
base.SetExitStatus(base.SAuthError) | ||
return err | ||
} | ||
wsp, err := m.CreateAndSelect(ctx, prov) | ||
if err != nil { | ||
base.SetExitStatus(base.SCacheError) | ||
return err | ||
} | ||
cfg.Log.Printf("Workspace %q added and selected. It is advised that you delete the file %q", wsp, filename) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters