meta

package
v1.7.0-rc6 Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package meta provides a client to the meta node to allow Kapacitor to perform auth. The real home of the meta client is in the InfluxDB Enterprise repo, however kapacitor's current dependency in influxdb is stuck on 1.1. This package allows kapacitor to use the newest meta client API but avoid having to upgrade kapacitor's dependency on influxdb which is now a couple years behind.

Index

Constants

View Source
const (
	// DefaultTimeout is the duration that the client will continue to
	// retry a failed operation.
	DefaultTimeout = 10 * time.Second

	// DefaultBackoffCap is the maximum duration a backoff value can
	// have.
	DefaultBackoffCap = DefaultTimeout / 3

	// MaxClientRedirects is the maximum number of redirects the Client will
	// attempt to follow for a single request, before failing.
	MaxClientRedirects = 5
)

Variables

View Source
var (
	// ErrAddressMissing is returned when a required addr parameter is
	// missing.
	ErrAddressMissing = errors.New("addr value is empty")

	// ErrHTTPAddressMissing is returned when a required httpAddr
	// parameter is missing.
	ErrHTTPAddressMissing = errors.New("httpAddr value is empty")

	// ErrTCPAddressMissing is returned when a required tcpAddr
	// parameter is missing.
	ErrTCPAddressMissing = errors.New("tcpAddr value is empty")

	// ErrLeaseNameMissing is returned when a required lease name is
	// missing.
	ErrLeaseNameMissing = errors.New("lease name is empty")

	// ErrLeaseConflict is returned when there is a conflict while
	// attempting to require a lease.
	ErrLeaseConflict = errors.New("another node owns the lease")

	// ErrMaximumRedirectsReached is returned when a Client has been
	// redirected too many times for a single request.
	ErrMaximumRedirectsReached = errors.New("too many redirects")

	// ErrNotMetaNode is returned when attempting to add a non-meta node
	// as a meta node in the cluster.
	ErrNotMetaNode = errors.New("not a meta node")

	// ErrEmptyCluster is returned when there are no nodes known to the
	// cluster.
	ErrEmptyCluster = errors.New("cluster is empty")

	ErrEmptyStatus = errors.New("status is empty")

	// ErrAntiEntropyDisabled is returned when the anti-entropy service
	// returns a 501 Not Implemented HTTP status.
	ErrAntiEntropyDisabled = errors.New("anti-entropy service is not enabled")
)
View Source
var UseAuth = func(t AuthType, username, password, secret string) ClientOption {
	return func(c *Client) {
		c.authType = t
		c.username = username
		c.password = password
		c.secret = secret
	}
}

UseAuth sets the authentication type and credentials that will be used.

View Source
var WithTLS = func(tlsConfig *tls.Config, useTLS bool, skip bool) ClientOption {
	return func(c *Client) {
		c.useTLS = useTLS
		if skip {
			c.skipTLS = true
			c.tls = &tls.Config{
				InsecureSkipVerify: true,
			}
		} else if useTLS {
			c.tls = tlsConfig
		}

		if t, ok := c.client.Transport.(*http.Transport); ok {
			t.TLSClientConfig = c.tls
		} else {
			c.client.Transport = &http.Transport{
				TLSClientConfig: c.tls,
			}
		}
	}
}

WithTLS specifies if communication to the meta node uses the specified TLS config if any and if we skip verifying certificates, allowing for self-signed certificates.

View Source
var WithTimeout = func(d time.Duration) ClientOption {
	return func(c *Client) {
		c.timeout = d
		c.backoffCap = c.timeout / 3
		if t, ok := c.client.Transport.(*http.Transport); ok {
			t.ResponseHeaderTimeout = d
		} else {
			c.client.Transport = &http.Transport{
				ResponseHeaderTimeout: d,
			}
		}
	}
}

WithTimeout specifies the duration the client will continue to retry failed operations before giving up.

Functions

This section is empty.

Types

type AuthType

type AuthType int

AuthType identifies a method of authentication.

const (
	// NoAuth means no authentication will be used.
	NoAuth AuthType = iota
	// BasicAuth means basic user authentication will be used.
	BasicAuth
	// BearerAuth means JWT tokens will be used.
	BearerAuth
)

type Client

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

Client is a client for the HTTP API exposed by a Plutonium Meta node.

func NewClient

func NewClient(addr string, options ...ClientOption) *Client

NewClient returns a new Client, which will make requests to the Meta node listening on addr. New accepts zero or more functional options for configuring aspects of the returned Client.

By default, a Client does not send communications over a TLS connection. TLS can be enforced using the WithTLS option. Output and errors are logged to stdout and stderr, respectively; use the appropriate options to set those outputs.

func (*Client) CheckPass

func (c *Client) CheckPass(name, pass string) error

func (*Client) Users

func (c *Client) Users(name string) ([]User, error)

Users returns a given user or a list of all users if name is empty. If the user is not found an empty list is returned without an error.

type ClientHTTPOption added in v1.6.6

type ClientHTTPOption func(client *http.Client) error

type ClientOption

type ClientOption func(c *Client)

ClientOption is a functional option for a Client.

func WithHTTPOption added in v1.6.6

func WithHTTPOption(opt ClientHTTPOption) ClientOption

type Error

type Error struct {
	Message string `json:"error"`
	Code    int    `json:"-"`
}

Error represent an error message sent in a response body from a meta node.

func NewError

func NewError(msg string, code int) Error

NewError returns a new Error value.

func (Error) Error

func (e Error) Error() string

type FatalError

type FatalError struct {
	Context error
}

A FatalError is returned when an operation on the meta node API was not successful and retrying the operation would always result in the same error being returned.

FatalError makes the last underlying error available in the Context field.

func (FatalError) Error

func (e FatalError) Error() string

type Permission

type Permission int

Permission type NOTE: Keep this type up-to-date with the corresponding type in meta/data.go The type cannot be imported as it creates an import cycle.

const (
	NoPermissions                   Permission = 0
	ViewAdminPermission             Permission = 1
	ViewChronografPermission        Permission = 2
	CreateDatabasePermission        Permission = 3
	CreateUserAndRolePermission     Permission = 4
	AddRemoveNodePermission         Permission = 5
	DropDatabasePermission          Permission = 6
	DropDataPermission              Permission = 7
	ReadDataPermission              Permission = 8
	WriteDataPermission             Permission = 9
	RebalancePermission             Permission = 10
	ManageShardPermission           Permission = 11
	ManageContinuousQueryPermission Permission = 12
	ManageQueryPermission           Permission = 13
	ManageSubscriptionPermission    Permission = 14
	MonitorPermission               Permission = 15
	CopyShardPermission             Permission = 16
	KapacitorAPIPermission          Permission = 17
	KapacitorConfigAPIPermission    Permission = 18
)

func (Permission) MarshalText

func (p Permission) MarshalText() ([]byte, error)

MarshalText converts a Permission into a textual represenation.

func (*Permission) UnmarshalText

func (p *Permission) UnmarshalText(t []byte) error

UnmarshalText sets the permission based on the textual represenation.

type TimeoutError

type TimeoutError struct {
	Context error
}

A TimeoutError is returned when an operation on the meta node API was not successful, and repeated attempts to succeed have failed.

TimeoutError makes the last underlying error available in the Context field.

func ErrTimeout

func ErrTimeout(ctx error) TimeoutError

ErrTimeout returns a new TimeoutError.

func (TimeoutError) Error

func (e TimeoutError) Error() string

type User

type User struct {
	Name        string                  `json:"name"`
	Hash        string                  `json:"hash"`
	Permissions map[string][]Permission `json:"permissions,omitempty"`
}

User holds information about a user's credentials and permissions.

Jump to

Keyboard shortcuts

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