-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add use/management of TF_APPEND_USER_AGENT to tfexec and tfinstall
Fixes #9
- Loading branch information
Showing
9 changed files
with
132 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package version | ||
|
||
const version = "0.7.0" | ||
|
||
// ModuleVersion returns the current version of the github.com/hashicorp/terraform-exec Go module. | ||
// This is a function to allow for future possible enhancement using debug.BuildInfo. | ||
func ModuleVersion() string { | ||
return version | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package tfinstall | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"strings" | ||
|
||
cleanhttp "github.com/hashicorp/go-cleanhttp" | ||
|
||
intversion "github.com/hashicorp/terraform-exec/internal/version" | ||
) | ||
|
||
type userAgentRoundTripper struct { | ||
inner http.RoundTripper | ||
userAgent string | ||
} | ||
|
||
func (rt *userAgentRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { | ||
if _, ok := req.Header["User-Agent"]; !ok { | ||
req.Header.Set("User-Agent", rt.userAgent) | ||
} | ||
return rt.inner.RoundTrip(req) | ||
} | ||
|
||
func newHTTPClient() *http.Client { | ||
appendUA := os.Getenv("TF_APPEND_USER_AGENT") | ||
userAgent := strings.TrimSpace(fmt.Sprintf("HashiCorp-tfinstall/%s %s", intversion.ModuleVersion(), appendUA)) | ||
|
||
cli := cleanhttp.DefaultPooledClient() | ||
cli.Transport = &userAgentRoundTripper{ | ||
userAgent: userAgent, | ||
inner: cli.Transport, | ||
} | ||
|
||
return cli | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.