Documentation
¶
Index ¶
- Constants
- Variables
- func NewOpenAPIValidator(ctx context.Context, base, namespace string) (func(h http.Handler) http.Handler, error)
- type BuildOptions
- type Builder
- type Namespace
- type Operation
- type OperationRegistration
- type ResourceKind
- type ResourceNode
- type ResourceOption
- type ResourceOptionBuilder
Constants ¶
const ( UCPRootScopePath = "/planes/radius/{planeName}" ResourceGroupPath = "/resourcegroups/{resourceGroupName}" )
Variables ¶
var ( // ErrResourceAlreadyExists represents an error when a resource already exists. ErrResourceAlreadyExists = errors.New("resource already exists") )
Functions ¶
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.
type Namespace ¶
type Namespace struct {
ResourceNode
// contains filtered or unexported fields
}
Namespace represents the namespace of UCP.
func NewNamespace ¶
NewNamespace creates a new namespace.
func (*Namespace) GenerateBuilder ¶
GenerateBuilder Builder object by traversing resource nodes from namespace.
func (*Namespace) SetAvailableOperations ¶
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.