From 00533edb2ed5e46e96559d1a65e0df5df1509a8a Mon Sep 17 00:00:00 2001 From: Jonathan Brill Date: Wed, 11 Dec 2024 17:53:18 -0500 Subject: [PATCH] DEVPROD-13240 staging environment header for the CLI (#8534) --- config.go | 2 +- globals.go | 1 + operations/http.go | 17 +++++++++++------ operations/model.go | 25 +++++++++++++++---------- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/config.go b/config.go index d51f2462a4f..61a835511b9 100644 --- a/config.go +++ b/config.go @@ -33,7 +33,7 @@ var ( // ClientVersion is the commandline version string used to control updating // the CLI. The format is the calendar date (YYYY-MM-DD). - ClientVersion = "2024-12-05" + ClientVersion = "2024-12-06" // Agent version to control agent rollover. The format is the calendar date // (YYYY-MM-DD). diff --git a/globals.go b/globals.go index bdd19350238..a8121150a66 100644 --- a/globals.go +++ b/globals.go @@ -559,6 +559,7 @@ const ( ContentLengthHeader = "Content-Length" APIUserHeader = "Api-User" APIKeyHeader = "Api-Key" + EnvironmentHeader = "X-Evergreen-Environment" ) const ( diff --git a/operations/http.go b/operations/http.go index 318296da7c4..ba311e6317d 100644 --- a/operations/http.go +++ b/operations/http.go @@ -27,12 +27,13 @@ import ( // legacyClient manages requests to the API server endpoints, and unmarshaling the results into // usable structures. type legacyClient struct { - APIRoot string - httpClient http.Client - User string - APIKey string - APIRootV2 string - UIRoot string + APIRoot string + httpClient http.Client + User string + APIKey string + APIRootV2 string + UIRoot string + stagingEnvironment string } // APIError is an implementation of error for reporting unexpected results from API calls. @@ -82,6 +83,10 @@ func (ac *legacyClient) doReq(method, path string, apiVersion int, body io.Reade req.Header.Add(evergreen.APIKeyHeader, ac.APIKey) req.Header.Add(evergreen.APIUserHeader, ac.User) + if ac.stagingEnvironment != "" { + req.Header.Add(evergreen.EnvironmentHeader, ac.stagingEnvironment) + } + resp, err := ac.httpClient.Do(req) if err != nil { return nil, err diff --git a/operations/model.go b/operations/model.go index 3e1101348e8..a6f223b5651 100644 --- a/operations/model.go +++ b/operations/model.go @@ -91,6 +91,9 @@ type ClientSettings struct { LoadedFrom string `json:"-" yaml:"-"` DisableAutoDefaulting bool `json:"disable_auto_defaulting" yaml:"disable_auto_defaulting"` ProjectsForDirectory map[string]string `json:"projects_for_directory,omitempty" yaml:"projects_for_directory,omitempty"` + + // StagingEnvironment configures which staging environment to point to. + StagingEnvironment string `json:"staging_environment,omitempty" yaml:"staging_environment,omitempty"` } func NewClientSettings(fn string) (*ClientSettings, error) { @@ -194,19 +197,21 @@ func (s *ClientSettings) getLegacyClients() (*legacyClient, *legacyClient, error } ac := &legacyClient{ - APIRoot: s.APIServerHost, - APIRootV2: s.APIServerHost + "/rest/v2", - User: s.User, - APIKey: s.APIKey, - UIRoot: s.UIServerHost, + APIRoot: s.APIServerHost, + APIRootV2: s.APIServerHost + "/rest/v2", + User: s.User, + APIKey: s.APIKey, + UIRoot: s.UIServerHost, + stagingEnvironment: s.StagingEnvironment, } rc := &legacyClient{ - APIRoot: apiURL.Scheme + "://" + apiURL.Host + "/rest/v1", - APIRootV2: apiURL.Scheme + "://" + apiURL.Host + "/rest/v2", - User: s.User, - APIKey: s.APIKey, - UIRoot: s.UIServerHost, + APIRoot: apiURL.Scheme + "://" + apiURL.Host + "/rest/v1", + APIRootV2: apiURL.Scheme + "://" + apiURL.Host + "/rest/v2", + User: s.User, + APIKey: s.APIKey, + UIRoot: s.UIServerHost, + stagingEnvironment: s.StagingEnvironment, } return ac, rc, nil