-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from hashicorp/remove-version
Remove occurrences of exported Terraform version
- Loading branch information
Showing
12 changed files
with
96 additions
and
116 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,53 @@ | ||
package httpclient | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
"strings" | ||
|
||
cleanhttp "github.com/hashicorp/go-cleanhttp" | ||
"github.com/hashicorp/terraform-plugin-sdk/internal/version" | ||
) | ||
|
||
const uaEnvVar = "TF_APPEND_USER_AGENT" | ||
const userAgentFormat = "Terraform/%s" | ||
|
||
// New returns the DefaultPooledClient from the cleanhttp | ||
// package that will also send a Terraform User-Agent string. | ||
func New() *http.Client { | ||
cli := cleanhttp.DefaultPooledClient() | ||
cli.Transport = &userAgentRoundTripper{ | ||
userAgent: UserAgentString(), | ||
inner: cli.Transport, | ||
} | ||
return cli | ||
} | ||
|
||
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) | ||
} | ||
log.Printf("[TRACE] HTTP client %s request to %s", req.Method, req.URL.String()) | ||
return rt.inner.RoundTrip(req) | ||
} | ||
|
||
func UserAgentString() string { | ||
ua := fmt.Sprintf(userAgentFormat, version.Version) | ||
|
||
if add := os.Getenv(uaEnvVar); add != "" { | ||
add = strings.TrimSpace(add) | ||
if len(add) > 0 { | ||
ua += " " + add | ||
log.Printf("[DEBUG] Using modified User-Agent: %s", ua) | ||
} | ||
} | ||
|
||
return ua | ||
} |
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
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.
This file was deleted.
Oops, something went wrong.