cache

package
v3.0.0-...-642363e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotTested   = errors.New("warning, " + ezLogin + " is not tested on this OS, if it doesn't work, use manual login method")
	ErrUnsupported = errors.New("" + ezLogin + " is not supported on this OS, please use the manual login method")
)
View Source
var (
	ErrEmpty   = errors.New("empty cache file")
	ErrExpired = errors.New("cache expired")
)
View Source
var (
	ErrNoWorkspaces = errors.New("no saved workspaces")
	ErrNameRequired = errors.New("workspace name is required")
	ErrNoDefault    = errors.New("default workspace not set")
)

Functions

func AuthReset

func AuthReset(cacheDir string) error

AuthReset removes the cached credentials.

func EzLoginFlags

func EzLoginFlags() map[string]bool

EZLoginFlags is a diagnostic function that returns the map of flags that describe the EZ-Login feature.

func ReadUsers

func ReadUsers(r io.Reader) (types.Users, error)

Types

type AuthData

type AuthData struct {
	Token         string
	Cookie        string
	UsePlaywright bool
}

AuthData is the authentication data.

func (AuthData) AuthProvider

func (c AuthData) AuthProvider(ctx context.Context, workspace string, opts ...auth.Option) (auth.Provider, error)

AuthProvider returns the appropriate auth Provider depending on the values of the token and cookie.

func (AuthData) IsEmpty

func (c AuthData) IsEmpty() bool

func (AuthData) Type

func (c AuthData) Type(context.Context) (AuthType, error)

Type returns the authentication type that should be used for the current slack creds. If the auth type wasn't tested on the system that the slackdump is being executed on it will return the valid type and ErrNotTested, so that this unfortunate fact could be relayed to the end-user. If the type of the authentication determined is not supported for the current system, it will return ErrUnsupported.

type AuthType

type AuthType int
const (
	ATInvalid AuthType = iota
	ATValue
	ATCookieFile
	ATRod
	ATPlaywright
)

type Credentials

type Credentials interface {
	IsEmpty() bool
	AuthProvider(ctx context.Context, workspace string, opts ...auth.Option) (auth.Provider, error)
}

type ErrWorkspace

type ErrWorkspace struct {
	Workspace string
	Message   string
	Err       error
}

ErrWorkspace is the error returned by the workspace manager, it contains the workspace name, the error message and the underlying error.

func (*ErrWorkspace) Error

func (ew *ErrWorkspace) Error() string

func (*ErrWorkspace) Unwrap

func (ew *ErrWorkspace) Unwrap() error

Unwrap returns the underlying error.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is the workspace manager. It is an abstraction over the directory with files with credentials for Slack workspaces.

There are several types of files that one could find in the managed directory:

  • "provider.bin" - the default workspace file, it contains the credentials for the "default" workspace. It exists for historical reasons, for migration from the previous version of the slackdump. It contains credentials for the workspace that slackdump v2 was authenticated in.
  • "*.bin" - other workspaces, the filename is the name of the workspace.
  • "workspace.txt" - a pointer to the current workspace, it contains the current workspace name.
  • "*.cache" - cache files, they contain the cache for users and channels.

func NewManager

func NewManager(dir string, opts ...Option) (*Manager, error)

NewManager creates a new workspace manager over the directory dir. The directory is created with rwx------ permissions, if it does not exist.

TODO: test with empty dir.

func (*Manager) Auth

func (m *Manager) Auth(ctx context.Context, name string, c Credentials) (auth.Provider, error)

Auth authenticates in the Slack Workspace "name" and saves credentials to the relevant file. It initialises the auth.Provider depending on provided slack credentials. It returns auth.Provider or an error. The logic diagram is available in the doc/diagrams/auth_flow.puml.

If the creds is empty, it attempts to load the stored credentials. If it finds them, it returns an initialised credentials provider. If not - it returns the auth provider according to the type of credentials determined by creds.AuthProvider, and saves them to an AES-256-CFB encrypted storage.

The storage is encrypted using the hash of the unique machine-ID, supplied by the operating system (see package encio), it makes it impossible use the stored credentials on another machine (including virtual), even another operating system on the same machine, unless it's a clone of the source operating system on which the credentials storage was created.

func (*Manager) CacheChannels

func (m *Manager) CacheChannels(teamID string, cc []slack.Channel) error

CacheChannels saves channels to cache.

func (*Manager) CacheUsers

func (m *Manager) CacheUsers(teamID string, uu []slack.User) error

CacheUsers saves users to user cache file for teamID.

func (*Manager) Current

func (m *Manager) Current() (string, error)

Current returns the current workspace name.

func (*Manager) Delete

func (m *Manager) Delete(name string) error

Delete deletes the workspace file.

func (*Manager) Exists

func (m *Manager) Exists(name string) bool

Exists returns true if the workspace with name "name" exists in the list of authenticated workspaces.

func (*Manager) FileInfo

func (m *Manager) FileInfo(name string) (fs.FileInfo, error)

FileInfo returns the container file information for the workspace.

func (*Manager) HasDefault

func (m *Manager) HasDefault() bool

func (*Manager) List

func (m *Manager) List() ([]string, error)

func (*Manager) LoadChannels

func (m *Manager) LoadChannels(teamID string, maxAge time.Duration) ([]slack.Channel, error)

LoadChannels loads channel cache no older than maxAge.

func (*Manager) LoadUsers

func (m *Manager) LoadUsers(teamID string, maxAge time.Duration) ([]slack.User, error)

LoadUsers loads user cache file no older than maxAge for teamID.

func (*Manager) Select

func (m *Manager) Select(name string) error

Select selects the existing workspace with "name".

func (*Manager) WalkUsers

func (m *Manager) WalkUsers(userFn func(path string, r io.Reader) error) error

WalkUsers scans the cache directory and calls userFn for each user file discovered.

type Option

type Option func(m *Manager)

func WithAuthOpts

func WithAuthOpts(opts ...auth.Option) Option

WithAuthOpts allows to change the default Auth options, they will be passed to auth package..

func WithChannelCacheBase

func WithChannelCacheBase(filename string) Option

WithChannelCacheBase allows to change the default cache file name for channels cache.

func WithUserCacheBase

func WithUserCacheBase(filename string) Option

WithUserCacheBase allows to change the default base name of "users.cache". If the filename is empty it's a noop. If the filename does not contain extension, ".cache" is appended.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL