Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

introduce PACKET_API_URL env variable #351

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"

"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -48,5 +47,4 @@ func Test_Deserialization(t *testing.T) {
assert.Equal(t, "10.144.51.11", volumes[0].IPs[1].String())
assert.Equal(t, 10, volumes[0].Capacity.Size)
assert.Equal(t, "gb", volumes[0].Capacity.Unit)

}
14 changes: 11 additions & 3 deletions packngo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (

const (
authTokenEnvVar = "PACKET_AUTH_TOKEN"
baseURL = "https://api.equinix.com/metal/v1/"
urlEnvVar = "PACKET_API_URL"
defaultURL = "https://api.equinix.com/metal/v1/"
mediaType = "application/json"
debugEnvVar = "PACKNGO_DEBUG"

Expand Down Expand Up @@ -339,7 +340,10 @@ func (c *Client) DoRequestWithHeader(method string, headers map[string]string, p
// an older version of Go, pass in a custom http.Client with a custom TLS configuration
// that sets "InsecureSkipVerify" to "true"
func NewClientWithAuth(consumerToken string, apiKey string, httpClient *http.Client) *Client {
client, _ := NewClientWithBaseURL(consumerToken, apiKey, httpClient, baseURL)
client, err := NewClient(WithAuth(consumerToken, apiKey), WithHTTPClient(httpClient))
if err != nil {
log.Printf("WARNING: NewClientWithAuth error %q suppressed", err)
}
return client
}

Expand Down Expand Up @@ -376,7 +380,11 @@ func NewClient(opts ...ClientOpt) (*Client, error) {
c.header.Set("Accept", mediaType)

var err error
c.BaseURL, err = url.Parse(baseURL)
apiURL := os.Getenv(urlEnvVar)
if apiURL == "" {
apiURL = defaultURL
}
c.BaseURL, err = url.Parse(apiURL)
if err != nil {
return nil, err
}
Expand Down
7 changes: 2 additions & 5 deletions packngo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
)

const (
apiURLEnvVar = "PACKET_API_URL"
packngoAccTestVar = "PACKNGO_TEST_ACTUAL_API"
testProjectPrefix = "PACKNGO_TEST_DELME_2d768716_"
testFacilityVar = "PACKNGO_TEST_FACILITY"
Expand Down Expand Up @@ -98,7 +97,6 @@ func setupWithProject(t *testing.T) (*Client, string, func()) {
}
stopRecord()
}

}

func skipUnlessAcceptanceTestsAllowed(t *testing.T) {
Expand Down Expand Up @@ -156,9 +154,9 @@ func setup(t *testing.T) (*Client, func()) {
if err != nil {
t.Fatal(err)
}
apiURL := os.Getenv(apiURLEnvVar)
apiURL := os.Getenv(urlEnvVar)
if apiURL == "" {
apiURL = baseURL
apiURL = defaultURL
}
r, stopRecord := testRecorder(t, name, mode)
httpClient := http.DefaultClient
Expand Down Expand Up @@ -216,7 +214,6 @@ func TestAccInvalidCredentials(t *testing.T) {
if !matched {
t.Fatalf("Unexpected error string: %s", expectedErr)
}

}

func Test_dumpDeprecation(t *testing.T) {
Expand Down