apix

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2021 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package apix provide API-related helpers.

Package apix is a generated GoMock package.

Package apix is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccessTokenInvalid = errors.New("invalid AccessToken")
)

Errors.

Functions

func FromContext

func FromContext(ctx Ctx) (remoteIP, methodName string, auth dom.Auth)

FromContext returns values describing request stored in ctx, if any.

Types

type AccessToken

type AccessToken string

AccessToken is an access token.

func AccessTokenFromContext added in v0.3.0

func AccessTokenFromContext(ctx Ctx) (accessToken AccessToken)

AccessTokenFromContext returns AccessToken stored in ctx, if any.

func (AccessToken) Format added in v0.3.0

func (s AccessToken) Format(f fmt.State, c rune)

Format wraps sensitive.String.

func (AccessToken) MarshalJSON added in v0.3.0

func (s AccessToken) MarshalJSON() ([]byte, error)

MarshalJSON wraps sensitive.String.

func (AccessToken) MarshalText added in v0.3.0

func (s AccessToken) MarshalText() ([]byte, error)

MarshalText wraps sensitive.String.

type Authn

type Authn interface {
	// Authenticate validates AccessToken and returns corresponding
	// Auth. If validation fails returns zero Auth with error.
	//
	// Errors: ErrAccessTokenInvalid.
	Authenticate(Ctx, AccessToken) (dom.Auth, error)
}

Authn validates AccessToken.

func NewAuthnClient added in v0.3.0

func NewAuthnClient(
	ctx Ctx,
	reg *prometheus.Registry,
	service string,
	ca *x509.CertPool,
	addr string,
) (Authn, error)

NewAuthnClient returns Authn implementation using gRPC AuthIntSvc at addr.

type Ctx

type Ctx = context.Context

func GRPCNewContext added in v0.3.0

func GRPCNewContext(ctx Ctx, fullMethod string, authn Authn) (_ Ctx, auth dom.Auth, err error)

GRPCNewContext returns a new context.Context that carries values describing this request without any deadline, plus result of authn.Authenticate.

type JSONRPC2Ctx added in v0.3.0

type JSONRPC2Ctx struct {
	AccessToken string
	jsonrpc2.Ctx
}

JSONRPC2Ctx describe JSON-RPC 2.0 Ctx param used by all API methods.

func (*JSONRPC2Ctx) NewContext added in v0.3.0

func (c *JSONRPC2Ctx) NewContext(
	authn Authn,
	service string,
) (
	ctx Ctx,
	log *structlog.Logger,
	methodName string,
	auth dom.Auth,
	err error,
)

NewContext returns a new context.Context that carries values describing this request without any deadline, plus some of the values.

type MockAuthn

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

MockAuthn is a mock of Authn interface.

func NewMockAuthn

func NewMockAuthn(ctrl *gomock.Controller) *MockAuthn

NewMockAuthn creates a new mock instance.

func (*MockAuthn) Authenticate

func (m *MockAuthn) Authenticate(arg0 Ctx, arg1 AccessToken) (dom.Auth, error)

Authenticate mocks base method.

func (*MockAuthn) EXPECT

func (m *MockAuthn) EXPECT() *MockAuthnMockRecorder

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

type MockAuthnMockRecorder

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

MockAuthnMockRecorder is the mock recorder for MockAuthn.

func (*MockAuthnMockRecorder) Authenticate

func (mr *MockAuthnMockRecorder) Authenticate(arg0, arg1 interface{}) *gomock.Call

Authenticate indicates an expected call of Authenticate.

type MockUserAgent added in v0.5.2

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

MockUserAgent is a mock of UserAgent interface.

func NewMockUserAgent added in v0.5.2

func NewMockUserAgent(ctrl *gomock.Controller) *MockUserAgent

NewMockUserAgent creates a new mock instance.

func (*MockUserAgent) Do added in v0.5.2

func (m *MockUserAgent) Do(ctx Ctx, req *http.Request, skip int) (*http.Response, []byte, error)

Do mocks base method.

func (*MockUserAgent) EXPECT added in v0.5.2

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

func (*MockUserAgent) Log added in v0.5.2

func (m *MockUserAgent) Log(ctx Ctx, resp *http.Response, body []byte)

Log mocks base method.

type MockUserAgentMockRecorder added in v0.5.2

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

MockUserAgentMockRecorder is the mock recorder for MockUserAgent.

func (*MockUserAgentMockRecorder) Do added in v0.5.2

func (mr *MockUserAgentMockRecorder) Do(ctx, req, skip interface{}) *gomock.Call

Do indicates an expected call of Do.

func (*MockUserAgentMockRecorder) Log added in v0.5.2

func (mr *MockUserAgentMockRecorder) Log(ctx, resp, body interface{}) *gomock.Call

Log indicates an expected call of Log.

type UserAgent added in v0.5.0

type UserAgent interface {
	// Do sends an HTTP request and returns an HTTP response.
	// It returns body for convenience - it's same as can be read from resp.Body.
	// It saves body to file if log level is Debug and cfg.Debug and cfg.DumpDir is set.
	// Returned resp.Body doesn't needs to be closed.
	Do(ctx Ctx, req *http.Request, skip int) (_ *http.Response, body []byte, _ error)
	// Log resp (both HTTP request and response).
	// It does nothing if cfg.Debug is false.
	Log(ctx Ctx, resp *http.Response, body []byte)
}

UserAgent is a convenience wrapper for http.Client, suitable for fetching small responses (because it reads full response in memory).

func NewUserAgent added in v0.5.0

func NewUserAgent(cfg UserAgentConfig) UserAgent

NewUserAgent creates and returns new UserAgent.

type UserAgentConfig added in v0.5.0

type UserAgentConfig struct {
	Timeout     time.Duration // Default: 30s.
	MaxBodySize int           // Default: 1MB.
	Debug       bool          // Log response.
	DumpDir     string        // If not empty and Debug - dump response body to files in this dir.
}

UserAgentConfig contains configuration for UserAgent.

Jump to

Keyboard shortcuts

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