From 484ea3724550f310e83beeb0d7a92db107be5ca1 Mon Sep 17 00:00:00 2001 From: Stefan Engstrom Date: Mon, 12 Mar 2018 14:40:10 -0500 Subject: [PATCH 1/5] updating mergo.Merge() to version passing override functions --- .gitignore | 3 +++ phpipam/session/session.go | 2 +- vendor/vendor.json | 13 ------------- 3 files changed, 4 insertions(+), 14 deletions(-) delete mode 100644 vendor/vendor.json diff --git a/.gitignore b/.gitignore index 1b256ac..09f24d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ cover.out vendor/* !vendor/vendor.json +.idea/ +Gopkg.toml +Gopkg.lock diff --git a/phpipam/session/session.go b/phpipam/session/session.go index 9329683..f335c58 100644 --- a/phpipam/session/session.go +++ b/phpipam/session/session.go @@ -32,7 +32,7 @@ func NewSession(configs ...phpipam.Config) *Session { Config: phpipam.DefaultConfigProvider(), } for _, v := range configs { - mergo.MergeWithOverwrite(&s.Config, v) + mergo.Merge(&s.Config, v, mergo.WithOverride) } return s diff --git a/vendor/vendor.json b/vendor/vendor.json deleted file mode 100644 index 91b13c7..0000000 --- a/vendor/vendor.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "comment": "", - "ignore": "test", - "package": [ - { - "checksumSHA1": "hwGdeQbcfc2RvIQS5wAaYRKJDd4=", - "path": "github.com/imdario/mergo", - "revision": "50d4dbd4eb0e84778abe37cefef140271d96fade", - "revisionTime": "2016-05-17T06:44:35Z" - } - ], - "rootPath": "github.com/paybyphone/phpipam-sdk-go" -} From c072da14c6b1a11f52d46fcf59ec34a7b7691858 Mon Sep 17 00:00:00 2001 From: Stefan Engstrom Date: Wed, 14 Mar 2018 11:37:24 -0500 Subject: [PATCH 2/5] allow specifying an http client --- phpipam/client/client.go | 1 + phpipam/request/request.go | 20 +++++++++++++++++--- phpipam/session/session.go | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/phpipam/client/client.go b/phpipam/client/client.go index b8fd830..99dcd25 100644 --- a/phpipam/client/client.go +++ b/phpipam/client/client.go @@ -8,6 +8,7 @@ import ( "github.com/paybyphone/phpipam-sdk-go/phpipam" "github.com/paybyphone/phpipam-sdk-go/phpipam/request" "github.com/paybyphone/phpipam-sdk-go/phpipam/session" + "net/http" ) // Client encompasses a generic client object that is further extended by diff --git a/phpipam/request/request.go b/phpipam/request/request.go index d8f47dd..5b84db6 100644 --- a/phpipam/request/request.go +++ b/phpipam/request/request.go @@ -129,12 +129,26 @@ func newRequestResponse(r *http.Response) *requestResponse { func (r *Request) Send() error { var req *http.Request var err error - client := &http.Client{ - CheckRedirect: func(req *http.Request, via []*http.Request) error { + + r.Session.RLock() + client := r.Session.HttpClient + r.Session.RUnlock() + + if client == nil { + client = new(http.Client) + } + + if client.CheckRedirect == nil { + client.CheckRedirect = func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse - }, + } } + // Write the client back to the session object and re-use it next time + r.Session.Lock() + r.Session.HttpClient = client + r.Session.Unlock() + switch r.Method { case "OPTIONS", "GET", "POST", "PUT", "PATCH", "DELETE": bs, err := json.Marshal(r.Input) diff --git a/phpipam/session/session.go b/phpipam/session/session.go index f335c58..4eceaa0 100644 --- a/phpipam/session/session.go +++ b/phpipam/session/session.go @@ -4,6 +4,8 @@ package session import ( "github.com/imdario/mergo" "github.com/paybyphone/phpipam-sdk-go/phpipam" + "net/http" + "sync" ) // timeLayout represents the datetime format returned by the PHPIPAM api. @@ -22,6 +24,12 @@ type Session struct { // The session token. Token Token + + // A session shares this client if provided + HttpClient *http.Client + + sync.RWMutex // protect updates of HttpClient + } // NewSession creates a new session based off supplied configs. It is up to the @@ -37,3 +45,12 @@ func NewSession(configs ...phpipam.Config) *Session { return s } + +// SetHttpClient sets a specific http client with a particular transport etc +// For backwards compatibility, a CheckRedirect function will be added at call time if not present +func (s *Session) SetHttpClient(hc *http.Client) { + s.Lock() + s.HttpClient = hc + s.Unlock() +} + From bde1fe080e12cdf732e477ab0b89bef7f24b1eb5 Mon Sep 17 00:00:00 2001 From: Stefan Engstrom Date: Wed, 14 Mar 2018 11:38:26 -0500 Subject: [PATCH 3/5] delete unused import --- phpipam/client/client.go | 1 - 1 file changed, 1 deletion(-) diff --git a/phpipam/client/client.go b/phpipam/client/client.go index 99dcd25..b8fd830 100644 --- a/phpipam/client/client.go +++ b/phpipam/client/client.go @@ -8,7 +8,6 @@ import ( "github.com/paybyphone/phpipam-sdk-go/phpipam" "github.com/paybyphone/phpipam-sdk-go/phpipam/request" "github.com/paybyphone/phpipam-sdk-go/phpipam/session" - "net/http" ) // Client encompasses a generic client object that is further extended by From ce51450a4d602019f35150ddc8def81d7b0f3f9d Mon Sep 17 00:00:00 2001 From: Stefan Engstrom Date: Wed, 14 Mar 2018 11:43:09 -0500 Subject: [PATCH 4/5] checking in deb files --- .gitignore | 3 --- Gopkg.lock | 21 +++++++++++++++++++++ Gopkg.toml | 11 +++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 Gopkg.lock create mode 100644 Gopkg.toml diff --git a/.gitignore b/.gitignore index 09f24d4..b713e92 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ cover.out vendor/* -!vendor/vendor.json .idea/ -Gopkg.toml -Gopkg.lock diff --git a/Gopkg.lock b/Gopkg.lock new file mode 100644 index 0000000..12235e5 --- /dev/null +++ b/Gopkg.lock @@ -0,0 +1,21 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + name = "github.com/davecgh/go-spew" + packages = ["spew"] + revision = "346938d642f2ec3594ed81d874461961cd0faa76" + version = "v1.1.0" + +[[projects]] + name = "github.com/imdario/mergo" + packages = ["."] + revision = "163f41321a19dd09362d4c63cc2489db2015f1f4" + version = "0.3.2" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "56d6604f451ec9a4dc705a505ad2dad3e2afa81b31c4226697d9009f545c341f" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml new file mode 100644 index 0000000..2bde623 --- /dev/null +++ b/Gopkg.toml @@ -0,0 +1,11 @@ +[[constraint]] + name = "github.com/davecgh/go-spew" + version = "1.1.0" + +[[constraint]] + name = "github.com/imdario/mergo" + version = "0.3.2" + +[[constraint]] + branch = "master" + name = "github.com/paybyphone/phpipam-sdk-go" From 8ac494a9cac92237d88e5efffecd0061ce4a9835 Mon Sep 17 00:00:00 2001 From: Stefan Engstrom Date: Mon, 19 Mar 2018 16:56:25 -0500 Subject: [PATCH 5/5] discoverSubnets returns true with '4' - adapting to that reality --- phpipam/phpipam.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpipam/phpipam.go b/phpipam/phpipam.go index 4f6e25c..1ad59fd 100644 --- a/phpipam/phpipam.go +++ b/phpipam/phpipam.go @@ -105,7 +105,7 @@ func (bis *BoolIntString) UnmarshalJSON(b []byte) error { switch s { case "0", "": *bis = false - case "1": + case "1","4": // for the bizarre case when IPAM returns "4" as true *bis = true default: return &json.UnmarshalTypeError{