handler

package
v0.0.0-...-4718e07 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NoUsernameError is the error message that will be displayed if
	// no username can be determined from the HTTP request
	NoUsernameError = "Unable to find username"

	// NoEmailError is the error message that will be displayed if
	// no email can be determined from the HTTP request
	NoEmailError = "Unable to find email"

	// ParsingError parsing failed on a field.
	ParsingError = "Unable to parse value"

	// InvalidOrExpiredCSRF is the error message that will be
	// displayed if a csrf token presented is invalid or expired
	InvalidOrExpiredCSRF = "Invalid or expired CSRF token"

	// RouteVarMissing indicates a bad route/handler match.
	RouteVarMissing = "Invalid route; missing variable"

	// UnspecifiedError indicates that an error message could not be specified.
	UnspecifiedError = "Unspecified error encountered"

	// FailedToLoadUserError indicates a user could not be loaded
	FailedToLoadUserError = "User could not be loaded"

	// ResponseMissingError indicates an action name was not specified
	ResponseMissingError = "Response not specified"

	// ObjectNotSupportedError indicates that the object type specified
	// is inappropriate.
	ObjectNotSupportedError = "Requested object type is not supported"

	// ValueMissingError indicates a required value (such as an argument)
	// is not present.
	ValueMissingError = "Value is missing"
)
View Source
const (
	// ErrorTemplateName is the name of our error template.
	ErrorTemplateName = "error"

	// ErrorsTemplateName is the name of our multiple error template.
	ErrorsTemplateName = "errors"
)
View Source
const (
	// ObjTypeParam is the key used to represent the type of an object
	// being requested to in a response
	ObjTypeParam = "objecttype"

	// ObjIDParam is the key used to represent the ID of an object being
	// requested or in a response
	ObjIDParam = "id"

	// ObjTimeStampParam is the key used to represent the timestamp of
	// a request or a response
	ObjTimeStampParam = "ts"
)
View Source
const (
	// CSRFParamName is the parameter name for submitted CSRF tokens.
	CSRFParamName = "csrf_token"
)
View Source
const (
	// IndexPageTemplateName is the name of the template that is used
	// to represent the index of the application
	IndexPageTemplateName = "indexPage"
)

Variables

This section is empty.

Functions

func CheckCSRFAPI

func CheckCSRFAPI(
	w ResponseWriter,
	request *http.Request,
	ctx apiContext,
) error

CheckCSRFAPI checks submitted CSRF token and returns an error if it is not valid or is missing.

func CheckCSRFWeb

func CheckCSRFWeb(
	w ResponseWriter,
	request *http.Request,
	ctx webContext,
) error

CheckCSRFWeb checks submitted CSRF token and returns an error if it is not valid or is missing.

func CheckHandlerWeb

func CheckHandlerWeb(w ResponseWriter, request *http.Request, ctx webContext) error

CheckHandlerWeb will check that the object is allowed to be moved into the check required state and will display the form to allow the user to set the check required bit

func CheckUpdateHandlerWeb

func CheckUpdateHandlerWeb(w ResponseWriter, request *http.Request, ctx webContext) error

CheckUpdateHandlerWeb handles the check required update request for and object. The function will verify that the user is allowed to make the change (is an admin) and then will set the check required bit on the object

func DBCheckWeb

func DBCheckWeb(w ResponseWriter, request *http.Request, ctx webContext) error

DBCheckWeb is used as a status check for the database of the application

func DomainNameToID

func DomainNameToID(w ResponseWriter, request *http.Request, ctx apiContext) (err error)

DomainNameToID attempt to convert a domain name into a domain ID. If an error occurs, the error will be returned

func EPPPassphrase

func EPPPassphrase(w ResponseWriter, request *http.Request, ctx apiContext) (err error)

EPPPassphrase is used to handle requests to get or save the encrypted EPP user passphrase.

func EndEPPRun

func EndEPPRun(w ResponseWriter, request *http.Request, ctx apiContext) (err error)

EndEPPRun is used to mark an EPP run as completed in the database

func GetHostIPAllowList

func GetHostIPAllowList(w ResponseWriter, request *http.Request, ctx apiContext) (err error)

GetHostIPAllowList is used to retrieve the list of IPs that are contained in the host ip allow list if one is set. If an error occurs while trying to obtain the list of IPs, it will be returned

func GetHostNames

func GetHostNames(w ResponseWriter, request *http.Request, ctx apiContext) (err error)

GetHostNames will generate an api response with a map of hostnames to ids

func GetProtectedDomainList

func GetProtectedDomainList(w ResponseWriter, request *http.Request, ctx apiContext) (err error)

GetProtectedDomainList is used to retrieve the list of proteced domains that in the database. If an error occurs trying to obtain the list, the error will be returned

func GetServerLocksWorkWeb

func GetServerLocksWorkWeb(w ResponseWriter, request *http.Request, ctx webContext) (err error)

GetServerLocksWorkWeb will generate a list of domains that need to be locked or unlocked in order to operate on the domains.

func GetTokenHandlerAPI

func GetTokenHandlerAPI(w ResponseWriter, request *http.Request, ctx apiContext) error

GetTokenHandlerAPI is used to generate a token for an API request and will respond with the token in a JSON serialized format

func GetWorkHandlerAPI

func GetWorkHandlerAPI(w ResponseWriter, request *http.Request, ctx apiContext) (err error)

GetWorkHandlerAPI will generate a list of items that are pending work for the object type provided. The lists of items will be serialized into JSON before returning the data to the user.

func HoldUpdateHandlerWeb

func HoldUpdateHandlerWeb(w ResponseWriter, request *http.Request, ctx webContext) error

HoldUpdateHandlerWeb handles updates to object holds. The function will first check to see if the user is allowed to make the change (admin) and then that the object is allowed to be placed on hold.

func HomeHandlerWeb

func HomeHandlerWeb(w ResponseWriter, request *http.Request, ctx webContext) error

HomeHandlerWeb handles request for the home page of the application

func LivenessCheck

func LivenessCheck(w ResponseWriter, request *http.Request, ctx noAuthWebContext) (err error)

LivenessCheck will handle the process of requesting the liveness status from the server and returning the correct status depending on the response from lib in order to inform GTM of the state of the server

func LogEPPAction

func LogEPPAction(w ResponseWriter, request *http.Request, ctx apiContext) (err error)

LogEPPAction is used to log an epp action that was taken. If an error occurs while processing the request, it will be returned.

func NewHandlerWeb

func NewHandlerWeb(w ResponseWriter, request *http.Request, ctx webContext) error

NewHandlerWeb handles the new action for all objects that implement the RegistrarObject interface.

func RenewCheck

func RenewCheck(w ResponseWriter, request *http.Request, ctx noAuthWebContext) (err error)

RenewCheck will check for domains that need to be renewed (domains that have less than 1 year before it expires)

func RequireAdminAPIUser

func RequireAdminAPIUser(w ResponseWriter, request *http.Request, ctx apiContext) error

RequireAdminAPIUser will ensure that the requests are being made by an admin API user.

func SaveHandlerWeb

func SaveHandlerWeb(w ResponseWriter, request *http.Request, ctx webContext) error

SaveHandlerWeb handles the save action for all objects that implement the RegistrarObject interface.

func SetHostIPAllowList

func SetHostIPAllowList(w ResponseWriter, request *http.Request, ctx apiContext) (err error)

SetHostIPAllowList is used to set the HostIPAllowList in the registrar application. If an error occurs while trying to set the IP allow list it will be returned

func SetProtectedDomainList

func SetProtectedDomainList(w ResponseWriter, request *http.Request, ctx apiContext) (err error)

SetProtectedDomainList is used to set the Protected Domain list in the registrar application. If an error occurs while trying to set the IP allowlist it will be returned

func StartEPPRun

func StartEPPRun(w ResponseWriter, request *http.Request, ctx apiContext) (err error)

StartEPPRun is used to create a new run ID for an EPP run and return the id to the client so it can be used as a unique key for the client transaction ids that are sent to the registry

func TakeActionHandlerAPI

func TakeActionHandlerAPI(w ResponseWriter, request *http.Request, ctx apiContext) error

TakeActionHandlerAPI is used to handle the take action request for API based requests.

func TakeActionHandlerWeb

func TakeActionHandlerWeb(w ResponseWriter, request *http.Request, ctx webContext) error

TakeActionHandlerWeb is used to handle the take action request for web based requests.

func ToForm

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

ToForm will take a map of keys to a valies and generate a url.Values object that can be used to represent a form

func UpdateHandlerWeb

func UpdateHandlerWeb(w ResponseWriter, request *http.Request, ctx webContext) error

UpdateHandlerWeb handles an update request from the web interface and will redirect the user to the object's page when the action is completed assuming no error was encountered

func ViewAllHandlerAPI

func ViewAllHandlerAPI(w ResponseWriter, request *http.Request, ctx apiContext) (err error)

ViewAllHandlerAPI will generate a JSON respons listing all of the object IDs for a given object type

func ViewAllHandlerWeb

func ViewAllHandlerWeb(w ResponseWriter, request *http.Request, ctx webContext) error

ViewAllHandlerWeb will generate a page listing all objects for an object type

func ViewAtHandlerAPI

func ViewAtHandlerAPI(w ResponseWriter, request *http.Request, ctx apiContext) error

ViewAtHandlerAPI is used to serialize a JSON form of the object for api requests with a version of the object from a specific point in time

func ViewHandlerAPI

func ViewHandlerAPI(w ResponseWriter, request *http.Request, ctx apiContext) error

ViewHandlerAPI is used to return an API request to get an object's information in a json serialized format

func ViewHandlerWeb

func ViewHandlerWeb(w ResponseWriter, request *http.Request, ctx webContext) error

ViewHandlerWeb is used to display an object's information using the templates provided to the factory

func WHOISConfirmEmail

func WHOISConfirmEmail(w ResponseWriter, request *http.Request, ctx noAuthWebContext) (err error)

WHOISConfirmEmail will review all domains and send WHOIS confirmation emails as required by ICANN once per year based on the registration date

Types

type APIHandlerFunc

type APIHandlerFunc func(ResponseWriter, *http.Request, apiContext) error

APIHandlerFunc is an function definition that API functions must implement to be handled by the API handler factory.

type Context

type Context interface {
	// GetRouteVars returns variables gorilla mux collected from the route.
	GetRouteVars() map[string]string
	// GetUsername returns the username of the requester.
	GetUsername() string
	// GetDB returns a DB handle.
	GetDB() *lib.DBCache
	// GetConf returns the application's configuration
	GetConf() lib.Config
	// GetLogger returns the application's logger facility
	GetLogger() *logging.Logger
	// LogRequest is used to log a request from teh current context
	LogRequest(level logging.Level, url, function, message string)

	// GetLivenessCheckFunc is used to retrieve the liveness check function
	// for the server. If no function is present, nil is returned
	GetLivenessCheckFunc() *LivenessCheckFunc
}

Context represents state surrounding a request.

type ErrorPage

type ErrorPage struct {
	ErrorMessage   string
	TargetLink     string
	TargetLinkText string
}

ErrorPage is used whe rendering the Error Page HTML Template

func MakeErrorPage

func MakeErrorPage(referer string, err error) ErrorPage

MakeErrorPage generates a page for use with ErrorTemplateName passing the text of the error to be displayed in.

type ErrorsPage

type ErrorsPage struct {
	ErrorMessages  []string
	TargetLink     string
	TargetLinkText string
}

ErrorsPage is used when rendering the Errors (list of errors) Page HTML Template

func MakeErrorsPage

func MakeErrorsPage(referer string, errs []error) ErrorsPage

MakeErrorsPage is used to generate an error reponse page for an action that returns multiple errors

type Factory

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

Factory is a structure that provides the ability to wrap handler functions while adding application specific checks that are common across request types such as user verification

func NewFactory

func NewFactory(conf lib.Config, db *lib.DBCacheFactory, templates *template.Template, logger *logging.Logger, liveness *LivenessCheckFunc) *Factory

NewFactory is used to take the application context information and will generate and return a handler Factory object

func (*Factory) ForAPI

func (factory *Factory) ForAPI(handlers ...APIHandlerFunc) http.Handler

ForAPI will take a list of APIFuncs and return a http.Handler object that can be passed to a router to server http requests natively in the API context (checking for an authorized user and display the api response or an error(s) if one occurs)

func (*Factory) ForNoAuthWeb

func (factory *Factory) ForNoAuthWeb(handlers ...NoAuthWebHandlerFunc) http.Handler

ForNoAuthWeb will take a list of NoAuthWebFuncs and return a http.Handler object that can be passed to a router to server http requests natively in the web context without an authenticated user.

func (*Factory) ForWeb

func (factory *Factory) ForWeb(handlers ...WebHandlerFunc) http.Handler

ForWeb will take a list of WebFuncs and return a http.Handler object that can be passed to a router to serve http requests natively in the web context (checking for a user and display the page if no error occurs and an error page if any error happens)

type Func

type Func func(ResponseWriter, *http.Request)

Func is a function defention that must be implemented in order to be similar to the standard http.HandlerFunc with the ResponseWriter defined in this package

type Handler

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

Handler ss a structure that is used to wrap a http function call with parameters related to the application

func (*Handler) ServeHTTP

func (wrapper *Handler) ServeHTTP(response http.ResponseWriter, request *http.Request)

ServeHTTP imitates the ServeHTTP function from the net/http package but wraps the ResponseWriter from net/http with the versino defined in the package

type IndexPage

type IndexPage struct {
	WorkDomains []lib.Domain
	WorkHosts   []lib.Host
}

IndexPage is used when rendering the HTML Template for the default index page

type LivenessCheckFunc

type LivenessCheckFunc func(*lib.DBCache) (float64, error)

LivenessCheckFunc is the type of the liveness check function that can be implemented

type NoAuthWebHandlerFunc

type NoAuthWebHandlerFunc func(ResponseWriter, *http.Request, noAuthWebContext) error

NoAuthWebHandlerFunc is a function definition that web functions that do not require authentication implement to be handled by the no auth web handler factory

type ResponseWriter

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

ResponseWriter implements and wraps http.ResponseWriter while providing common rendering functions.

func WrapResponseWriter

func WrapResponseWriter(
	writer http.ResponseWriter,
	templates *template.Template,
	conf lib.Config,
) ResponseWriter

WrapResponseWriter takes a http.ResponseWriter and common application objects and wraps the resonse writer to allow the use to templates and error generation

func (ResponseWriter) DisplayError

func (w ResponseWriter) DisplayError(referer string, err error, username ...string) error

DisplayError will use the provided error and it will generate an error page using the error template

func (ResponseWriter) DisplayErrors

func (w ResponseWriter) DisplayErrors(referer string, errs []error, username ...string) error

DisplayErrors will use the provided errors and it will generate an errors page using the errors template

func (ResponseWriter) DisplayTemplate

func (w ResponseWriter) DisplayTemplate(name string, page interface{}, usernameOpt ...string) error

DisplayTemplate renders a template, if provided an RegistrarObjectPage and a username, sets CSRF token.

func (ResponseWriter) HasWritten

func (w ResponseWriter) HasWritten() bool

HasWritten will return true iff the response writer has had any data written to it

func (ResponseWriter) Header

func (w ResponseWriter) Header() http.Header

Header returns the header map that will be sent by WriteHeader. Changing the header after a call to WriteHeader (or Write) has no effect.

func (ResponseWriter) MustDisplayError

func (w ResponseWriter) MustDisplayError(referer string, err error, username ...string)

MustDisplayError will cause an internal server error if the error template fails to generate.

func (ResponseWriter) MustSendAPIError

func (w ResponseWriter) MustSendAPIError(err error)

MustSendAPIError will attempt to send the api and if an error occurs when generating the response, a http error will be sent

func (ResponseWriter) Redirect

func (w ResponseWriter) Redirect(request *http.Request, loc string, status int) error

Redirect redirects the request to the provided location with the given status code

func (ResponseWriter) SendAPIError

func (w ResponseWriter) SendAPIError(err error) error

SendAPIError will generate an API error response and serialize it to send to the requestor

func (ResponseWriter) SendAPIErrors

func (w ResponseWriter) SendAPIErrors(errs []error) error

SendAPIErrors will generate an API error response witht he errors provided and serialize it to send to the requestor

func (ResponseWriter) SendAPIResponse

func (w ResponseWriter) SendAPIResponse(response lib.APIResponse) error

SendAPIResponse will serielize the API response and send it to the requestor as the response

func (ResponseWriter) Write

func (w ResponseWriter) Write(data []byte) (int, error)

Write writes the data to the connection as part of an HTTP reply. If WriteHeader has not yet been called, Write calls WriteHeader(http.StatusOK) before writing the data. If the Header does not contain a Content-Type line, Write adds a Content-Type set to the result of passing the initial 512 bytes of written data to DetectContentType.

func (ResponseWriter) WriteHeader

func (w ResponseWriter) WriteHeader(status int)

WriteHeader sends an HTTP response header with status code. If WriteHeader is not called explicitly, the first call to Write will trigger an implicit WriteHeader(http.StatusOK). Thus explicit calls to WriteHeader are mainly used to send error codes.

type WebHandlerFunc

type WebHandlerFunc func(ResponseWriter, *http.Request, webContext) error

WebHandlerFunc is a function definition that web functions must implement to be handled by the web handler factory

Jump to

Keyboard shortcuts

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