Documentation
¶
Index ¶
- type AuthInterface
- type AuthMock
- func (m *AuthMock) AddDefaultMocks()
- func (m *AuthMock) AuthWithTeamDomain(ctx context.Context, teamDomain string) (types.SlackAuth, error)
- func (m *AuthMock) AuthWithTeamID(ctx context.Context, teamID string) (types.SlackAuth, error)
- func (m *AuthMock) AuthWithToken(ctx context.Context, token string) (types.SlackAuth, error)
- func (m *AuthMock) Auths(ctx context.Context) ([]types.SlackAuth, error)
- func (m *AuthMock) DeleteAuth(ctx context.Context, auth types.SlackAuth) (types.SlackAuth, error)
- func (m *AuthMock) FilterKnownAuthErrors(ctx context.Context, err error) (bool, error)
- func (m *AuthMock) IsAPIHostSlackDev(host string) bool
- func (m *AuthMock) IsAPIHostSlackProd(host string) bool
- func (m *AuthMock) MapAuthTokensToDomains(ctx context.Context) string
- func (m *AuthMock) ResolveAPIHost(ctx context.Context, apiHostFlag string, customAuth *types.SlackAuth) string
- func (m *AuthMock) ResolveLogstashHost(ctx context.Context, apiHost string) string
- func (m *AuthMock) RevokeToken(ctx context.Context, token string) error
- func (m *AuthMock) SetAuth(ctx context.Context, auth types.SlackAuth) (types.SlackAuth, string, error)
- func (m *AuthMock) SetSelectedAuth(ctx context.Context, auth types.SlackAuth, config *config.Config, os types.Os)
- type Client
- func (c *Client) AuthWithTeamDomain(ctx context.Context, teamDomain string) (types.SlackAuth, error)
- func (c *Client) AuthWithTeamID(ctx context.Context, teamID string) (types.SlackAuth, error)
- func (c *Client) AuthWithToken(ctx context.Context, token string) (types.SlackAuth, error)
- func (c *Client) Auths(ctx context.Context) ([]types.SlackAuth, error)
- func (c *Client) DeleteAuth(ctx context.Context, auth types.SlackAuth) (types.SlackAuth, error)
- func (c *Client) FilterKnownAuthErrors(ctx context.Context, err error) (bool, error)
- func (c *Client) IsAPIHostSlackDev(host string) bool
- func (c *Client) IsAPIHostSlackProd(host string) bool
- func (c *Client) MapAuthTokensToDomains(ctx context.Context) string
- func (c *Client) ResolveAPIHost(ctx context.Context, apiHostFlag string, customAuth *types.SlackAuth) string
- func (c *Client) ResolveLogstashHost(ctx context.Context, apiHost string) string
- func (c *Client) RevokeToken(ctx context.Context, token string) error
- func (c *Client) SetAuth(ctx context.Context, auth types.SlackAuth) (types.SlackAuth, string, error)
- func (c *Client) SetSelectedAuth(ctx context.Context, auth types.SlackAuth, config *config.Config, os types.Os)
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 ¶
func (*AuthMock) AddDefaultMocks ¶
func (m *AuthMock) AddDefaultMocks()
func (*AuthMock) AuthWithTeamDomain ¶
func (*AuthMock) AuthWithTeamID ¶
func (*AuthMock) AuthWithToken ¶
func (*AuthMock) DeleteAuth ¶
func (*AuthMock) FilterKnownAuthErrors ¶
func (*AuthMock) IsAPIHostSlackDev ¶
func (*AuthMock) IsAPIHostSlackProd ¶
func (*AuthMock) MapAuthTokensToDomains ¶
func (*AuthMock) ResolveAPIHost ¶
func (*AuthMock) ResolveLogstashHost ¶
func (*AuthMock) RevokeToken ¶
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 ¶
AuthWithTeamID finds an auth with a given team ID
func (*Client) AuthWithToken ¶
AuthWithToken collects authentication information for the provided token
func (*Client) Auths ¶
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 ¶
DeleteAuth removes an auth from the list of auths in credentials.json
func (*Client) FilterKnownAuthErrors ¶
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 ¶
IsAPIHostSlackDev returns true if host is the Slack Dev endpoint (dev.slack.com, https://dev1234.api.slack.com, etc)
func (*Client) IsAPIHostSlackProd ¶
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 ¶
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 ¶
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 ¶
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.