Skip to content

Commit

Permalink
DEVPROD-13240 staging environment header for the CLI (#8534)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybrill authored Dec 11, 2024
1 parent b50bffe commit 00533ed
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
1 change: 1 addition & 0 deletions globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ const (
ContentLengthHeader = "Content-Length"
APIUserHeader = "Api-User"
APIKeyHeader = "Api-Key"
EnvironmentHeader = "X-Evergreen-Environment"
)

const (
Expand Down
17 changes: 11 additions & 6 deletions operations/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
25 changes: 15 additions & 10 deletions operations/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 00533ed

Please sign in to comment.