http

package
v0.0.68 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: Apache-2.0, MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// VersionHTTPHeader is the HTTP header key for the version.
	VersionHTTPHeader = "X-VINCE-VERSION"

	// ServedByHTTPHeader is the HTTP header used to report which
	// node (by node Raft address) actually served the request if
	// it wasn't served by this node.
	ServedByHTTPHeader = "X-VINCE-SERVED-BY"

	// AllowOriginHeader is the HTTP header for allowing CORS compliant access from certain origins
	AllowOriginHeader = "Access-Control-Allow-Origin"

	// AllowMethodsHeader is the HTTP header for supporting the correct methods
	AllowMethodsHeader = "Access-Control-Allow-Methods"

	// AllowHeadersHeader is the HTTP header for supporting the correct request headers
	AllowHeadersHeader = "Access-Control-Allow-Headers"

	// AllowCredentialsHeader is the HTTP header for supporting specifying credentials
	AllowCredentialsHeader = "Access-Control-Allow-Credentials"
)

Variables

View Source
var (
	// ErrLeaderNotFound is returned when a node cannot locate a leader
	ErrLeaderNotFound = errors.New("leader not found")
)
View Source
var InternalError = status.Error(codes.Internal, "Something went wrong")

Avoid leaking internal errors to client. The actual error is logged and this is returned back to the client.

Functions

func IsNotAuthorized

func IsNotAuthorized(err error) bool

func NewNodesFromServers

func NewNodesFromServers(servers *v1.Server_List) *v1.Node_List

NewNodesFromServers creates a slice of Nodes from a slice of Servers.

func TestNode

func TestNode(ctx context.Context, n *v1.Node, ga GetAddresser, leaderAddr string, timeout time.Duration)

Test tests the node's reachability and leadership status. If an error occurs, the Error field will be populated.

func ValidByPeriod

func ValidByPeriod(period *v1.TimePeriod, i v1.Interval) bool

func Voters

func Voters(n *v1.Node_List) (o *v1.Node_List)

Types

type Cluster

type Cluster interface {
	GetAddresser

	SendData(ctx context.Context, req *v1.Data, nodeAddr string, cred *v1.Credentials) error
	Load(ctx context.Context, req *v1.Load_Request, nodeAddr string, cred *v1.Credentials) error
	RemoveNode(ctx context.Context, req *v1.RemoveNode_Request, nodeAddr string, cred *v1.Credentials) error
	Backup(ctx context.Context, dst io.Writer, br *v1.Backup_Request, nodeAddr string, cred *v1.Credentials) error

	Realtime(ctx context.Context, req *v1.Realtime_Request, nodeAddr string, cred *v1.Credentials) (*v1.Realtime_Response, error)
	Aggregate(ctx context.Context, req *v1.Aggregate_Request, nodeAddr string, cred *v1.Credentials) (*v1.Aggregate_Response, error)
	Timeseries(ctx context.Context, req *v1.Timeseries_Request, nodeAddr string, cred *v1.Credentials) (*v1.Timeseries_Response, error)
	Breakdown(ctx context.Context, req *v1.BreakDown_Request, nodeAddr string, cred *v1.Credentials) (*v1.BreakDown_Response, error)
	Status() *v1.Status_Cluster
}

type CredentialStore

type CredentialStore interface {
	// AA authenticates and checks authorization for the given perm.
	AA(username, password string, perm v1.Credential_Permission) bool
}

CredentialStore is the interface credential stores must support.

type GetAddresser

type GetAddresser interface {
	GetNodeAPIAddr(ctx context.Context, addr string) (string, error)
}

GetAddresser is the interface that wraps the GetNodeAPIAddr method. GetNodeAPIAddr returns the HTTP API URL for the node at the given Raft address.

type QueryParams

type QueryParams map[string]string

QueryParams represents the query parameters passed in an HTTP request. Query parameter keys are case-sensitive, as per the HTTP spec.

func NewQueryParams

func NewQueryParams(r *http.Request) (QueryParams, error)

NewQueryParams returns a new QueryParams from the given HTTP request.

func (QueryParams) Associative

func (qp QueryParams) Associative() bool

Associative returns true if the query parameters request associative results.

func (QueryParams) Basic added in v0.0.65

func (qp QueryParams) Basic() (username, password string, ok bool)

func (QueryParams) BearerToken added in v0.0.65

func (qp QueryParams) BearerToken() string

func (QueryParams) Bypass

func (qp QueryParams) Bypass() bool

Bypass returns true if the query parameters indicate bypass mode.

func (QueryParams) Compress

func (qp QueryParams) Compress() bool

Compress returns true if the query parameters request compression.

func (QueryParams) DBTimeout

func (qp QueryParams) DBTimeout(def time.Duration) time.Duration

DBTimeout returns the value of the key named "db_timeout".

func (QueryParams) Filters

func (p QueryParams) Filters(ctx context.Context) (o []*v1.Filter)

func (QueryParams) Freshness

func (qp QueryParams) Freshness() time.Duration

Freshness returns the requested freshness duration.

func (QueryParams) FreshnessStrict

func (qp QueryParams) FreshnessStrict() bool

FreshnessStrict returns true if the query parameters indicate strict freshness.

func (QueryParams) HasKey

func (qp QueryParams) HasKey(k string) bool

HasKey returns true if the given key is present in the query parameters.

func (QueryParams) Interval

func (p QueryParams) Interval(ctx context.Context) v1.Interval

func (QueryParams) IsBearer added in v0.0.65

func (qp QueryParams) IsBearer() bool

func (QueryParams) Key

func (qp QueryParams) Key() string

Key returns the value of the key named "key".

func (QueryParams) Metrics

func (p QueryParams) Metrics(ctx context.Context) (o []v1.Metric)

func (QueryParams) NoLeader

func (qp QueryParams) NoLeader() bool

NoLeader returns true if the query parameters request no leader mode.

func (QueryParams) NoRewriteRandom

func (qp QueryParams) NoRewriteRandom() bool

NoRewrite returns true if the query parameters request no rewriting of queries.

func (QueryParams) NonVoters

func (qp QueryParams) NonVoters() bool

NonVoters returns true if the query parameters request non-voters to be included in results.

func (QueryParams) Period

func (p QueryParams) Period(ctx context.Context) *v1.TimePeriod

func (QueryParams) PeriodToRange

func (p QueryParams) PeriodToRange(ctx context.Context, now func() time.Time, period *v1.TimePeriod) (start, end time.Time)

func (QueryParams) Pretty

func (qp QueryParams) Pretty() bool

Pretty returns true if the query parameters indicate pretty-printing should be returned.

func (QueryParams) Property

func (p QueryParams) Property(ctx context.Context) (o []v1.Property)

func (QueryParams) Query

func (qp QueryParams) Query() string

Query returns the requested query.

func (QueryParams) Queue

func (qp QueryParams) Queue() bool

Query returns true if the query parameters request queued operation

func (QueryParams) Redirect

func (qp QueryParams) Redirect() bool

Redirect returns true if the query parameters request redirect mode.

func (QueryParams) Retries

func (qp QueryParams) Retries(def int) int

Retries returns the requested number of retries.

func (QueryParams) SiteID

func (qp QueryParams) SiteID() string

func (QueryParams) Sync

func (qp QueryParams) Sync() bool

Sync returns whether the sync flag is set.

func (QueryParams) TenantID

func (qp QueryParams) TenantID() string

func (QueryParams) Timeout

func (qp QueryParams) Timeout(def time.Duration) time.Duration

Timeout returns the requested timeout duration.

func (QueryParams) Timings

func (qp QueryParams) Timings() bool

Timings returns true if the query parameters indicate timings should be returned.

func (QueryParams) Tx

func (qp QueryParams) Tx() bool

Tx returns true if the query parameters indicate the query should be executed in a transaction.

func (QueryParams) Vacuum

func (qp QueryParams) Vacuum() bool

Vacuum returns true if the query parameters request vacuum mode.

func (QueryParams) Version

func (qp QueryParams) Version() string

Version returns the requested version.

func (QueryParams) Wait

func (qp QueryParams) Wait() bool

Wait returns true if the query parameters indicate the query should wait.

type ResultsError

type ResultsError interface {
	Error() string
	IsAuthorized() bool
}

type Service

type Service struct {
	AllowOrigin string // Value to set for Access-Control-Allow-Origin
	// contains filtered or unexported fields
}

func New

func New(store store.Storage, cluster Cluster, credentials CredentialStore, guard guard.Guard,
	tenants tenant.Loader, geo *geo.Geo) *Service

New returns an uninitialized HTTP service. If credentials is nil, then the service performs no authentication and authorization checks.

func (*Service) CheckRequestPerm

func (s *Service) CheckRequestPerm(params QueryParams, perm v1.Credential_Permission) (b bool)

func (*Service) DoRedirect

func (s *Service) DoRedirect(w http.ResponseWriter, r *http.Request, qp QueryParams) bool

DoRedirect checks if the request is a redirect, and if so, performs the redirect. Returns true caller can consider the request handled. Returns false if the request was not a redirect and the caller should continue processing the request.

func (*Service) FormRedirect

func (s *Service) FormRedirect(r *http.Request) (string, error)

FormRedirect returns the value for the "Location" header for a 301 response.

func (*Service) LeaderAPIAddr

func (s *Service) LeaderAPIAddr(ctx context.Context) string

LeaderAPIAddr returns the API address of the leader, as known by this node.

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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