auth

package
v0.0.0-...-c693443 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthInterface

type AuthInterface interface {
	// AuthWithToken collects authentication information for the provided token
	AuthWithToken(ctx context.Context, token string) (types.SlackAuth, error)
	// AuthWithTeamDomain finds an auth with a given team domain
	//
	// FIXME: This is an unsafe method, since team domain does not guarantee unique auth if org and workspace are named the same
	AuthWithTeamDomain(ctx context.Context, teamDomain string) (types.SlackAuth, error)
	// AuthWithTeamID finds an auth with a given team ID
	AuthWithTeamID(ctx context.Context, teamID string) (types.SlackAuth, error)
	// Auths returns all the user's authorizatons as a slice
	Auths(ctx context.Context) ([]types.SlackAuth, error)

	// SetAuth will write new or overwrite existing auth record in credentials.json with provided auth
	SetAuth(ctx context.Context, auth types.SlackAuth) (types.SlackAuth, string, error)
	// SetSelectedAuth updates API configurations with relevant authentication details
	SetSelectedAuth(ctx context.Context, auth types.SlackAuth, config *config.Config, os types.Os)

	// DeleteAuth removes an auth from the list of auths in credentials.json
	DeleteAuth(context.Context, types.SlackAuth) (types.SlackAuth, error)
	// RevokeToken removes access for a given token, filtering known and safe errors
	RevokeToken(ctx context.Context, token string) error

	// ResolveAPIHost returns the API Host based on the API Host Flag, Dev Flag, Project Config, and Stored Auth API Host.
	ResolveAPIHost(ctx context.Context, apiHostFlag string, customAuth *types.SlackAuth) string
	// ResolveLogstashHost returns the error log stash host based on API Host and CLI version from context
	ResolveLogstashHost(ctx context.Context, apiHost string) string

	// MapAuthTokensToDomains groups tokens by API host then delineates the host
	MapAuthTokensToDomains(ctx context.Context) string

	// IsAPIHostSlackProd returns true if host is a development endpoint target
	IsAPIHostSlackDev(host string) bool
	// IsAPIHostSlackProd returns true if host is the production endpoint target
	IsAPIHostSlackProd(host string) bool

	// FilterKnownAuthErrors catches known error codes that can be ignored to allow
	// the process to proceed safely without exiting.
	FilterKnownAuthErrors(ctx context.Context, err error) (bool, error)
}

type AuthMock

type AuthMock struct {
	mock.Mock
}

func (*AuthMock) AddDefaultMocks

func (m *AuthMock) AddDefaultMocks()

func (*AuthMock) AuthWithTeamDomain

func (m *AuthMock) AuthWithTeamDomain(ctx context.Context, teamDomain string) (types.SlackAuth, error)

func (*AuthMock) AuthWithTeamID

func (m *AuthMock) AuthWithTeamID(ctx context.Context, teamID string) (types.SlackAuth, error)

func (*AuthMock) AuthWithToken

func (m *AuthMock) AuthWithToken(ctx context.Context, token string) (types.SlackAuth, error)

func (*AuthMock) Auths

func (m *AuthMock) Auths(ctx context.Context) ([]types.SlackAuth, error)

func (*AuthMock) DeleteAuth

func (m *AuthMock) DeleteAuth(ctx context.Context, auth types.SlackAuth) (types.SlackAuth, error)

func (*AuthMock) FilterKnownAuthErrors

func (m *AuthMock) FilterKnownAuthErrors(ctx context.Context, err error) (bool, error)

func (*AuthMock) IsAPIHostSlackDev

func (m *AuthMock) IsAPIHostSlackDev(host string) bool

func (*AuthMock) IsAPIHostSlackProd

func (m *AuthMock) IsAPIHostSlackProd(host string) bool

func (*AuthMock) MapAuthTokensToDomains

func (m *AuthMock) MapAuthTokensToDomains(ctx context.Context) string

func (*AuthMock) ResolveAPIHost

func (m *AuthMock) ResolveAPIHost(ctx context.Context, apiHostFlag string, customAuth *types.SlackAuth) string

func (*AuthMock) ResolveLogstashHost

func (m *AuthMock) ResolveLogstashHost(ctx context.Context, apiHost string) string

func (*AuthMock) RevokeToken

func (m *AuthMock) RevokeToken(ctx context.Context, token string) error

func (*AuthMock) SetAuth

func (m *AuthMock) SetAuth(ctx context.Context, auth types.SlackAuth) (types.SlackAuth, string, error)

func (*AuthMock) SetSelectedAuth

func (m *AuthMock) SetSelectedAuth(ctx context.Context, auth types.SlackAuth, config *config.Config, os types.Os)

type Client

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

Client can manage the state of the system's user/workspace authentications.

func NewClient

func NewClient(apiClient api.APIInterface, appClient *app.Client, config *config.Config, io iostreams.IOStreamer, fs afero.Fs) *Client

NewClient returns a new, empty instance of the Client

func (*Client) AuthWithTeamDomain

func (c *Client) AuthWithTeamDomain(ctx context.Context, teamDomain string) (types.SlackAuth, error)

Getters AuthWithTeamDomain finds an auth with a given team domain FIXME: This is an unsafe method, since team domain does not guarantee unique auth if org and workspace are named the same

TODO: Deprecate

func (*Client) AuthWithTeamID

func (c *Client) AuthWithTeamID(ctx context.Context, teamID string) (types.SlackAuth, error)

AuthWithTeamID finds an auth with a given team ID

func (*Client) AuthWithToken

func (c *Client) AuthWithToken(ctx context.Context, token string) (types.SlackAuth, error)

AuthWithToken collects authentication information for the provided token

func (*Client) Auths

func (c *Client) Auths(ctx context.Context) ([]types.SlackAuth, error)

Auths returns all the user's authorizatons as a slice Use this method outside this package to fetch a users cli authorizations

func (*Client) DeleteAuth

func (c *Client) DeleteAuth(ctx context.Context, auth types.SlackAuth) (types.SlackAuth, error)

DeleteAuth removes an auth from the list of auths in credentials.json

func (*Client) FilterKnownAuthErrors

func (c *Client) FilterKnownAuthErrors(ctx context.Context, err error) (bool, error)

FilterKnownAuthErrors catches certain error codes that indicate an API error related to authentication happened, but the error might allow the process to proceed without exiting.

If an error is caught with this filter, a "true" boolean is returned without the caught error. If no error is caught, this boolean will be "false" and the provided error is returned.

Errors that are not caught should prevent certain commands from completing, such as deleting local authentication records with the "logout" command.

func (*Client) IsAPIHostSlackDev

func (c *Client) IsAPIHostSlackDev(host string) bool

IsAPIHostSlackDev returns true if host is the Slack Dev endpoint (dev.slack.com, https://dev1234.api.slack.com, etc)

func (*Client) IsAPIHostSlackProd

func (c *Client) IsAPIHostSlackProd(host string) bool

TODO (@kian) Make our Auths storage and checking convention consistent.Should this function also account for the nil case (ie. no host specified) being a prod auth? Either we should always save the api hostname even when it's a prod auth, or we should update this function to also return true if the api hostname is empty/undefined IsAPIHostSlackProd returns true if host is the production endpoint target.

func (*Client) MapAuthTokensToDomains

func (c *Client) MapAuthTokensToDomains(ctx context.Context) string

MapAuthTokensToDomains creates a delimited string of tokens for each api domain included in the available login contexts. If there are multiple login contexts for the the same api domain, the last one wins. It doesn't matter we just need one to be valid.

func (*Client) ResolveAPIHost

func (c *Client) ResolveAPIHost(ctx context.Context, apiHostFlag string, customAuth *types.SlackAuth) string

ResolveAPIHost returns the API Host based on the API Host Flag, Dev Flag, Project Config, and Stored Auth API Host.

func (*Client) ResolveLogstashHost

func (c *Client) ResolveLogstashHost(ctx context.Context, apiHost string) string

TODO: how does this play together with ResolveAPIHost above? ResolveLogstashHost returns the error log stash host based on API Host and CLI version

func (*Client) RevokeToken

func (c *Client) RevokeToken(ctx context.Context, token string) error

RevokeToken revokes API access of the given token

An error is returned if the revoking request failed for a reason unrelated to expired or a somehow invalid authentication. That error should not be ignored since it might mean the token was not revoked.

func (*Client) SetAuth

func (c *Client) SetAuth(ctx context.Context, auth types.SlackAuth) (types.SlackAuth, string, error)

SetAuth will write new or overwrite existing auth record in credentials.json with provided auth

func (*Client) SetSelectedAuth

func (c *Client) SetSelectedAuth(ctx context.Context, auth types.SlackAuth, config *config.Config, os types.Os)

SetSelectedAuth updates API configurations with relevant authentication details

Jump to

Keyboard shortcuts

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