style(httpbackoff -> pkg): Adjusts package name to follow convention
This commit is contained in:
parent
2cedebb4eb
commit
8ca3c2ed1f
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
*.swp
|
||||
bin/
|
||||
coverage/
|
||||
pkg/
|
||||
gopath/
|
||||
|
7
build
7
build
@ -3,7 +3,12 @@
|
||||
ORG_PATH="github.com/coreos"
|
||||
REPO_PATH="${ORG_PATH}/coreos-cloudinit"
|
||||
|
||||
if [ ! -h gopath/src/${REPO_PATH} ]; then
|
||||
mkdir -p gopath/src/${ORG_PATH}
|
||||
ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255
|
||||
fi
|
||||
|
||||
export GOBIN=${PWD}/bin
|
||||
export GOPATH=${PWD}
|
||||
export GOPATH=${PWD}/gopath
|
||||
|
||||
go build -o bin/coreos-cloudinit ${REPO_PATH}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package datasource
|
||||
|
||||
import "github.com/coreos/coreos-cloudinit/httpbackoff"
|
||||
import "github.com/coreos/coreos-cloudinit/pkg"
|
||||
|
||||
type metadataService struct {
|
||||
url string
|
||||
@ -11,7 +11,7 @@ func NewMetadataService(url string) *metadataService {
|
||||
}
|
||||
|
||||
func (ms *metadataService) Fetch() ([]byte, error) {
|
||||
client := httpbackoff.NewHttpClient()
|
||||
client := pkg.NewHttpClient()
|
||||
return client.Get(ms.url)
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/coreos-cloudinit/httpbackoff"
|
||||
"github.com/coreos/coreos-cloudinit/pkg"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -31,7 +31,7 @@ func (self *procCmdline) Fetch() ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := httpbackoff.NewHttpClient()
|
||||
client := pkg.NewHttpClient()
|
||||
cfg, err := client.Get(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/coreos/coreos-cloudinit/httpbackoff"
|
||||
"github.com/coreos/coreos-cloudinit/pkg"
|
||||
"github.com/coreos/coreos-cloudinit/system"
|
||||
)
|
||||
|
||||
@ -24,7 +24,7 @@ func SSHImportKeysFromURL(system_user string, url string) error {
|
||||
}
|
||||
|
||||
func fetchUserKeys(url string) ([]string, error) {
|
||||
client := httpbackoff.NewHttpClient()
|
||||
client := pkg.NewHttpClient()
|
||||
data, err := client.Get(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -1,4 +1,4 @@
|
||||
package httpbackoff
|
||||
package pkg
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
@ -23,14 +23,14 @@ type HttpClient struct {
|
||||
// Maximum exp backoff duration. Defaults to 5 seconds
|
||||
MaxBackoff time.Duration
|
||||
|
||||
// Maximum amount of connection retries. Defaults to 15
|
||||
// Maximum number of connection retries. Defaults to 15
|
||||
MaxRetries int
|
||||
|
||||
// HTTP client timeout, this is suggested to be low since exponential
|
||||
// backoff will kick off too. Defaults to 2 seconds
|
||||
Timeout time.Duration
|
||||
|
||||
//Whether or not to skip TLS verification. Defaults to false
|
||||
// Whether or not to skip TLS verification. Defaults to false
|
||||
SkipTLS bool
|
||||
}
|
||||
|
||||
@ -45,10 +45,6 @@ func NewHttpClient() *HttpClient {
|
||||
|
||||
// Fetches a given URL with support for exponential backoff and maximum retries
|
||||
func (h *HttpClient) Get(rawurl string) ([]byte, error) {
|
||||
if h == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if rawurl == "" {
|
||||
return nil, errors.New("URL is empty. Skipping.")
|
||||
}
|
||||
@ -115,6 +111,8 @@ func (h *HttpClient) Get(rawurl string) ([]byte, error) {
|
||||
duration = h.MaxBackoff
|
||||
}
|
||||
|
||||
log.Printf("Sleeping for %d seconds", duration)
|
||||
|
||||
time.Sleep(duration)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package httpbackoff
|
||||
package pkg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -19,7 +19,7 @@ var expBackoffTests = []struct {
|
||||
|
||||
// Test exponential backoff and that it continues retrying if a 5xx response is
|
||||
// received
|
||||
func TestFetchURLExpBackOff(t *testing.T) {
|
||||
func TestGetURLExpBackOff(t *testing.T) {
|
||||
client := NewHttpClient()
|
||||
|
||||
for i, tt := range expBackoffTests {
|
||||
@ -52,7 +52,7 @@ func TestFetchURLExpBackOff(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test that it stops retrying if a 4xx response comes back
|
||||
func TestFetchURL4xx(t *testing.T) {
|
||||
func TestGetURL4xx(t *testing.T) {
|
||||
client := NewHttpClient()
|
||||
retries := 0
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@ -72,7 +72,7 @@ func TestFetchURL4xx(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test that it fetches and returns user-data just fine
|
||||
func TestFetchURL2xx(t *testing.T) {
|
||||
func TestGetURL2xx(t *testing.T) {
|
||||
var cloudcfg = `
|
||||
#cloud-config
|
||||
coreos:
|
||||
@ -103,7 +103,7 @@ coreos:
|
||||
}
|
||||
|
||||
// Test attempt to fetching using malformed URL
|
||||
func TestFetchURLMalformed(t *testing.T) {
|
||||
func TestGetMalformedURL(t *testing.T) {
|
||||
client := NewHttpClient()
|
||||
|
||||
var tests = []struct {
|
@ -1 +0,0 @@
|
||||
../../../
|
Loading…
x
Reference in New Issue
Block a user