server

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// APIVersion is a query string for the API version of Radius resource provider.
	APIVersionParam = "api-version"

	// CatchAllPath is the path for the catch-all route.
	CatchAllPath = "/*"
)

Variables

View Source
var (
	ErrInvalidOperationTypeOption = errors.New("the resource type and method must be specified if the operation type is not specified")
)

Functions

func ConfigureDefaultHandlers

func ConfigureDefaultHandlers(
	ctx context.Context,
	rootRouter chi.Router,
	rootScopePath string,
	isAzureProvider bool,
	providerNamespace string,
	operationCtrlFactory ControllerFactoryFunc,
	ctrlOpts ctrl.Options) error

ConfigureDefaultHandlers registers handlers for the default operations such as getting operationStatuses and operationResults, and updating a subscription lifecycle. It returns an error if any of the handler registrations fail.

func HandleError

func HandleError(ctx context.Context, w http.ResponseWriter, req *http.Request, err error)

HandleError handles unhandled errors from frontend controller and creates internal server error response based on the error type.

func HandlerForController

func HandlerForController(controller ctrl.Controller, operationType v1.OperationType) http.HandlerFunc

HandlerForController creates a http.HandlerFunc function that runs resource provider frontend controller, renders a http response from the returned rest.Response, and handles the error as a default internal error if this controller returns error.

func New

func New(ctx context.Context, options Options) (*http.Server, error)

New creates a frontend server that can listen on the provided address and serve requests - it creates an HTTP server with a router, configures the router with the given options, adds the default middlewares for logging, authentication, and service context, and then returns the server.

func NewSubrouter

func NewSubrouter(parent chi.Router, path string, middlewares ...func(http.Handler) http.Handler) chi.Router

NewSubrouter creates a new subrouter and mounts it on the parent router with the given middlewares.

func RegisterHandler

func RegisterHandler(ctx context.Context, opts HandlerOptions, ctrlOpts ctrl.Options) error

RegisterHandler registers a handler for the given resource type and method. This function should only be used for controllers that process a single resource type.

Types

type ControllerFactoryFunc

type ControllerFactoryFunc func(ctrl.Options) (ctrl.Controller, error)

type HandlerOptions

type HandlerOptions struct {
	// ParentRouter is the router to register the handler with.
	ParentRouter chi.Router

	// Path is the matched pattern for ParentRouter handler. This is optional and the default value is "/".
	Path string

	// ResourceType is the resource type of the operation. May be blank if Operation is specified.
	//
	// If specified the ResourceType will be used to filter the StorageClient.
	ResourceType string

	// Method is the method of the operation. May be blank if Operation is specified.
	//
	// If the specified the Method will be used to filter by HTTP method.
	Method v1.OperationMethod

	// OperationType designates the operation and should be unique per handler. May be blank if ResourceType and Method are specified.
	//
	// The OperationType is used in logs and other mechanisms to identify the kind of operation being performed.
	// If the OperationType is not specified, it will be inferred from that ResourceType and Method.
	OperationType *v1.OperationType

	// ControllerFactory is a function invoked to create the controller. Will be invoked once during server startup.
	ControllerFactory ControllerFactoryFunc

	// Middlewares are the middlewares to apply to the handler.
	Middlewares []func(http.Handler) http.Handler
}

HandlerOptions represents a controller to be registered with the server.

Each HandlerOptions should represent either a resource-type-scoped operation (e.g. GET on an `Applications.Core/controllers` resource) or a more general operation that works with multiple types of resources (e.g. PUT on any type of AWS resource): - Set ResourceType for operations that are scoped to a resource type. - Set OperationType for general operations.

In the controller options passed to the controller factory:

- When ResourceType is set, the StorageClient will be configured to use the resource type. - When OperationType is set, the StorageClient will be generic and not filtered to a specific resource type.

type Options

type Options struct {
	ServiceName   string
	Location      string
	Address       string
	PathBase      string
	EnableArmAuth bool
	Configure     func(chi.Router) error
	ArmCertMgr    *authentication.ArmCertManager
}

type Service

type Service struct {
	// ProviderName is the name of provider namespace.
	ProviderName string

	// Options is the server hosting options.
	Options hostoptions.HostOptions

	// StorageProvider is the provider of storage client.
	StorageProvider dataprovider.DataStorageProvider

	// OperationStatusManager is the manager of the operation status.
	OperationStatusManager manager.StatusManager

	// ARMCertManager is the certificate manager of client cert authentication.
	ARMCertManager *authentication.ArmCertManager

	// KubeClient is the Kubernetes controller runtime client.
	KubeClient controller_runtime.Client
}

Service is the base worker service implementation to initialize and start web service.

func (*Service) Init

func (s *Service) Init(ctx context.Context) error

Init initializes web service - it initializes the StorageProvider, QueueProvider, OperationStatusManager, KubeClient and ARMCertManager with the given context and returns an error if any of the initialization fails.

func (*Service) Start

func (s *Service) Start(ctx context.Context, opt Options) error

Start starts HTTP server, listening on a given address and shutdown the server gracefully when context is cancelled.

Jump to

Keyboard shortcuts

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