service

package
v0.0.0-...-db2636d Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 68 Imported by: 13

Documentation

Overview

Package service exposes core UI and API endpoints.

Index

Constants

View Source
const (
	FlashSeveritySuccess = "success"
	FlashSeverityInfo    = "info"
	FlashSeverityWarning = "warning"
	FlashSeverityError   = "danger"
)
View Source
const (
	ProjectCookieName string = "mci-project-cookie"

	// Key values used to map user and project data to request context.
	// These are private custom types to avoid key collisions.
	RequestTask reqCtxKey = iota
	RequestProjectContext
)
View Source
const (
	WebRootPath  = "service"
	Templates    = "templates"
	Static       = "static"
	DefaultSkip  = 0
	DefaultLimit = 10
)
View Source
const (

	// Initial number of revisions to return on first page load
	InitRevisionsBefore = 50
	InitRevisionsAfter  = 100

	// Number of revisions to return on subsequent requests
	NoRevisions     = 0
	MaxNumRevisions = 50
)
View Source
const DefaultLogMessages = 100 // passed as a limit, so 0 means don't limit

the task's most recent log messages

View Source
const FlashSession = "mci-session"
View Source
const (
	IncludeSpawnedHosts = "includeSpawnedHosts"
)
View Source
const NumRecentVersions = 10
View Source
const RestContext restContextKey = 0
View Source
const (
	// The resolution of times stored in the database
	TimePrecision = time.Millisecond
)

Variables

View Source
var (
	HostRename                 = "changeHostDisplayName"
	HostPasswordUpdate         = "updateRDPPassword"
	HostInstanceTypeUpdate     = "updateInstanceType"
	HostTagUpdate              = "updateHostTags"
	HostExpirationExtension    = "extendHostExpiration"
	HostTerminate              = "terminate"
	HostStop                   = "stop"
	HostStart                  = "start"
	VolumeRename               = "changeVolumeDisplayName"
	VolumeExtendExpiration     = "extendVolumeExpiration"
	VolumeSetNoExpiration      = "setVolumeNoExpiration"
	VolumeSetHasExpiration     = "setVolumeHasExpiration"
	VolumeAttach               = "attachVolume"
	VolumeDetach               = "detachVolume"
	VolumeDelete               = "deleteVolume"
	MaxExpirationDurationHours = 24 * 7 // 7 days
)
View Source
var NumTasksToSearchForTestNames = 10

Functions

func ForbiddenHandler

func ForbiddenHandler(w http.ResponseWriter, r *http.Request)

ForbiddenHandler logs a rejected request befure returning a 403 to the client

func GetHost

func GetHost(r *http.Request) *host.Host

GetHost loads the host attached to a request

func GetListener

func GetListener(addr string) (net.Listener, error)

GetListener creates a network listener on the given address.

func GetProject

func GetProject(r *http.Request) *model.Project

GetProject loads the project attached to a request into request context.

func GetProjectContext

func GetProjectContext(r *http.Request) (projectContext, error)

GetProjectContext fetches the projectContext associated with the request. Returns an error if no projectContext has been loaded and attached to the request.

func GetRESTContext

func GetRESTContext(r *http.Request) (*model.Context, error)

GetRESTContext fetches the context associated with the request.

func GetRESTv1App

func GetRESTv1App(evgService restAPIService) *gimlet.APIApp

GetRESTv1App attaches a router at the given root that hooks up REST endpoint URIs to be handled by the given restAPIService.

func GetRouter

func GetRouter(as *APIServer, uis *UIServer) (http.Handler, error)

func GetServer

func GetServer(addr string, n http.Handler) *http.Server

GetServer produces an HTTP server instance for a handler.

func GetTLSListener

func GetTLSListener(addr string, conf *tls.Config) (net.Listener, error)

GetTLSListener creates an encrypted listener with the given TLS config and address.

func GetTask

func GetTask(r *http.Request) *task.Task

GetTask loads the task attached to a request.

func MakeTemplateFuncs

func MakeTemplateFuncs(fo TemplateFunctionOptions) map[string]interface{}

MakeTemplateFuncs creates and registers all of our built-in template functions.

func MustHaveHost

func MustHaveHost(r *http.Request) *host.Host

MustHaveHost gets the host from the HTTP Request Panics if the host is not in the request context

func MustHaveProject

func MustHaveProject(r *http.Request) *model.Project

MustHaveProject gets the project from the HTTP request and panics if there is no project specified

func MustHaveProjectContext

func MustHaveProjectContext(r *http.Request) projectContext

MustHaveProjectContext gets the projectContext from the request, or panics if it does not exist.

func MustHaveRESTContext

func MustHaveRESTContext(r *http.Request) *model.Context

MustHaveRESTContext fetches the model.Context stored with the request, and panics if the key is not set.

func MustHaveTask

func MustHaveTask(r *http.Request) *task.Task

MustHaveTask gets the task from an HTTP Request. Panics if the task is not in request context.

func MustHaveUser

func MustHaveUser(r *http.Request) *user.DBUser

MustHaveUser gets the user from the request or panics if it does not exist.

func NewErrorFlash

func NewErrorFlash(message string) flashMessage

func NewInfoFlash

func NewInfoFlash(message string) flashMessage

func NewSuccessFlash

func NewSuccessFlash(message string) flashMessage

func NewWarningFlash

func NewWarningFlash(message string) flashMessage

func PopFlashes

func PopFlashes(store *sessions.CookieStore, r *http.Request, w http.ResponseWriter) []interface{}

func PushFlash

func PushFlash(store *sessions.CookieStore, r *http.Request, w http.ResponseWriter, msg flashMessage)

func RedirectIfSpruceSet

func RedirectIfSpruceSet(w http.ResponseWriter, r *http.Request, u *user.DBUser, redirect, UIv2Url string) bool

RedirectIfSpruceSet redirects the user to spruce only if they aren't visiting this page from spruce already and have spruce enabled

func RedirectSpruceUsers

func RedirectSpruceUsers(w http.ResponseWriter, r *http.Request, redirect string) bool

Types

type APIServer

type APIServer struct {
	UserManager gimlet.UserManager
	Settings    evergreen.Settings
	// contains filtered or unexported fields
}

APIServer handles communication with Evergreen agents and other back-end requests.

func NewAPIServer

func NewAPIServer(env evergreen.Environment, queue amboy.Queue) (*APIServer, error)

NewAPIServer returns an APIServer initialized with the given settings and plugins.

func (*APIServer) FetchTask

func (as *APIServer) FetchTask(w http.ResponseWriter, r *http.Request)

FetchTask loads the task from the database and sends it to the requester.

func (*APIServer) GetServiceApp

func (as *APIServer) GetServiceApp() *gimlet.APIApp

NewRouter returns the root router for all APIServer endpoints. These routes are deprecated; any new functionality should be added to REST v2

func (*APIServer) GetSettings

func (as *APIServer) GetSettings() evergreen.Settings

GetSettings returns the global evergreen settings.

func (*APIServer) LoggedError

func (as *APIServer) LoggedError(w http.ResponseWriter, r *http.Request, code int, err error)

LoggedError logs the given error and writes an HTTP response with its details formatted as JSON if the request headers indicate that it's acceptable (or plaintext otherwise).

type BuildInfo

type BuildInfo struct {
	Id          string     `json:"id"`
	DisplayName string     `json:"display_name"`
	Tasks       []TaskInfo `json:"tasks"`
}

type PatchAPIResponse

type PatchAPIResponse struct {
	Message string       `json:"message"`
	Action  string       `json:"action"`
	Patch   *patch.Patch `json:"patch"`
}

PatchAPIResponse is returned by all patch-related API calls

type PatchInfo

type PatchInfo struct {
	Id            string    `json:"id"`
	Version       string    `json:"version"`
	Author        string    `json:"author"`
	CreateTime    time.Time `json:"create_time"`
	Project       string    `json:"project"`
	Description   string    `json:"description"`
	Githash       string    `json:"githash"`
	BaseVersionId string    `json:"base_version_id"`
	Alias         string    `json:"alias"`
}

type RestPatch

type RestPatch struct {
	Id          string              `json:"_id"`
	Description string              `json:"desc"`
	Project     string              `json:"project"`
	Revision    string              `json:"revision"`
	PatchNumber int                 `json:"patch_number"`
	Author      string              `json:"author"`
	Version     string              `json:"version"`
	CreateTime  time.Time           `json:"create_time"`
	Patches     []patch.ModulePatch `json:"patches"`
}

type RestTask

type RestTask struct {
	Id                  string                `json:"id"`
	CreateTime          time.Time             `json:"create_time"`
	ScheduledTime       time.Time             `json:"scheduled_time"`
	DispatchTime        time.Time             `json:"dispatch_time"`
	StartTime           time.Time             `json:"start_time"`
	FinishTime          time.Time             `json:"finish_time"`
	Version             string                `json:"version"`
	Project             string                `json:"project"`
	Revision            string                `json:"revision"`
	Priority            int64                 `json:"priority"`
	LastHeartbeat       time.Time             `json:"last_heartbeat"`
	Activated           bool                  `json:"activated"`
	BuildId             string                `json:"build_id"`
	DistroId            string                `json:"distro"`
	Container           string                `json:"container,omitempty"`
	BuildVariant        string                `json:"build_variant"`
	DependsOn           []task.Dependency     `json:"depends_on"`
	DisplayName         string                `json:"display_name"`
	HostId              string                `json:"host_id"`
	Execution           int                   `json:"execution"`
	Archived            bool                  `json:"archived"`
	RevisionOrderNumber int                   `json:"order"`
	Requester           string                `json:"requester"`
	Status              string                `json:"status"`
	StatusDetails       taskStatusDetails     `json:"status_details"`
	Aborted             bool                  `json:"aborted"`
	TimeTaken           time.Duration         `json:"time_taken"`
	ExpectedDuration    time.Duration         `json:"expected_duration"`
	LocalTestResults    taskTestResultsByName `json:"test_results"`
	MinQueuePos         int                   `json:"min_queue_pos"`
	PatchNumber         int                   `json:"patch_number,omitempty"`
	PatchId             string                `json:"patch_id,omitempty"`
	ModulePaths         map[string]string     `json:"module_paths,omitempty"`

	// Artifacts and binaries
	Files []taskFile `json:"files"`
}

type TaskInfo

type TaskInfo struct {
	Id          string                  `json:"id"`
	DisplayName string                  `json:"display_name"`
	Status      string                  `json:"status"`
	Details     apimodels.TaskEndDetail `json:"status_details"`
}

type TemplateFunctionOptions

type TemplateFunctionOptions struct {
	WebHome  string
	HelpHome string
}

FuncOptions are global variables injected into our templating functions.

type TestServer

type TestServer struct {
	URL string
	net.Listener
	*APIServer
	// contains filtered or unexported fields
}

func CreateTestServer

func CreateTestServer(settings *evergreen.Settings, tlsConfig *tls.Config, loadUserManager bool) (*TestServer, error)

func (*TestServer) Close

func (s *TestServer) Close()

type UIBuild

type UIBuild struct {
	Id         string    `json:"id"`
	CreateTime time.Time `json:"create_time"`
	StartTime  time.Time `json:"start_time"`
	FinishTime time.Time `json:"finish_time"`
	Version    string    `json:"version"`
	Status     string    `json:"status"`
	TimeTaken  int64     `json:"time_taken"`
}

UIBuild has the fields that are necessary to send over the wire for builds

type UIBuildVariant

type UIBuildVariant struct {
	Name         string          `json:"name"`
	TaskNames    []string        `json:"task_names"`
	DisplayTasks []UIDisplayTask `json:"display_tasks"`
}

UIBuildVariant contains the name of the build variant and the tasks associated with that build variant.

type UIDisplayTask

type UIDisplayTask struct {
	Name           string   `json:"name"`
	ExecutionTasks []string `json:"execution_tasks"`
}

type UIProject

type UIProject struct {
	Name          string           `json:"name"`
	BuildVariants []UIBuildVariant `json:"build_variants"`
	TaskNames     []string         `json:"task_names"`
}

UIProject has all the tasks that are in a project and all the BuildVariants.

type UIServer

type UIServer struct {

	// Home is the root path on disk from which relative urls are constructed for loading
	// plugins or other assets.
	Home string

	// The root URL of the server, used in redirects for instance.
	RootURL string

	Settings    evergreen.Settings
	CookieStore *sessions.CookieStore

	plugin.PanelManager
	// contains filtered or unexported fields
}

UIServer provides a web interface for Evergreen.

func NewUIServer

func NewUIServer(env evergreen.Environment, queue amboy.Queue, home string, fo TemplateFunctionOptions) (*UIServer, error)

func (*UIServer) GetCommonViewData

func (uis *UIServer) GetCommonViewData(w http.ResponseWriter, r *http.Request, needsUser, needsProject bool) ViewData

GetCommonViewData returns a struct that can supplement the struct used to provide data to views. It contains data that is used for most/all Evergreen pages. The needsUser and needsProject params will cause an error to be logged if there is no user/project. Data will not be returned if the project cannot be found.

func (*UIServer) GetManifest

func (uis *UIServer) GetManifest(w http.ResponseWriter, r *http.Request)

func (*UIServer) GetPluginHandler

func (uis *UIServer) GetPluginHandler(uiPage *plugin.UIPage, pluginName string) func(http.ResponseWriter, *http.Request)

GetPluginHandler returns a handler function given the template route and data to go to that page.

func (*UIServer) GetServiceApp

func (uis *UIServer) GetServiceApp() *gimlet.APIApp

NewRouter sets up a request router for the UI, installing hard-coded routes as well as those belonging to plugins.

func (*UIServer) GetSettings

func (uis *UIServer) GetSettings() evergreen.Settings

GetSettings returns the global evergreen settings.

func (*UIServer) LoadProjectContext

func (uis *UIServer) LoadProjectContext(rw http.ResponseWriter, r *http.Request) (projectContext, error)

LoadProjectContext builds a projectContext from vars in the request's URL. This is done by reading in specific variables and inferring other required context variables when necessary (e.g. loading a project based on the task).

func (*UIServer) LoggedError

func (uis *UIServer) LoggedError(w http.ResponseWriter, r *http.Request, code int, err error)

LoggedError logs the given error and writes an HTTP response with its details formatted as JSON if the request headers indicate that it's acceptable (or plaintext otherwise).

func (*UIServer) RedirectToLogin

func (uis *UIServer) RedirectToLogin(w http.ResponseWriter, r *http.Request)

RedirectToLogin forces a redirect to the login page. The redirect param is set on the query so that the user will be returned to the original page after they login.

type UIStats

type UIStats struct {
	Tasks    []*UITask       `json:"tasks"`
	Builds   []*UIBuild      `json:"builds"`
	Versions []model.Version `json:"versions"`
	Patches  []patch.Patch   `json:"patches"`
}

UIStats is all of the data that the stats page might need.

type UITask

type UITask struct {
	Id                     string    `json:"id"`
	CreateTime             time.Time `json:"create_time"`
	DispatchTime           time.Time `json:"dispatch_time"`
	ScheduledTime          time.Time `json:"scheduled_time"`
	ContainerAllocatedTime time.Time `json:"container_allocated_time,omitempty"`
	StartTime              time.Time `json:"start_time"`
	FinishTime             time.Time `json:"finish_time"`
	Version                string    `json:"version"`
	Status                 string    `json:"status"`
	Host                   string    `json:"host"`
	Distro                 string    `json:"distro"`
	Container              string    `json:"container,omitempty"`
	IsDisplay              bool      `json:"is_display"`
}

UITask has the fields that are necessary to send over the wire for tasks

type ViewData

type ViewData struct {
	User        *user.DBUser
	ProjectData projectContext
	Project     model.Project
	Flashes     []interface{}
	Banner      string
	BannerTheme string
	Csrf        htmlTemplate.HTML
	JiraHost    string
	NewRelic    evergreen.NewRelicConfig
	IsAdmin     bool
	NewUILink   string
}

ViewData contains common data that is provided to all Evergreen pages

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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