client

package
v0.0.0-...-956c19b Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: Apache-2.0 Imports: 19 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 = "Possibly user credentials are expired, try logging in again via the Evergreen web UI."

AuthError is a special error when the CLI receives 401 Unauthorized to suggest logging in again as a possible solution to the error.

Functions

This section is empty.

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 Configuration methods
	//
	SetAPIUser(string)
	SetAPIKey(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)
	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) ([]interface{}, 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) 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
	ListAliases(context.Context, string) ([]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)

	// CreateVersionFromConfig takes an evergreen config and makes runnable tasks from it
	CreateVersionFromConfig(context.Context, string, string, bool, []byte) (*model.Version, error)

	// Commit Queue
	GetCommitQueue(ctx context.Context, projectID string) (*restmodel.APICommitQueue, error)
	DeleteCommitQueueItem(ctx context.Context, item string) error
	// if enqueueNext is true then allow item to be processed next
	EnqueueItem(ctx context.Context, patchID string, enqueueNext bool) (int, error)
	CreatePatchForMerge(ctx context.Context, patchID, commitMessage string) (*restmodel.APIPatch, error)
	GetMessageForPatch(ctx context.Context, patchID string) (string, error)

	// Notifications
	SendNotification(ctx context.Context, notificationType string, data interface{}) error

	// GetManifestByTask returns the manifest corresponding to the given task
	GetManifestByTask(ctx context.Context, taskId string) (*manifest.Manifest, error)

	GetRecentVersionsForProject(ctx context.Context, projectID, requester string) ([]restmodel.APIVersion, error)

	// GetTaskSyncReadCredentials returns the credentials to fetch task
	// directory from S3.
	GetTaskSyncReadCredentials(ctx context.Context) (*evergreen.S3Credentials, error)
	// GetTaskSyncPath returns the path to the task directory in S3.
	GetTaskSyncPath(ctx context.Context, taskID string) (string, 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, hostID, hostSecret, instanceID string) (*restmodel.APIHost, error)
	// GetHostProvisioningOptions gets the options to provision a host.
	GetHostProvisioningOptions(ctx context.Context, hostID, hostSecret string) (*restmodel.APIHostProvisioningOptions, error)

	// CompareTasks returns the order that the given tasks would be scheduled, along with the scheduling logic.
	CompareTasks(context.Context, []string, bool) ([]string, map[string]map[string]string, error)

	// GetRawPatchWithModules fetches the raw patch and module diffs for a given patch ID.
	GetRawPatchWithModules(ctx context.Context, patchId string) (*restmodel.APIRawPatch, 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 Mock

type Mock struct {

	// mock behavior
	GetSubscriptionsFail bool
	// 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) CreatePatchForMerge

func (c *Mock) CreatePatchForMerge(ctx context.Context, patchID, commitMessage string) (*model.APIPatch, error)

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) CreateVersionFromConfig

func (c *Mock) CreateVersionFromConfig(ctx context.Context, project, message string, active bool, config []byte) (*serviceModel.Version, error)

func (*Mock) CreateVolume

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

func (*Mock) DeleteCommitQueueItem

func (c *Mock) DeleteCommitQueueItem(ctx context.Context, item string) 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) EnqueueItem

func (c *Mock) EnqueueItem(ctx context.Context, patchID string, force bool) (int, error)

func (*Mock) ExtendSpawnHostExpiration

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

func (*Mock) FindHostByIpAddress

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

func (*Mock) GetBannerMessage

func (c *Mock) GetBannerMessage(ctx context.Context) (string, 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) GetCommitQueue

func (c *Mock) GetCommitQueue(ctx context.Context, projectID string) (*model.APICommitQueue, 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) GetEvents

func (c *Mock) GetEvents(ctx context.Context, ts time.Time, limit int) ([]interface{}, 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, hostID, hostSecret string) (*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) GetMatchingHosts

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

func (*Mock) GetMessageForPatch

func (c *Mock) GetMessageForPatch(context.Context, string) (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(context.Context, string, string) ([]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) GetTaskSyncPath

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

func (*Mock) GetTaskSyncReadCredentials

func (c *Mock) GetTaskSyncReadCredentials(context.Context) (*evergreen.S3Credentials, 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) ListAliases

func (c *Mock) ListAliases(ctx context.Context, keyName string) ([]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, hostID, hostSecret, instanceID string) (*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) SendNotification

func (c *Mock) SendNotification(_ context.Context, _ string, _ interface{}) error

func (*Mock) SetAPIKey

func (c *Mock) SetAPIKey(apiKey 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) SetMaxAttempts

func (c *Mock) SetMaxAttempts(attempts int)

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(context.Context, string, string, 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)

Jump to

Keyboard shortcuts

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