builder

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UCPRootScopePath  = "/planes/radius/{planeName}"
	ResourceGroupPath = "/resourcegroups/{resourceGroupName}"
)

Variables

View Source
var (
	// ErrResourceAlreadyExists represents an error when a resource already exists.
	ErrResourceAlreadyExists = errors.New("resource already exists")
)

Functions

func NewOpenAPIValidator

func NewOpenAPIValidator(ctx context.Context, base, namespace string) (func(h http.Handler) http.Handler, error)

NewOpenAPIValidatorMiddleware creates a new OpenAPI validator middleware.

Types

type BuildOptions

type BuildOptions struct {
	// ResourceType represents the resource type.
	ResourceType string

	// ParameterName represents the resource name for resource type.
	ParameterName string

	// ResourceNamePattern represents the resource name pattern used for HTTP routing path.
	ResourceNamePattern string
}

BuildOptions is the options for building resource outputs.

type Builder

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

Builder can be used to register operations and build HTTP routing paths and handlers for a resource namespace.

func (*Builder) ApplyAPIHandlers

func (b *Builder) ApplyAPIHandlers(ctx context.Context, r chi.Router, ctrlOpts apictrl.Options, middlewares ...func(h http.Handler) http.Handler) error

ApplyAPIHandlers builds HTTP routing paths and handlers for namespace.

func (*Builder) ApplyAsyncHandler

func (b *Builder) ApplyAsyncHandler(ctx context.Context, registry *worker.ControllerRegistry, ctrlOpts asyncctrl.Options) error

ApplyAsyncHandler registers asynchronous controllers from HandlerOutput.

func (*Builder) Namespace

func (b *Builder) Namespace() string

type Namespace

type Namespace struct {
	ResourceNode
	// contains filtered or unexported fields
}

Namespace represents the namespace of UCP.

func NewNamespace

func NewNamespace(namespace string) *Namespace

NewNamespace creates a new namespace.

func (*Namespace) GenerateBuilder

func (p *Namespace) GenerateBuilder() Builder

GenerateBuilder Builder object by traversing resource nodes from namespace.

func (*Namespace) SetAvailableOperations

func (p *Namespace) SetAvailableOperations(operations []v1.Operation)

SetAvailableOperations sets the available operations for the namespace.

type Operation

type Operation[T any] struct {
	// Disabled indicates that the operation is disabled. By default, all operations are enabled.
	Disabled bool

	// UpdateFilters is a slice of filters that execute prior to updating a resource.
	UpdateFilters []controller.UpdateFilter[T]

	// DeleteFilters is a slice of filters that execute prior to deleting a resource.
	DeleteFilters []controller.DeleteFilter[T]

	// APIController is the controller function for the API controller frontend.
	APIController server.ControllerFactoryFunc

	// AsyncJobController is the controller function for the async job worker.
	AsyncJobController worker.ControllerFactoryFunc

	// AsyncOperationTimeout is the default timeout duration of async operations for the operation.
	AsyncOperationTimeout time.Duration

	// AsyncOperationRetryAfter is the value of the Retry-After header that will be used for async operations.
	// If this is 0 then the default value of v1.DefaultRetryAfter will be used. Consider setting this to a smaller
	// value like 5 seconds if your operations will complete quickly.
	AsyncOperationRetryAfter time.Duration
}

Operation defines converters for request and response, update and delete filters, asynchronous operation controller, and the options for API operation.

type OperationRegistration

type OperationRegistration struct {
	// ResourceType represents the resource type.
	ResourceType string

	// ResourceNamePattern represents the resource name pattern used for HTTP routing path.
	ResourceNamePattern string

	// Path represents additional custom action path after resource name.
	Path string

	// Method represents the operation method.
	Method v1.OperationMethod

	// APIController represents the API controller handler.
	APIController server.ControllerFactoryFunc

	// AsyncController represents the async controller handler.
	AsyncController worker.ControllerFactoryFunc
}

OperationRegistration is the output for building resource outputs.

type ResourceKind

type ResourceKind string

ResourceKind represents the kind of resource.

const (
	// NamespaceResourceKind represents the namespace resource kind.
	NamespaceResourceKind ResourceKind = "Namespace"

	// TrackedResourceKind represents the tracked resource kind.
	TrackedResourceKind ResourceKind = "TrackedResource"

	// ProxyResourceKind represents the proxy resource kind.
	ProxyResourceKind ResourceKind = "ProxyResource"
)

type ResourceNode

type ResourceNode struct {
	// Kind is the resource kind.
	Kind ResourceKind

	// Name is the resource name.
	Name string
	// contains filtered or unexported fields
}

ResourceNode is a node in the resource tree.

func (*ResourceNode) AddResource

func (r *ResourceNode) AddResource(name string, option ResourceOptionBuilder) *ResourceNode

AddResource adds a new child resource type and API handlers and returns new resource node.

type ResourceOption

type ResourceOption[P interface {
	*T
	v1.ResourceDataModel
}, T any] struct {

	// ResourceParamName is the parameter name of the resource. This is optional.
	// If not set, the parameter name will be generated by adding "Name" suffix to the resource name.
	ResourceParamName string

	// RequestConverter is the request converter.
	RequestConverter v1.ConvertToDataModel[T]

	// ResponseConverter is the response converter.
	ResponseConverter v1.ConvertToAPIModel[T]

	// ListPlane defines the operation for listing resources by plane scope.
	ListPlane Operation[T]

	// List defines the operation for listing resources by resource group scope.
	List Operation[T]

	// Get defines the operation for getting a resource.
	Get Operation[T]

	// Put defines the operation for creating or updating a resource.
	Put Operation[T]

	// Patch defines the operation for updating a resource.
	Patch Operation[T]

	// Delete defines the operation for deleting a resource.
	Delete Operation[T]

	// Custom defines the custom actions.
	Custom map[string]Operation[T]
	// contains filtered or unexported fields
}

ResourceOption is the option for ResourceNode. It defines model converters for request and response and configures operation for each CRUDL and custom actions.

func (*ResourceOption[P, T]) BuildHandlerOutputs

func (r *ResourceOption[P, T]) BuildHandlerOutputs(opts BuildOptions) []*OperationRegistration

BuildHandlerOutputs builds the handler outputs for each operation.

func (*ResourceOption[P, T]) LinkResource

func (r *ResourceOption[P, T]) LinkResource(node *ResourceNode)

LinkResource links the resource node to the resource option.

func (*ResourceOption[P, T]) ParamName

func (r *ResourceOption[P, T]) ParamName() string

ParamName returns the parameter name of the resource. If ResourceParamName is not set, the parameter name will be generated by adding "Name" suffix to the resource name.

type ResourceOptionBuilder

type ResourceOptionBuilder interface {
	// LinkResource links the resource node to the resource option.
	LinkResource(*ResourceNode)

	// ParamName gets the resource name for resource type.
	ParamName() string

	// BuildHandlerOutputs builds the resource outputs which constructs the API routing path and handlers.
	BuildHandlerOutputs(BuildOptions) []*OperationRegistration
}

ResourceOptionBuilder is the interface for resource option.

Jump to

Keyboard shortcuts

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