client

package
v0.0.0-...-5f5e9cb Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 27 Imported by: 12

Documentation

Overview

Package client provides a REST client for API requests to the server.

Index

Constants

This section is empty.

Variables

View Source
var (
	// AuthError is a special error when the CLI receives 401 Unauthorized to
	// suggest logging in again as a possible solution to the error.
	AuthError = "Possibly user credentials are expired, try logging in again via the Evergreen web UI."
	// VPNError is a special error when the CLI receives 403 Forbidden to
	// suggest checking VPN connection as a possible solution to the error.
	VPNError = "VPN connection required: please make sure you're on the VPN and have access to Evergreen."
)

Functions

func GetOAuthToken

func GetOAuthToken(ctx context.Context, doNotUseBrowser bool, opts ...dex.ClientOption) (*oauth2.Token, string, error)

Types

type Communicator

type Communicator interface {
	// Setters
	//
	// SetTimeoutStart sets the initial timeout for a request.
	SetTimeoutStart(time.Duration)
	// SetTimeoutMax sets the maximum timeout for a request.
	SetTimeoutMax(time.Duration)
	// SetMaxAttempts sets the number of attempts a request will be made.
	SetMaxAttempts(int)
	// Client authentication methods (for users)
	SetAPIUser(string)
	SetAPIKey(string)
	SetOAuth(string)
	SetAPIServerHost(string)
	// Client authentication methods (for hosts)
	SetHostID(string)
	SetHostSecret(string)
	// Method to release resources used by the communicator.
	Close()

	// Admin methods
	//
	SetBannerMessage(context.Context, string, evergreen.BannerTheme) error
	GetBannerMessage(context.Context) (string, error)
	GetUiV2URL(context.Context) (string, error)
	SetServiceFlags(context.Context, *restmodel.APIServiceFlags) error
	GetServiceFlags(context.Context) (*restmodel.APIServiceFlags, error)
	IsServiceUser(context.Context, string) (bool, error)
	RestartRecentTasks(context.Context, time.Time, time.Time) error
	GetSettings(context.Context) (*evergreen.Settings, error)
	UpdateSettings(context.Context, *restmodel.APIAdminSettings) (*restmodel.APIAdminSettings, error)
	GetEvents(context.Context, time.Time, int) ([]any, error)
	RevertSettings(context.Context, string) error
	GetServiceUsers(ctx context.Context) ([]restmodel.APIDBUser, error)
	UpdateServiceUser(context.Context, string, string, []string) error
	DeleteServiceUser(context.Context, string) error

	// Spawnhost methods
	//
	CreateSpawnHost(context.Context, *restmodel.HostRequestOptions) (*restmodel.APIHost, error)
	GetSpawnHost(context.Context, string) (*restmodel.APIHost, error)
	ModifySpawnHost(context.Context, string, host.HostModifyOptions) error
	StopSpawnHost(context.Context, string, string, bool, bool) error
	StartSpawnHost(context.Context, string, string, bool) error
	TerminateSpawnHost(context.Context, string) error
	ChangeSpawnHostPassword(context.Context, string, string) error
	ExtendSpawnHostExpiration(context.Context, string, int) error
	GetHosts(context.Context, restmodel.APIHostParams) ([]*restmodel.APIHost, error)
	AttachVolume(context.Context, string, *host.VolumeAttachment) error
	DetachVolume(context.Context, string, string) error
	CreateVolume(context.Context, *host.Volume) (*restmodel.APIVolume, error)
	DeleteVolume(context.Context, string) error
	ModifyVolume(context.Context, string, *restmodel.VolumeModifyOptions) error
	GetVolume(context.Context, string) (*restmodel.APIVolume, error)
	GetVolumesByUser(context.Context) ([]restmodel.APIVolume, error)
	StartHostProcesses(context.Context, []string, string, int) ([]restmodel.APIHostProcess, error)
	GetHostProcessOutput(context.Context, []restmodel.APIHostProcess, int) ([]restmodel.APIHostProcess, error)
	FindHostByIpAddress(context.Context, string) (*restmodel.APIHost, error)

	// Fetch list of distributions evergreen can spawn
	GetDistrosList(context.Context) ([]restmodel.APIDistro, error)

	// Fetch the current authenticated user's public keys
	GetCurrentUsersKeys(context.Context) ([]restmodel.APIPubKey, error)

	AddPublicKey(context.Context, string, string) error

	// Delete a key with specified name from the current authenticated user
	DeletePublicKey(context.Context, string) error

	// List variant/task aliases, with bool parameter to optionally include YAML-defined aliases.
	ListAliases(context.Context, string, bool) ([]model.ProjectAlias, error)
	ListPatchTriggerAliases(context.Context, string) ([]string, error)
	GetDistroByName(context.Context, string) (*restmodel.APIDistro, error)

	// Get parameters for project
	GetParameters(context.Context, string) ([]model.ParameterInfo, error)

	// GetClientConfig fetches the ClientConfig for the evergreen server
	GetClientConfig(context.Context) (*evergreen.ClientConfig, error)

	// GetSubscriptions fetches the subscriptions for the user defined
	// in the local evergreen yaml
	GetSubscriptions(context.Context) ([]event.Subscription, error)

	// Notifications
	SendSlackNotification(ctx context.Context, data *restmodel.APISlack) error
	SendEmailNotification(ctx context.Context, data *restmodel.APIEmail) error

	// GetManifestByTask returns the manifest corresponding to the given task
	GetManifestByTask(ctx context.Context, taskId string) (*manifest.Manifest, error)
	// GetManifestForVersion returns the manifest for a given version ID.
	GetManifestForVersion(ctx context.Context, versionID string) (*restmodel.APIManifest, error)

	// GetRecentVersionsForProject returns the most recent versions for a
	// project.
	GetRecentVersionsForProject(ctx context.Context, projectID, requester string, startAtOrderNum, limit int) ([]restmodel.APIVersion, error)

	// GetBuildsForVersion gets all builds for a version.
	GetBuildsForVersion(ctx context.Context, versionID string) ([]restmodel.APIBuild, error)
	// GetTasksForBuild gets all tasks in a build.
	GetTasksForBuild(ctx context.Context, buildID string, startAt string, limit int) ([]restmodel.APITask, error)

	// GetClientURLs returns the all URLs that can be used to request the
	// Evergreen binary for a given distro.
	GetClientURLs(ctx context.Context, distroID string) ([]string, error)

	// PostHostIsUp indicates to the app server that the task host is up and
	// running.
	PostHostIsUp(ctx context.Context, opts host.HostMetadataOptions) (*restmodel.APIHost, error)
	// GetHostProvisioningOptions gets the options to provision a host.
	GetHostProvisioningOptions(ctx context.Context) (*restmodel.APIHostProvisioningOptions, error)

	// GetRawPatchWithModules fetches the raw patch and module diffs for a given patch ID.
	GetRawPatchWithModules(ctx context.Context, patchId string) (*restmodel.APIRawPatch, error)

	// GetTaskLogs returns task logs for the given task.
	GetTaskLogs(context.Context, GetTaskLogsOptions) (io.ReadCloser, error)
	// GetTaskLogs returns test logs for the given task.
	GetTestLogs(context.Context, GetTestLogsOptions) (io.ReadCloser, error)

	// GetEstimatedGeneratedTasks returns the estimated number of generated tasks to be created by an unfinalized patch.
	GetEstimatedGeneratedTasks(context.Context, string, []model.TVPair) (int, error)

	// RevokeGitHubDynamicAccessToken revokes the given GitHub dynamic access tokens.
	RevokeGitHubDynamicAccessTokens(ctx context.Context, taskID string, tokens []string) error

	// Validate validates a project configuration file.
	Validate(ctx context.Context, data []byte, quiet bool, projectID string) (validator.ValidationErrors, error)

	// SendPanicReport sends a panic report to the evergreen service.
	SendPanicReport(ctx context.Context, details *restmodel.PanicReport) error
}

Communicator is an interface for communicating with the API server.

func NewCommunicator

func NewCommunicator(serverURL string) (Communicator, error)

NewCommunicator returns a Communicator capable of making HTTP REST requests against the API server. To change the default retry behavior, use the SetTimeoutStart, SetTimeoutMax, and SetMaxAttempts methods.

type GetTaskLogsOptions

type GetTaskLogsOptions struct {
	TaskID        string
	Execution     *int
	Type          string
	Start         string
	End           string
	LineLimit     int
	TailLimit     int
	PrintTime     bool
	PrintPriority bool
	Paginate      bool
}

GetTaskLogsOptions are the options for fetching task logs for a given task.

type GetTestLogsOptions

type GetTestLogsOptions struct {
	TaskID        string
	Path          string
	Execution     *int
	LogsToMerge   []string
	Start         string
	End           string
	LineLimit     int
	TailLimit     int
	PrintTime     bool
	PrintPriority bool
	Paginate      bool
}

GetTestLogsOptions are the options for fetching test logs for a given task.

type Mock

type Mock struct {

	// mock behavior
	GetSubscriptionsFail bool
	MockServiceFlags     *model.APIServiceFlags
	MockServiceFlagErr   error

	GetRecentVersionsResult   []restmodel.APIVersion
	GetBuildsForVersionResult []restmodel.APIBuild
	GetTasksForBuildResult    []restmodel.APITask

	SendSlackNotificationData *model.APISlack
	SendEmailNotificationData *model.APIEmail
	// contains filtered or unexported fields
}

Mock mocks EvergreenREST for testing.

func (*Mock) AddPublicKey

func (c *Mock) AddPublicKey(ctx context.Context, keyName, keyValue string) error

func (*Mock) AttachVolume

func (*Mock) AttachVolume(context.Context, string, *host.VolumeAttachment) error

func (*Mock) ChangeSpawnHostPassword

func (*Mock) ChangeSpawnHostPassword(context.Context, string, string) error

func (*Mock) Close

func (c *Mock) Close()

func (*Mock) CreateSpawnHost

func (*Mock) CreateSpawnHost(ctx context.Context, spawnRequest *model.HostRequestOptions) (*model.APIHost, error)

CreateSpawnHost will return a mock host that would have been intended

func (*Mock) CreateVolume

func (*Mock) CreateVolume(context.Context, *host.Volume) (*model.APIVolume, error)

func (*Mock) DeletePublicKey

func (c *Mock) DeletePublicKey(ctx context.Context, keyName string) error

func (*Mock) DeleteServiceUser

func (c *Mock) DeleteServiceUser(context.Context, string) error

func (*Mock) DeleteVolume

func (*Mock) DeleteVolume(context.Context, string) error

func (*Mock) DetachVolume

func (*Mock) DetachVolume(context.Context, string, string) error

func (*Mock) ExtendSpawnHostExpiration

func (*Mock) ExtendSpawnHostExpiration(context.Context, string, int) error

func (*Mock) FindHostByIpAddress

func (*Mock) FindHostByIpAddress(ctx context.Context, ip string) (*model.APIHost, error)

func (*Mock) GetBannerMessage

func (c *Mock) GetBannerMessage(ctx context.Context) (string, error)

func (*Mock) GetBuildsForVersion

func (c *Mock) GetBuildsForVersion(ctx context.Context, versionID string) ([]restmodel.APIBuild, error)

func (*Mock) GetClientConfig

func (c *Mock) GetClientConfig(ctx context.Context) (*evergreen.ClientConfig, error)

func (*Mock) GetClientURLs

func (c *Mock) GetClientURLs(context.Context, string) ([]string, error)

func (*Mock) GetCurrentUsersKeys

func (c *Mock) GetCurrentUsersKeys(ctx context.Context) ([]model.APIPubKey, error)

func (*Mock) GetDistroByName

func (c *Mock) GetDistroByName(context.Context, string) (*model.APIDistro, error)

func (*Mock) GetDistrosList

func (c *Mock) GetDistrosList(ctx context.Context) ([]model.APIDistro, error)

func (*Mock) GetEstimatedGeneratedTasks

func (c *Mock) GetEstimatedGeneratedTasks(ctx context.Context, patchId string, tvPairs []serviceModel.TVPair) (int, error)

func (*Mock) GetEvents

func (c *Mock) GetEvents(ctx context.Context, ts time.Time, limit int) ([]any, error)

func (*Mock) GetHostProcessOutput

func (c *Mock) GetHostProcessOutput(context.Context, []model.APIHostProcess, int) ([]model.APIHostProcess, error)

func (*Mock) GetHostProvisioningOptions

func (c *Mock) GetHostProvisioningOptions(ctx context.Context) (*restmodel.APIHostProvisioningOptions, error)

func (*Mock) GetHosts

func (c *Mock) GetHosts(ctx context.Context, data model.APIHostParams) ([]*model.APIHost, error)

GetHosts will return an array with a single mock host

func (*Mock) GetManifestByTask

func (c *Mock) GetManifestByTask(context.Context, string) (*manifest.Manifest, error)

func (*Mock) GetManifestForVersion

func (c *Mock) GetManifestForVersion(context.Context, string) (*model.APIManifest, error)

func (*Mock) GetMatchingHosts

func (c *Mock) GetMatchingHosts(context.Context, time.Time, time.Time, string, bool) ([]string, error)

func (*Mock) GetParameters

func (c *Mock) GetParameters(context.Context, string) ([]serviceModel.ParameterInfo, error)

func (*Mock) GetRawPatchWithModules

func (c *Mock) GetRawPatchWithModules(context.Context, string) (*restmodel.APIRawPatch, error)

func (*Mock) GetRecentVersionsForProject

func (c *Mock) GetRecentVersionsForProject(ctx context.Context, project, branch string, startAtOrderNum, limit int) ([]restmodel.APIVersion, error)

func (*Mock) GetServiceFlags

func (c *Mock) GetServiceFlags(ctx context.Context) (*model.APIServiceFlags, error)

func (*Mock) GetServiceUsers

func (c *Mock) GetServiceUsers(context.Context) ([]model.APIDBUser, error)

func (*Mock) GetSettings

func (c *Mock) GetSettings(ctx context.Context) (*evergreen.Settings, error)

func (*Mock) GetSpawnHost

func (*Mock) GetSpawnHost(ctx context.Context, hostID string) (*model.APIHost, error)

func (*Mock) GetSubscriptions

func (c *Mock) GetSubscriptions(_ context.Context) ([]event.Subscription, error)

func (*Mock) GetTaskLogs

func (c *Mock) GetTaskLogs(ctx context.Context, opts GetTaskLogsOptions) (io.ReadCloser, error)

func (*Mock) GetTasksForBuild

func (c *Mock) GetTasksForBuild(ctx context.Context, buildID string, startAt string, limit int) ([]restmodel.APITask, error)

func (*Mock) GetTestLogs

func (c *Mock) GetTestLogs(ctx context.Context, opts GetTestLogsOptions) (io.ReadCloser, error)

func (*Mock) GetUiV2URL

func (c *Mock) GetUiV2URL(ctx context.Context) (string, error)

func (*Mock) GetVolume

func (c *Mock) GetVolume(context.Context, string) (*model.APIVolume, error)

func (*Mock) GetVolumesByUser

func (*Mock) GetVolumesByUser(context.Context) ([]model.APIVolume, error)

func (*Mock) IsServiceUser

func (c *Mock) IsServiceUser(context.Context, string) (bool, error)

func (*Mock) ListAliases

func (c *Mock) ListAliases(ctx context.Context, project string, includeProjectConfig bool) ([]serviceModel.ProjectAlias, error)

func (*Mock) ListPatchTriggerAliases

func (c *Mock) ListPatchTriggerAliases(ctx context.Context, project string) ([]string, error)

func (*Mock) ModifySpawnHost

func (*Mock) ModifySpawnHost(ctx context.Context, hostID string, changes host.HostModifyOptions) error

func (*Mock) ModifyVolume

func (*Mock) PostHostIsUp

func (c *Mock) PostHostIsUp(ctx context.Context, options host.HostMetadataOptions) (*restmodel.APIHost, error)

func (*Mock) RestartRecentTasks

func (c *Mock) RestartRecentTasks(ctx context.Context, starAt, endAt time.Time) error

func (*Mock) RevertSettings

func (c *Mock) RevertSettings(ctx context.Context, guid string) error

func (*Mock) RevokeGitHubDynamicAccessTokens

func (c *Mock) RevokeGitHubDynamicAccessTokens(ctx context.Context, taskId string, tokens []string) error

func (*Mock) SendEmailNotification

func (c *Mock) SendEmailNotification(_ context.Context, data *model.APIEmail) error

func (*Mock) SendPanicReport

func (c *Mock) SendPanicReport(ctx context.Context, details *model.PanicReport) error

func (*Mock) SendSlackNotification

func (c *Mock) SendSlackNotification(_ context.Context, data *model.APISlack) error

func (*Mock) SetAPIKey

func (c *Mock) SetAPIKey(apiKey string)

func (*Mock) SetAPIServerHost

func (c *Mock) SetAPIServerHost(serverURL string)

func (*Mock) SetAPIUser

func (c *Mock) SetAPIUser(apiUser string)

func (*Mock) SetBannerMessage

func (c *Mock) SetBannerMessage(ctx context.Context, m string, t evergreen.BannerTheme) error

func (*Mock) SetHostID

func (c *Mock) SetHostID(hostID string)

func (*Mock) SetHostSecret

func (c *Mock) SetHostSecret(hostSecret string)

func (*Mock) SetMaxAttempts

func (c *Mock) SetMaxAttempts(attempts int)

func (*Mock) SetOAuth

func (c *Mock) SetOAuth(oauth string)

func (*Mock) SetServiceFlags

func (c *Mock) SetServiceFlags(ctx context.Context, f *model.APIServiceFlags) error

func (*Mock) SetTimeoutMax

func (c *Mock) SetTimeoutMax(timeoutMax time.Duration)

func (*Mock) SetTimeoutStart

func (c *Mock) SetTimeoutStart(timeoutStart time.Duration)

func (*Mock) StartHostProcesses

func (c *Mock) StartHostProcesses(context.Context, []string, string, int) ([]model.APIHostProcess, error)

func (*Mock) StartSpawnHost

func (*Mock) StartSpawnHost(context.Context, string, string, bool) error

func (*Mock) StopSpawnHost

func (*Mock) StopSpawnHost(ctx context.Context, hostID string, subscriptionType string, shouldKeepOff, wait bool) error

func (*Mock) TerminateSpawnHost

func (*Mock) TerminateSpawnHost(ctx context.Context, hostID string) error

func (*Mock) UpdateServiceUser

func (c *Mock) UpdateServiceUser(context.Context, string, string, []string) error

func (*Mock) UpdateSettings

func (c *Mock) UpdateSettings(ctx context.Context, update *model.APIAdminSettings) (*model.APIAdminSettings, error)

func (*Mock) Validate

func (c *Mock) Validate(ctx context.Context, data []byte, quiet bool, projectID string) (validator.ValidationErrors, error)

Jump to

Keyboard shortcuts

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