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

Add X-TFE-Version header #563

Merged
merged 3 commits into from Oct 26, 2022
Merged

Add X-TFE-Version header #563

merged 3 commits into from Oct 26, 2022

Conversation

sebasslash
Copy link
Contributor

Description

Since TFE Version 202208-3, we've included the TFE version string as a header for each response. This PR adds support for the client to retrieve that header during the initial metadata request and cache it locally. That version string can be fetched using the new Client method: RemoteTFEVersion()

Testing plan

You can run the integration test:

go test -run TestClient_newClient -v ./... -tags=integration

Optionally, you can test against an actual TFE instance if you have one at your disposal:

func main() {
  ctx := context.Background()
  cfg := &tfe.Config{
    Address: "https://your-tfe-address",
    Token: "your-token",
    RetryServerErrors: true,
  }
  
  client, err := tfe.NewClient(cfg)
  if err != nil {
    // sound the alarm!
  }
  
  if version := client.RemoteTFEVersion(); version == "" {
    panic("sound the alarm again!")
  }
}

@sebasslash sebasslash requested a review from a team as a code owner October 25, 2022 20:24
CHANGELOG.md Outdated
@@ -3,6 +3,7 @@
## Enhancements

* Add `NotificationTriggerAssessmentCheckFailed` notification trigger type by @rexredinger [#549](https://github.com/hashicorp/go-tfe/pull/549)
* Add `RemoteTFEVersion()` to the `Client` interface, which exposes the `X-TFE-Version` header set by a remote TFE instance by @sebasslash []
Copy link
Collaborator

@uturunku1 uturunku1 Oct 25, 2022

Choose a reason for hiding this comment

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

Suggested change
* Add `RemoteTFEVersion()` to the `Client` interface, which exposes the `X-TFE-Version` header set by a remote TFE instance by @sebasslash []
* Add `RemoteTFEVersion()` to the `Client` interface, which exposes the `X-TFE-Version` header set by a remote TFE instance by @sebasslash [#563](https://github.com/hashicorp/go-tfe/pull/563)

@@ -27,6 +27,7 @@ func TestClient_newClient(t *testing.T) {
w.Header().Set("Content-Type", "application/vnd.api+json")
w.Header().Set("X-RateLimit-Limit", "30")
w.Header().Set("TFP-API-Version", "34.21.9")
w.Header().Set("X-TFE-Version", "202205-1")
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about testing for the case where we have TFC?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue with this is that I'd have restructure most of the test simply to test that a field is an empty string (the test isn't really operating under a TFC vs TFE context).

One nice guarantee we have is that the function that's used to fetch the header http.Response.Header.Get() returns a string and the docs mention that if a key does not exist the function will return an empty string. So by testing that we can fetch the value of that header we are also inadvertently testing that it can potentially be empty as well since we know that header can be omitted.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK - that makes sense - thank you for that explanation.

@uturunku1
Copy link
Collaborator

@annawinkler and I got together today, and we partially tested your PR. We were able to verify the proper behavior for TFC (an empty string returned by the method) by using your code sample. However, we were not able to test the behavior for a TFE instance because we do have access to one. We requested one in the # proj-tfe-releases channel, but the request is pending.

@sebasslash
Copy link
Contributor Author

Oh! Well you can configure your local dev instance as TFE by setting ONPREM_ENABLED=1 when running stack up.

Copy link
Contributor

@annawinkler annawinkler left a comment

Choose a reason for hiding this comment

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

✅ Tested with latest tfe test instance and test script and got v202211-1

:shipit:

@sebasslash sebasslash merged commit 3a5f9ff into main Oct 26, 2022
@sebasslash sebasslash deleted the add-tfe-version-header branch October 26, 2022 19:25
@github-actions
Copy link

Reminder to the contributor that merged this PR: if your changes have added important functionality or fixed a relevant bug, open a follow-up PR to update CHANGELOG.md with a note on your changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants