examagent

package
v0.0.0-...-2e8aeb9 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package examagent contains the main logic and helpers for the crownlabs exam agent component.

Package examagent contains the main logic and helpers for the crownlabs exam agent component.

Index

Constants

View Source
const (
	// XForwardedFor -> "X-Forwarded-For" header.
	XForwardedFor = "X-Forwarded-For"
)

Variables

View Source
var Options options

Options object holds all the examagent parameters.

Functions

func AcceptsHTML

func AcceptsHTML(r *http.Request) bool

AcceptsHTML returns true if the request accepts JSON.

func InstanceSpecFromAdapter

func InstanceSpecFromAdapter(instReq *InstanceAdapter) clv1alpha2.InstanceSpec

InstanceSpecFromAdapter creates an InstanceSpec from a given InstanceAdapter.

func NewK8sClient

func NewK8sClient() (client.Client, error)

NewK8sClient initializes the global k8s client.

func ValuesToMap

func ValuesToMap(values url.Values) map[string]string

ValuesToMap converts a url.Values to a map[string]string. In case of duplicate keys, the first value is used; in case of no values or empty first value, "true" is set automatically as a value.

func WriteError

func WriteError(w http.ResponseWriter, r *http.Request, log logr.Logger, code int, text string)

WriteError writes the error as a JSON or as an HTML page depending on the request type.

func WriteErrorJSON

func WriteErrorJSON(w http.ResponseWriter, code int, text string) error

WriteErrorJSON writes the error as a JSON to the given writer.

func WriteErrorPage

func WriteErrorPage(w http.ResponseWriter, code int, text string) error

WriteErrorPage writes the error page to the given writer.

func WriteJSON

func WriteJSON(w http.ResponseWriter, obj interface{}) error

WriteJSON writes the given object as JSON to the given writer.

func WriteStartupPage

func WriteStartupPage(w http.ResponseWriter) error

WriteStartupPage writes the startup page to the given writer.

Types

type AllowedIPs

type AllowedIPs string

AllowedIPs contains a list of IPs that are allowed to create new instances.

type HTTPErrorModel

type HTTPErrorModel struct {
	Code int    `json:"code"`
	Text string `json:"text"`
}

HTTPErrorModel is the model for the error page.

type InstanceAdapter

type InstanceAdapter struct {
	ID                string                               `json:"id"`
	Template          string                               `json:"template"`
	Running           *bool                                `json:"running,omitempty"`
	CustomizationUrls clv1alpha2.InstanceCustomizationUrls `json:"customizationUrls"`
	Phase             string                               `json:"phase"`
	URL               string                               `json:"url,omitempty"`
	Labels            map[string]string                    `json:"labels"`
}

InstanceAdapter represents an Instance within the examagent.

func AdapterFromInstance

func AdapterFromInstance(inst *clv1alpha2.Instance) *InstanceAdapter

AdapterFromInstance creates an InstanceAdapter from a given Instance.

func InstanceAdapterFromRequest

func InstanceAdapterFromRequest(r *http.Request, log logr.Logger) (InstanceAdapter, error)

InstanceAdapterFromRequest parses a InstanceAdapter from a request.

type InstanceHandler

type InstanceHandler struct {
	Log             logr.Logger
	Client          client.Client
	AdapterEndpoint string
}

InstanceHandler is the handler for the InstanceAdapter.

func (*InstanceHandler) EmptyInstanceFromRequest

func (ih *InstanceHandler) EmptyInstanceFromRequest(r *http.Request) *clv1alpha2.Instance

EmptyInstanceFromRequest returns an Instance from a given request with just the ObjectMeta field set.

func (*InstanceHandler) GetInstanceIDFromRequest

func (ih *InstanceHandler) GetInstanceIDFromRequest(r *http.Request) string

GetInstanceIDFromRequest returns the instance id from the request.

func (*InstanceHandler) HandleDelete

func (ih *InstanceHandler) HandleDelete(w http.ResponseWriter, r *http.Request, log logr.Logger)

HandleDelete handles the DELETE request for a InstanceAdapter api call.

func (*InstanceHandler) HandleGet

func (ih *InstanceHandler) HandleGet(w http.ResponseWriter, r *http.Request, log logr.Logger)

HandleGet handles the GET request for the examagent.

func (*InstanceHandler) HandleGetAll

func (ih *InstanceHandler) HandleGetAll(w http.ResponseWriter, r *http.Request, log logr.Logger)

HandleGetAll handles the GET request for all the instances.

func (*InstanceHandler) HandlePut

func (ih *InstanceHandler) HandlePut(w http.ResponseWriter, r *http.Request, log logr.Logger)

HandlePut handles the PUT request for a InstanceAdapter api call.

func (*InstanceHandler) ServeHTTP

func (ih *InstanceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is the Instance handler for the examagent.

type TemplateAdapter

type TemplateAdapter struct {
	Name       string      `json:"name"`
	PrettyName string      `json:"prettyName"`
	Persistent bool        `json:"persistent"`
	CreatedAt  metav1.Time `json:"createdAt"`
}

TemplateAdapter represents a Template within the examagent.

type TemplateHandler

type TemplateHandler struct {
	Log    logr.Logger
	Client client.Client
}

TemplateHandler is the handler for the TemplateAdapter.

func (*TemplateHandler) ServeHTTP

func (th *TemplateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is the handler for the TemplateAdapter.

Jump to

Keyboard shortcuts

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