mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 02:57:59 +00:00
Use cleanhttp instead of bare http.Client
This commit is contained in:
@@ -9,6 +9,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-cleanhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -38,10 +40,10 @@ type Config struct {
|
|||||||
func DefaultConfig() *Config {
|
func DefaultConfig() *Config {
|
||||||
config := &Config{
|
config := &Config{
|
||||||
Address: "https://127.0.0.1:8200",
|
Address: "https://127.0.0.1:8200",
|
||||||
HttpClient: &http.Client{
|
|
||||||
Timeout: time.Second * 60,
|
HttpClient: cleanhttp.DefaultClient(),
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
config.HttpClient.Timeout = time.Second * 60
|
||||||
|
|
||||||
if addr := os.Getenv("VAULT_ADDR"); addr != "" {
|
if addr := os.Getenv("VAULT_ADDR"); addr != "" {
|
||||||
config.Address = addr
|
config.Address = addr
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package github
|
package github
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/google/go-github/github"
|
"github.com/google/go-github/github"
|
||||||
|
"github.com/hashicorp/go-cleanhttp"
|
||||||
"github.com/hashicorp/vault/logical"
|
"github.com/hashicorp/vault/logical"
|
||||||
"github.com/hashicorp/vault/logical/framework"
|
"github.com/hashicorp/vault/logical/framework"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
@@ -54,7 +53,7 @@ type backend struct {
|
|||||||
// Client returns the GitHub client to communicate to GitHub via the
|
// Client returns the GitHub client to communicate to GitHub via the
|
||||||
// configured settings.
|
// configured settings.
|
||||||
func (b *backend) Client(token string) (*github.Client, error) {
|
func (b *backend) Client(token string) (*github.Client, error) {
|
||||||
tc := &http.Client{}
|
tc := cleanhttp.DefaultClient()
|
||||||
if token != "" {
|
if token != "" {
|
||||||
tc = oauth2.NewClient(oauth2.NoContext, &tokenSource{Value: token})
|
tc = oauth2.NewClient(oauth2.NoContext, &tokenSource{Value: token})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -13,6 +12,7 @@ import (
|
|||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||||
"github.com/aws/aws-sdk-go/service/ec2"
|
"github.com/aws/aws-sdk-go/service/ec2"
|
||||||
|
"github.com/hashicorp/go-cleanhttp"
|
||||||
"github.com/hashicorp/vault/logical"
|
"github.com/hashicorp/vault/logical"
|
||||||
logicaltest "github.com/hashicorp/vault/logical/testing"
|
logicaltest "github.com/hashicorp/vault/logical/testing"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
@@ -98,7 +98,7 @@ func testAccStepReadUser(t *testing.T, name string) logicaltest.TestStep {
|
|||||||
awsConfig := &aws.Config{
|
awsConfig := &aws.Config{
|
||||||
Credentials: creds,
|
Credentials: creds,
|
||||||
Region: aws.String("us-east-1"),
|
Region: aws.String("us-east-1"),
|
||||||
HTTPClient: &http.Client{},
|
HTTPClient: cleanhttp.DefaultClient(),
|
||||||
}
|
}
|
||||||
client := ec2.New(awsConfig)
|
client := ec2.New(awsConfig)
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package aws
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||||
"github.com/aws/aws-sdk-go/service/iam"
|
"github.com/aws/aws-sdk-go/service/iam"
|
||||||
|
"github.com/hashicorp/go-cleanhttp"
|
||||||
"github.com/hashicorp/vault/logical"
|
"github.com/hashicorp/vault/logical"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ func clientIAM(s logical.Storage) (*iam.IAM, error) {
|
|||||||
awsConfig := &aws.Config{
|
awsConfig := &aws.Config{
|
||||||
Credentials: creds,
|
Credentials: creds,
|
||||||
Region: aws.String(config.Region),
|
Region: aws.String(config.Region),
|
||||||
HTTPClient: &http.Client{},
|
HTTPClient: cleanhttp.DefaultClient(),
|
||||||
}
|
}
|
||||||
return iam.New(awsConfig), nil
|
return iam.New(awsConfig), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-cleanhttp"
|
||||||
"github.com/hashicorp/vault/logical"
|
"github.com/hashicorp/vault/logical"
|
||||||
"github.com/hashicorp/vault/vault"
|
"github.com/hashicorp/vault/vault"
|
||||||
)
|
)
|
||||||
@@ -23,7 +24,7 @@ func TestSysMounts_headerAuth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
req.Header.Set(AuthHeaderName, token)
|
req.Header.Set(AuthHeaderName, token)
|
||||||
|
|
||||||
client := &http.Client{}
|
client := cleanhttp.DefaultClient()
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-cleanhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testHttpGet(t *testing.T, token string, addr string) *http.Response {
|
func testHttpGet(t *testing.T, token string, addr string) *http.Response {
|
||||||
@@ -47,9 +49,8 @@ func testHttpData(t *testing.T, method string, token string, addr string, body i
|
|||||||
req.Header.Set("X-Vault-Token", token)
|
req.Header.Set("X-Vault-Token", token)
|
||||||
}
|
}
|
||||||
|
|
||||||
client := &http.Client{
|
client := cleanhttp.DefaultClient()
|
||||||
Timeout: 60 * time.Second,
|
client.Timeout = 60 * time.Second
|
||||||
}
|
|
||||||
|
|
||||||
// From https://github.com/michiwend/gomusicbrainz/pull/4/files
|
// From https://github.com/michiwend/gomusicbrainz/pull/4/files
|
||||||
defaultRedirectLimit := 30
|
defaultRedirectLimit := 30
|
||||||
|
|||||||
Reference in New Issue
Block a user