auth

package
v3.2.5 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package auth is a generated GoMock package.

Index

Constants

View Source
const APIAuthEndpoint = "/auth/cli/runme"

Variables

View Source
var ErrNotFound = errors.New("value not found")

Functions

func WithClient

func WithClient(c *http.Client) func(*Auth)

func WithEnv

func WithEnv(env Env) func(*Auth)

Types

type APITokenError

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

func NewAPITokenError

func NewAPITokenError(msg string) *APITokenError

func (*APITokenError) Error

func (e *APITokenError) Error() string

type Auth

type Auth struct {
	// OAuthConfig describes OAuth flow.
	OAuthConfig oauth2.Config

	// APIBaseURL is Stateful API address.
	// It is used to obtain Stateful's JWT token.
	APIBaseURL string

	// Storage is responsible for storing and retrieving token.
	Storage Storage
	// contains filtered or unexported fields
}

Auth provides an authentication and authorization method for the CLI. It relies on a browser and known web application to do it securely.

func New

func New(oauthConfig oauth2.Config, apiURL string, storage Storage, opts ...Opts) *Auth

New creates a new instance of Auth.

func (*Auth) GetFreshToken

func (a *Auth) GetFreshToken(ctx context.Context) (string, error)

GetFreshToken is similar to GetToken but it always returns a new API token.

func (*Auth) GetToken

func (a *Auth) GetToken(ctx context.Context) (string, error)

GetToken returns an API token to access the Stateful API. If the token exists and is valid for at least 15 seconds, it is returned immediately. Otherwise, it's fetched using a never-expiring GitHub token.

func (*Auth) GetTokenPath

func (a *Auth) GetTokenPath() (string, error)

func (*Auth) Login

func (a *Auth) Login(ctx context.Context) error

Login opens browser and authenticates user. It fallbacks to no browser flow if opening a URL fails,

func (*Auth) Logout

func (a *Auth) Logout() error

type Authorizer

type Authorizer interface {
	TokenProvider
	Login(context.Context) error
	Logout() error
}

type DiskStorage

type DiskStorage struct {
	// Location is a directory where data will be stored.
	Location string
	// contains filtered or unexported fields
}

func (*DiskStorage) Delete

func (s *DiskStorage) Delete(key string) error

func (*DiskStorage) Load

func (s *DiskStorage) Load(key string, val interface{}) error

func (*DiskStorage) Path

func (s *DiskStorage) Path(key string) string

func (*DiskStorage) Save

func (s *DiskStorage) Save(key string, val interface{}) error

type Env

type Env interface {
	IsAutonomous() bool
	RequestCode(url, state string) error
	WaitForCodeAndState(ctx context.Context) (string, string, error)
}

type MockAuthorizer

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

MockAuthorizer is a mock of Authorizer interface.

func NewMockAuthorizer

func NewMockAuthorizer(ctrl *gomock.Controller) *MockAuthorizer

NewMockAuthorizer creates a new mock instance.

func (*MockAuthorizer) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockAuthorizer) GetFreshToken

func (m *MockAuthorizer) GetFreshToken(arg0 context.Context) (string, error)

GetFreshToken mocks base method.

func (*MockAuthorizer) GetToken

func (m *MockAuthorizer) GetToken(arg0 context.Context) (string, error)

GetToken mocks base method.

func (*MockAuthorizer) GetTokenPath

func (m *MockAuthorizer) GetTokenPath() (string, error)

GetTokenPath mocks base method.

func (*MockAuthorizer) Login

func (m *MockAuthorizer) Login(arg0 context.Context) error

Login mocks base method.

func (*MockAuthorizer) Logout

func (m *MockAuthorizer) Logout() error

Logout mocks base method.

type MockAuthorizerMockRecorder

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

MockAuthorizerMockRecorder is the mock recorder for MockAuthorizer.

func (*MockAuthorizerMockRecorder) GetFreshToken

func (mr *MockAuthorizerMockRecorder) GetFreshToken(arg0 interface{}) *gomock.Call

GetFreshToken indicates an expected call of GetFreshToken.

func (*MockAuthorizerMockRecorder) GetToken

func (mr *MockAuthorizerMockRecorder) GetToken(arg0 interface{}) *gomock.Call

GetToken indicates an expected call of GetToken.

func (*MockAuthorizerMockRecorder) GetTokenPath

func (mr *MockAuthorizerMockRecorder) GetTokenPath() *gomock.Call

GetTokenPath indicates an expected call of GetTokenPath.

func (*MockAuthorizerMockRecorder) Login

func (mr *MockAuthorizerMockRecorder) Login(arg0 interface{}) *gomock.Call

Login indicates an expected call of Login.

func (*MockAuthorizerMockRecorder) Logout

func (mr *MockAuthorizerMockRecorder) Logout() *gomock.Call

Logout indicates an expected call of Logout.

type Opts

type Opts func(*Auth)

type Storage

type Storage interface {
	Path(string) string
	Load(string, interface{}) error
	Save(string, interface{}) error
	Delete(string) error
}

type TerminalEnv

type TerminalEnv struct {
	io.Reader // in
	io.Writer // out
}

func (TerminalEnv) IsAutonomous

func (TerminalEnv) IsAutonomous() bool

func (*TerminalEnv) RequestCode

func (e *TerminalEnv) RequestCode(url, state string) (err error)

func (*TerminalEnv) WaitForCodeAndState

func (e *TerminalEnv) WaitForCodeAndState(context.Context) (string, string, error)

type TestEnv

type TestEnv struct {
	Autonomous bool
	// contains filtered or unexported fields
}

func (TestEnv) IsAutonomous

func (e TestEnv) IsAutonomous() bool

func (*TestEnv) RequestCode

func (e *TestEnv) RequestCode(url, state string) (err error)

func (*TestEnv) WaitForCodeAndState

func (e *TestEnv) WaitForCodeAndState(context.Context) (string, string, error)

type Token

type Token struct {
	Type string `json:"type"`
	Data string `json:"data"`
}

type TokenProvider

type TokenProvider interface {
	GetToken(context.Context) (string, error)
	GetTokenPath() (string, error)
	GetFreshToken(context.Context) (string, error)
}

Jump to

Keyboard shortcuts

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