Skip to content

Commit

Permalink
get rid of auth.Type
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Jan 14, 2024
1 parent a51e728 commit 09723a1
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 82 deletions.
14 changes: 0 additions & 14 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,6 @@ import (

const SlackURL = "https://slack.com"

// Type is the auth type.
//
//go:generate stringer -type Type -linecomment
type Type uint8

// All supported auth types.
const (
TypeInvalid Type = iota // Invalid
TypeValue // Value
TypeCookieFile // Cookie File
TypeBrowser // EZ-Login 3000
TypeRod // EZ-Login 3001
)

// Provider is the Slack Authentication provider.
//
//go:generate mockgen -destination ../internal/mocks/mock_auth/mock_auth.go github.com/rusq/slackdump/v3/auth Provider
Expand Down
4 changes: 0 additions & 4 deletions auth/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,3 @@ func NewBrowserAuth(ctx context.Context, opts ...Option) (BrowserAuth, error) {
}
return br, nil
}

func (BrowserAuth) Type() Type {
return TypeBrowser
}
4 changes: 0 additions & 4 deletions auth/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ type fakeProvider struct {
simpleProvider
}

func (fakeProvider) Type() Type {
return Type(99)
}

var fakeTestProvider = &fakeProvider{simpleProvider{Token: "test"}}

var (
Expand Down
4 changes: 0 additions & 4 deletions auth/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,3 @@ func NewCookieFileAuth(token string, cookieFile string) (CookieFileAuth, error)
}
return fc, nil
}

func (CookieFileAuth) Type() Type {
return TypeCookieFile
}
4 changes: 0 additions & 4 deletions auth/rod.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ type RodAuth struct {
opts options
}

func (p RodAuth) Type() Type {
return TypeRod
}

type rodOpts struct {
ui browserAuthUIExt
}
Expand Down
27 changes: 0 additions & 27 deletions auth/type_string.go

This file was deleted.

4 changes: 0 additions & 4 deletions auth/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ func NewValueAuth(token string, cookie string) (ValueAuth, error) {
return c, nil
}

func (ValueAuth) Type() Type {
return TypeValue
}

var timeFunc = time.Now

func makeCookie(key, val string) *http.Cookie {
Expand Down
30 changes: 20 additions & 10 deletions internal/cache/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,37 @@ var (
ErrUnsupported = errors.New("" + ezLogin + " is not supported on this OS, please use the manual login method")
)

type AuthType int

const (
ATInvalid AuthType = iota
ATValue
ATCookieFile
ATRod
ATBrowser
)

// 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.
func (c SlackCreds) Type(ctx context.Context) (auth.Type, error) {
func (c SlackCreds) Type(ctx context.Context) (AuthType, error) {
if !c.IsEmpty() {
if isExistingFile(c.Cookie) {
return auth.TypeCookieFile, nil
return ATCookieFile, nil
}
return auth.TypeValue, nil
return ATValue, nil
}

if !ezLoginSupported() {
return auth.TypeInvalid, ErrUnsupported
return ATInvalid, ErrUnsupported
}
if !ezLoginTested() {
return auth.TypeRod, ErrNotTested
return ATRod, ErrNotTested
}
return auth.TypeRod, nil
return ATRod, nil

}

Expand All @@ -75,13 +85,13 @@ func (c SlackCreds) AuthProvider(ctx context.Context, workspace string, opts ...
opts = append([]auth.Option{auth.BrowserWithWorkspace(workspace)}, opts...)

switch authType {
case auth.TypeBrowser:
case ATBrowser:
return auth.NewBrowserAuth(ctx, opts...)
case auth.TypeCookieFile:
case ATCookieFile:
return auth.NewCookieFileAuth(c.Token, c.Cookie)
case auth.TypeValue:
case ATValue:
return auth.NewValueAuth(c.Token, c.Cookie)
case auth.TypeRod:
case ATRod:
return auth.NewRODAuth(ctx, opts...)
}
return nil, errors.New("internal error: unsupported auth type")
Expand Down
8 changes: 4 additions & 4 deletions internal/cache/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ func TestSlackCreds_Type(t *testing.T) {
name string
fields fields
args args
want auth.Type
want AuthType
wantErr bool
}
tests := []test{
{"value", fields{Token: "t", Cookie: "c"}, args{context.Background()}, auth.TypeValue, false},
{"cookie file", fields{Token: "t", Cookie: testFile}, args{context.Background()}, auth.TypeCookieFile, false},
{"value", fields{Token: "t", Cookie: "c"}, args{context.Background()}, ATValue, false},
{"cookie file", fields{Token: "t", Cookie: testFile}, args{context.Background()}, ATCookieFile, false},
}
if !isWSL {
tests = append(tests, test{"browser", fields{Token: "", Cookie: ""}, args{context.Background()}, auth.TypeBrowser, false})
tests = append(tests, test{"browser", fields{Token: "", Cookie: ""}, args{context.Background()}, ATRod, false})
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
7 changes: 0 additions & 7 deletions internal/chunk/chunktest/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package chunktest
import (
"context"
"net/http"

"github.com/rusq/slackdump/v3/auth"
)

// TestAuth to use with the chunktest server.
Expand All @@ -27,11 +25,6 @@ func (a *TestAuth) Cookies() []*http.Cookie {
return nil
}

// Type returns the auth type.
func (a *TestAuth) Type() auth.Type {
return auth.Type(255)
}

// Validate should return error, in case the token or cookies cannot be
// retrieved.
func (a *TestAuth) Validate() error {
Expand Down

0 comments on commit 09723a1

Please sign in to comment.