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
- Variables
- func AcceptsHTML(r *http.Request) bool
- func InstanceSpecFromAdapter(instReq *InstanceAdapter) clv1alpha2.InstanceSpec
- func NewK8sClient() (client.Client, error)
- func ValuesToMap(values url.Values) map[string]string
- func WriteError(w http.ResponseWriter, r *http.Request, log logr.Logger, code int, text string)
- func WriteErrorJSON(w http.ResponseWriter, code int, text string) error
- func WriteErrorPage(w http.ResponseWriter, code int, text string) error
- func WriteJSON(w http.ResponseWriter, obj interface{}) error
- func WriteStartupPage(w http.ResponseWriter) error
- type AllowedIPs
- type HTTPErrorModel
- type InstanceAdapter
- type InstanceHandler
- func (ih *InstanceHandler) EmptyInstanceFromRequest(r *http.Request) *clv1alpha2.Instance
- func (ih *InstanceHandler) GetInstanceIDFromRequest(r *http.Request) string
- func (ih *InstanceHandler) HandleDelete(w http.ResponseWriter, r *http.Request, log logr.Logger)
- func (ih *InstanceHandler) HandleGet(w http.ResponseWriter, r *http.Request, log logr.Logger)
- func (ih *InstanceHandler) HandleGetAll(w http.ResponseWriter, r *http.Request, log logr.Logger)
- func (ih *InstanceHandler) HandlePut(w http.ResponseWriter, r *http.Request, log logr.Logger)
- func (ih *InstanceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type TemplateAdapter
- type TemplateHandler
Constants ¶
const (
// XForwardedFor -> "X-Forwarded-For" header.
XForwardedFor = "X-Forwarded-For"
)
Variables ¶
var Options options
Options object holds all the examagent parameters.
Functions ¶
func AcceptsHTML ¶
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 ¶
NewK8sClient initializes the global k8s client.
func ValuesToMap ¶
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 ¶
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 ¶
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 ¶
InstanceAdapterFromRequest parses a InstanceAdapter from a request.
type InstanceHandler ¶
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 ¶
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.