Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased

* Remove org settings validation in RegistryModulesCreateMonorepo tests, by @jillirami ([#1236](https://github.com/hashicorp/go-tfe/pull/1236))
* Add `RemoteTFENumericVersion()` to the `Client` interface, which exposes the `X-TFE-Current-Version` header set by a remote TFE instance by @skj-skj [#1246](https://github.com/hashicorp/go-tfe/pull/1246)

# v1.95.0

Expand Down
62 changes: 42 additions & 20 deletions tfe.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ import (
)

const (
_userAgent = "go-tfe"
_headerRateLimit = "X-RateLimit-Limit"
_headerRateReset = "X-RateLimit-Reset"
_headerAppName = "TFP-AppName"
_headerAPIVersion = "TFP-API-Version"
_headerTFEVersion = "X-TFE-Version"
_includeQueryParam = "include"
_userAgent = "go-tfe"
_headerRateLimit = "X-RateLimit-Limit"
_headerRateReset = "X-RateLimit-Reset"
_headerAppName = "TFP-AppName"
_headerAPIVersion = "TFP-API-Version"
_headerTFEVersion = "X-TFE-Version"
_headerTFENumericVersion = "X-TFE-Current-Version"
_includeQueryParam = "include"

DefaultAddress = "https://app.terraform.io"
DefaultBasePath = "/api/v2/"
Expand Down Expand Up @@ -111,17 +112,18 @@ func DefaultConfig() *Config {
// Client is the Terraform Enterprise API client. It provides the basic
// connectivity and configuration for accessing the TFE API
type Client struct {
baseURL *url.URL
registryBaseURL *url.URL
token string
headers http.Header
http *retryablehttp.Client
limiter *rate.Limiter
retryLogHook RetryLogHook
retryServerErrors bool
remoteAPIVersion string
remoteTFEVersion string
appName string
baseURL *url.URL
registryBaseURL *url.URL
token string
headers http.Header
http *retryablehttp.Client
limiter *rate.Limiter
retryLogHook RetryLogHook
retryServerErrors bool
remoteAPIVersion string
remoteTFEVersion string
remoteTFENumericVersion string
appName string

Admin Admin
Agents Agents
Expand Down Expand Up @@ -449,6 +451,9 @@ func NewClient(cfg *Config) (*Client, error) {
// Save the TFE version
client.remoteTFEVersion = meta.TFEVersion

// Save the TFE Numeric version
client.remoteTFENumericVersion = meta.TFENumericVersion

// Save the app name
client.appName = meta.AppName

Expand Down Expand Up @@ -613,7 +618,7 @@ func (c *Client) SetFakeRemoteAPIVersion(fakeAPIVersion string) {
c.remoteAPIVersion = fakeAPIVersion
}

// RemoteTFEVersion returns the server's declared TFE version string.
// RemoteTFEVersion returns the server's declared TFE monthly version string.
//
// A Terraform Enterprise API server includes its current version in an
// HTTP header field in all responses. This value is saved by the client
Expand All @@ -624,6 +629,17 @@ func (c Client) RemoteTFEVersion() string {
return c.remoteTFEVersion
}

// RemoteTFENumericVersion returns the server's declared TFE version string.
//
// A Terraform Enterprise API server includes its current numeric version in an
// HTTP header field in all responses. This value is saved by the client
// during the initial setup request and RemoteTFENumericVersion returns that cached
// value. This function returns an empty string for any Terraform Enterprise version
// earlier than 1.0.3 and for HCP Terraform.
func (c Client) RemoteTFENumericVersion() string {
return c.remoteTFENumericVersion
}

// RetryServerErrors configures the retry HTTP check to also retry
// unexpected errors or requests that failed with a server error.
func (c *Client) RetryServerErrors(retry bool) {
Expand Down Expand Up @@ -699,11 +715,16 @@ type rawAPIMetadata struct {
// field was not included in the response.
APIVersion string

// TFEVersion is the raw TFE version string reported by the server in the
// TFEVersion is the raw TFE monthly version string reported by the server in the
// X-TFE-Version response header, or an empty string if that header
// field was not included in the response.
TFEVersion string

// TFENumericVersion is the raw TFE Numeric version string reported by the server in the
// X-TFE-Current-Version response header, or an empty string if that header
// field was not included in the response.
TFENumericVersion string

// RateLimit is the raw API version string reported by the server in the
// X-RateLimit-Limit response header, or an empty string if that header
// field was not included in the response.
Expand Down Expand Up @@ -743,6 +764,7 @@ func (c *Client) getRawAPIMetadata() (rawAPIMetadata, error) {
meta.APIVersion = resp.Header.Get(_headerAPIVersion)
meta.RateLimit = resp.Header.Get(_headerRateLimit)
meta.TFEVersion = resp.Header.Get(_headerTFEVersion)
meta.TFENumericVersion = resp.Header.Get(_headerTFENumericVersion)
meta.AppName = resp.Header.Get(_headerAppName)

return meta, nil
Expand Down
6 changes: 5 additions & 1 deletion tfe_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestClient_newClient(t *testing.T) {
w.Header().Set("X-RateLimit-Limit", "30")
w.Header().Set("TFP-API-Version", "34.21.9")
w.Header().Set("X-TFE-Version", "202205-1")
w.Header().Set("X-TFE-Current-Version", "1.1.0")
if enterpriseEnabled() {
w.Header().Set("TFP-AppName", "Terraform Enterprise")
} else {
Expand Down Expand Up @@ -87,7 +88,10 @@ func TestClient_newClient(t *testing.T) {
t.Errorf("unexpected remote API version %q; want %q", client.RemoteAPIVersion(), want)
}
if want := "202205-1"; client.RemoteTFEVersion() != want {
t.Errorf("unexpected remote TFE version %q; want %q", client.RemoteTFEVersion(), want)
t.Errorf("unexpected remote TFE monthly version %q; want %q", client.RemoteTFEVersion(), want)
}
if want := "1.1.0"; client.RemoteTFENumericVersion() != want {
t.Errorf("unexpected remote TFE numeric version %q; want %q", client.RemoteTFENumericVersion(), want)
}

if enterpriseEnabled() {
Expand Down
Loading