Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVPROD-13240 staging environment header for the CLI #8534

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -557,6 +557,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
environment string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a plan to use this for non-staging environments? If not we can rename to something like stagingEnvironment for clarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to stagingEnvironment

}

// 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.environment != "" {
req.Header.Add(evergreen.EnvironmentHeader, ac.environment)
}

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,
environment: 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,
environment: s.StagingEnvironment,
}

return ac, rc, nil
Expand Down
Loading