base

package
v0.0.0-...-e73b65a Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProvidersRoot = "providers"
	ProviderParam = "provider"
	DetailParam   = "detail"
	NsParam       = "namespace"
	NameParam     = "name"
)

Root - all routes.

View Source
const (
	// Explains reason behind status code.
	ReasonHeader = "X-Reason"
	// Explains 404 caused by provider not found in
	// inventory as opposed to the requested resource
	// not found within the provider in the inventory.
	UnknownProvider = "ProviderNotFound"
)

Reply Header.

Variables

View Source
var DefaultAuth = Auth{
	TTL: time.Second * 10,
}

Default auth provider.

View Source
var Settings = &settings.Settings

Application settings.

Functions

func Link(path string, params Params) string

Build link.

Types

type Auth

type Auth struct {
	// k8s API writer.
	Writer client.Writer
	// Cached token TTL.
	TTL time.Duration
	// contains filtered or unexported fields
}

Authorized by k8s bearer token SAR. Token must have "*" on the provider CR.

func (*Auth) Permit

func (r *Auth) Permit(ctx *gin.Context, p *api.Provider) (status int)

Authenticate token.

type Client

type Client interface {
	// Finder
	Finder() Finder
	// Get a resource.
	// The `resource` must be a pointer to a resource object.
	// Returns:
	//   ProviderNotSupportedErr
	//   ProviderNotReadyErr
	//   NotFoundErr
	Get(resource interface{}, id string) error
	// List a collection.
	// The `list` must be a pointer to a slice of resource object.
	// Returns:
	//   ProviderNotSupportedErr
	//   ProviderNotReadyErr
	//   NotFoundErr
	List(list interface{}, param ...Param) error
	// Watch a collection.
	// Returns:
	//   ProviderNotSupportedErr
	//   ProviderNotReadyErr
	//   NotFoundErr
	Watch(resource interface{}, h EventHandler) (*Watch, error)
	// Get a resource by ref.
	// Returns:
	//   ProviderNotSupportedErr
	//   ProviderNotReadyErr
	//   NotFoundErr
	//   RefNotUniqueErr
	Find(resource interface{}, ref Ref) error
	// Find a VM by ref.
	// Returns the matching resource and:
	//   ProviderNotSupportedErr
	//   ProviderNotReadyErr
	//   NotFoundErr
	//   RefNotUniqueErr
	VM(ref *Ref) (interface{}, error)
	// Find a Workload by ref.
	// Returns the matching resource and:
	//   ProviderNotSupportedErr
	//   ProviderNotReadyErr
	//   NotFoundErr
	//   RefNotUniqueErr
	Workload(ref *Ref) (interface{}, error)
	// Find a Network by ref.
	// Returns the matching resource and:
	//   ProviderNotSupportedErr
	//   ProviderNotReadyErr
	//   NotFoundErr
	//   RefNotUniqueErr
	Network(ref *Ref) (interface{}, error)
	// Find storage by ref.
	// Returns the matching resource and:
	//   ProviderNotSupportedErr
	//   ProviderNotReadyErr
	//   NotFoundErr
	//   RefNotUniqueErr
	Storage(ref *Ref) (interface{}, error)
	// Find host by ref.
	// Returns the matching resource and:
	//   ProviderNotSupportedErr
	//   ProviderNotReadyErr
	//   NotFoundErr
	//   RefNotUniqueErr
	Host(ref *Ref) (interface{}, error)
}

REST Client.

type EventHandler

type EventHandler = libweb.EventHandler

Lib.

type Finder

type Finder interface {
	// Finder with client.
	With(client Client) Finder
	// Find a resource by ref.
	// Returns:
	//   ProviderNotSupportedErr
	//   ProviderNotReadyErr
	//   NotFoundErr
	//   RefNotUniqueErr
	ByRef(resource interface{}, ref Ref) error
	// Find a VM by ref.
	// Returns the matching resource and:
	//   ProviderNotSupportedErr
	//   ProviderNotReadyErr
	//   NotFoundErr
	//   RefNotUniqueErr
	VM(ref *Ref) (interface{}, error)
	// Find a workload by ref.
	// Returns the matching resource and:
	//   ProviderNotSupportedErr
	//   ProviderNotReadyErr
	//   NotFoundErr
	//   RefNotUniqueErr
	Workload(ref *Ref) (interface{}, error)
	// Find a Network by ref.
	// Returns the matching resource and:
	//   ProviderNotSupportedErr
	//   ProviderNotReadyErr
	//   NotFoundErr
	//   RefNotUniqueErr
	Network(ref *Ref) (interface{}, error)
	// Find storage by ref.
	// Returns the matching resource and:
	//   ProviderNotSupportedErr
	//   ProviderNotReadyErr
	//   NotFoundErr
	//   RefNotUniqueErr
	Storage(ref *Ref) (interface{}, error)
	// Find host by ref.
	// Returns the matching resource and:
	//   ProviderNotSupportedErr
	//   ProviderNotReadyErr
	//   NotFoundErr
	//   RefNotUniqueErr
	Host(ref *Ref) (interface{}, error)
}

Resource Finder.

type Handler

type Handler struct {
	libweb.Parity
	libweb.Watched
	libweb.Paged
	// Container
	Container *libcontainer.Container
	// Provider referenced in the request.
	Provider *api.Provider
	// Collector responsible for the provider.
	Collector libcontainer.Collector
	// Resources detail level.
	Detail int
}

Base handler.

func (h *Handler) Link(path string, params Params) string

Build link.

func (*Handler) PathMatch

func (h *Handler) PathMatch(absolute, relative string) (matched bool)

Match (compare) paths. Determine if the relative path is contained in the absolute path.

func (*Handler) PathMatchRoot

func (h *Handler) PathMatchRoot(absolute, path string) (matched bool)

Match (compare) paths. Determine if the paths have the same root.

func (*Handler) Prepare

func (h *Handler) Prepare(ctx *gin.Context) int

Prepare to handle the request.

type LibClient

type LibClient = libweb.Client

type NodeBuilder

type NodeBuilder interface {
	Node(p *TreeNode, m libmodel.Model) *TreeNode
}

Node builder.

type NotFoundError

type NotFoundError struct {
	Ref
}

Resource not found.

func (NotFoundError) Error

func (r NotFoundError) Error() string

type Param

type Param struct {
	Key   string
	Value string
}

Web parameter.

type Params

type Params = map[string]string

Params

type Ref

type Ref = ref.Ref

Reference.

type RefNotUniqueError

type RefNotUniqueError struct {
	Ref
}

Reference matches multiple resources.

func (RefNotUniqueError) Error

func (r RefNotUniqueError) Error() string

type Resolver

type Resolver interface {
	// Find the API path for the specified resource.
	Path(resource interface{}, id string) (string, error)
}

Resolves resources to API paths.

type ResourceNotResolvedError

type ResourceNotResolvedError struct {
	Object interface{}
}

Resource kind cannot be resolved.

func (ResourceNotResolvedError) Error

func (r ResourceNotResolvedError) Error() string

type RestClient

type RestClient struct {
	LibClient
	Resolver
	// Host <host>:<port>
	Host string
	// Parameters
	Params Params
}

REST API client.

func (*RestClient) Get

func (c *RestClient) Get(resource interface{}, id string) (status int, err error)

Get a resource.

func (*RestClient) List

func (c *RestClient) List(list interface{}, param ...Param) (status int, err error)

List resources in a collection.

func (*RestClient) Watch

func (c *RestClient) Watch(resource interface{}, h EventHandler) (status int, w *Watch, err error)

Watch a resource.

type Tree

type Tree struct {
	NodeBuilder
	// Depth limit.
	Depth int
}

Tree.

func (*Tree) Ancestry

func (r *Tree) Ancestry(leaf model.Model, navigator model.ParentNavigator) (*TreeNode, error)

Ancestry (Tree).

func (*Tree) Build

func (r *Tree) Build(m model.Model, navigator model.BranchNavigator) (*TreeNode, error)

Build the tree

type TreeNode

type TreeNode struct {
	// Parent node.
	Parent *TreeNode `json:"-"`
	// Object kind.
	Kind string `json:"kind"`
	// Object (resource).
	Object interface{} `json:"object"`
	// Child nodes.
	Children []*TreeNode `json:"children"`
}

Tree node resource.

type Watch

type Watch = libweb.Watch

Jump to

Keyboard shortcuts

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