diff --git a/Gopkg.lock b/Gopkg.lock index a32a4bec..a2370e20 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,44 +2,65 @@ [[projects]] - branch = "master" - digest = "1:e5a6dff65fb1ea477350d48ecd5f92e29be4212ca0a17d2bdb8932ef8149ba45" + digest = "1:20e04f7898c08824b69760e314c3ff9b64e65fd78889ad64a8ef1dcbc94bcaf4" name = "code.cloudfoundry.org/lager" packages = [ ".", "lagerctx", "lagertest", ] - pruneopts = "" - revision = "a77e1033ba8d8e36597be5c0d384ee6054105bc2" + pruneopts = "UT" + revision = "b152b7147a2a0154109a5194fcc7f4a933283abb" + version = "v2.0.0" [[projects]] - digest = "1:029f604c64cb13a3e2facee76fd1ae446d343df36fbb280b536bf36f9864ef1f" + digest = "1:15ecf74f7d731f8f0cf8f432b27c14748c2440551ce6a136c384747242f38c53" name = "github.com/drewolson/testflight" packages = ["."] - pruneopts = "" + pruneopts = "UT" revision = "ab2d9a74b97eda058004c8deef80ac624432f408" version = "v1.0.0" [[projects]] - digest = "1:20ed7daa9b3b38b6d1d39b48ab3fd31122be5419461470d0c28de3e121c93ecf" + digest = "1:236d7e1bdb50d8f68559af37dbcf9d142d56b431c9b2176d41e2a009b664cda8" + name = "github.com/google/uuid" + packages = ["."] + pruneopts = "UT" + revision = "9b3b1e0f5f99ae461456d768e7d301a7acdaa2d8" + version = "v1.1.0" + +[[projects]] + digest = "1:c79fb010be38a59d657c48c6ba1d003a8aa651fa56b579d959d74573b7dff8e1" name = "github.com/gorilla/context" packages = ["."] - pruneopts = "" - revision = "1ea25387ff6f684839d82767c1733ff4d4d15d0a" - version = "v1.1" + pruneopts = "UT" + revision = "08b5f424b9271eedf6f9f0ce86cb9396ed337a42" + version = "v1.1.1" [[projects]] - digest = "1:aa016bbb412f496a7baed9e02787a60cd15c9a3edfa72da9c4a95d6cea610334" + digest = "1:e73f5b0152105f18bc131fba127d9949305c8693f8a762588a82a48f61756f5f" name = "github.com/gorilla/mux" packages = ["."] - pruneopts = "" - revision = "53c1911da2b537f792e7cafcb446b05ffe33b996" - version = "v1.6.1" + pruneopts = "UT" + revision = "e3702bed27f0d39777b0b37b664b6280e8ef8fbf" + version = "v1.6.2" [[projects]] branch = "master" - digest = "1:8df8625c851c00c5c55a8cde64323d203fd1221a8ea3e137ad2d05d01945ca55" + digest = "1:59392ed8afb901aab4287d4894df8191722e34f3957716f4350c8c133ce99046" + name = "github.com/hpcloud/tail" + packages = [ + ".", + "ratelimiter", + "util", + "watch", + "winfile", + ] + pruneopts = "UT" + revision = "a1dbeea552b7c8df4b542c66073e393de198a800" + +[[projects]] + digest = "1:5f4b78246f0bcb105b1e3b2b9e22b52a57cd02f57a8078572fe27c62f4a75ff7" name = "github.com/onsi/ginkgo" packages = [ ".", @@ -61,12 +82,12 @@ "reporters/stenographer/support/go-isatty", "types", ] - pruneopts = "" - revision = "9008c7b79f9636c46a0a945141020124702f0ecf" + pruneopts = "UT" + revision = "2e1be8f7d90e9d3e3e58b0ce470f2f14d075406f" + version = "v1.7.0" [[projects]] - branch = "master" - digest = "1:44c1e18198c748e250810263a25205168c1cb452bdd8b850c40ef93b92ab4c7d" + digest = "1:5a52ee2374f9d6582665cf84195058888faff1007302aa7f07abee1fda39bb54" name = "github.com/onsi/gomega" packages = [ ".", @@ -83,46 +104,48 @@ "matchers/support/goraph/util", "types", ] - pruneopts = "" - revision = "49e4233a3b46c26dddd43cf84547cf31c92d0f2b" + pruneopts = "UT" + revision = "65fb64232476ad9046e57c26cd0bff3d3a8dc6cd" + version = "v1.4.3" [[projects]] - branch = "master" - digest = "1:beeb9206cc21cfeb113066c3dcf4bbb0ba304d73dd441f3244721566f51f44e6" + digest = "1:e5d0bd87abc2781d14e274807a470acd180f0499f8bf5bb18606e9ec22ad9de9" name = "github.com/pborman/uuid" packages = ["."] - pruneopts = "" - revision = "c65b2f87fee37d1c7854c9164a450713c28d50cd" + pruneopts = "UT" + revision = "adf5a7427709b9deb95d29d3fa8a2bf9cfd388f1" + version = "v1.2" [[projects]] - digest = "1:7365acd48986e205ccb8652cc746f09c8b7876030d53710ea6ef7d0bd0dcd7ca" + digest = "1:40e195917a951a8bf867cd05de2a46aaf1806c50cf92eebf4c16f78cd196f747" name = "github.com/pkg/errors" packages = ["."] - pruneopts = "" + pruneopts = "UT" revision = "645ef00459ed84a119197bfb8d8205042c6df63d" version = "v0.8.0" [[projects]] branch = "master" - digest = "1:b4ba046df563f56fe42b6270b20039107a37e1ab47c97aa47a16f848aa5b6d9a" + digest = "1:5193d913046443e59093d66a97a40c51f4a5ea4ceba60f3b3ecf89694de5d16f" name = "golang.org/x/net" packages = [ "html", "html/atom", "html/charset", ] - pruneopts = "" - revision = "cbe0f9307d0156177f9dd5dc85da1a31abc5f2fb" + pruneopts = "UT" + revision = "927f97764cc334a6575f4b7a1584a147864d5723" [[projects]] - digest = "1:1ed067f6338b4c6496a27a889a53e5c1adcafdcc4442024a01e035e5dcf28698" + branch = "master" + digest = "1:5004e851e5eccde563d17871cd9d11c82e2faa578b1a0de81dc74867ad3845a4" name = "golang.org/x/sys" packages = ["unix"] - pruneopts = "" - revision = "a408501be4d17ee978c04a618e7a1b22af058c0e" + pruneopts = "UT" + revision = "82a175fd1598e8a172e58ebdf5ed262bb29129e5" [[projects]] - digest = "1:5acd3512b047305d49e8763eef7ba423901e85d5dd2fd1e71778a0ea8de10bd4" + digest = "1:aa4d6967a3237f8367b6bf91503964a77183ecf696f1273e8ad3551bb4412b5f" name = "golang.org/x/text" packages = [ "encoding", @@ -143,16 +166,32 @@ "transform", "unicode/cldr", ] - pruneopts = "" + pruneopts = "UT" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" version = "v0.3.0" [[projects]] - digest = "1:59925e8b791ee90b60e4dc05099d34fd38d0922a2a8f9b4e700cb61fc421e6b2" + digest = "1:abeb38ade3f32a92943e5be54f55ed6d6e3b6602761d74b4aab4c9dd45c18abd" + name = "gopkg.in/fsnotify/fsnotify.v1" + packages = ["."] + pruneopts = "UT" + revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9" + version = "v1.4.7" + +[[projects]] + digest = "1:3c839a777de0e6da035c9de900b60cbec463b0a89351192c1ea083eaf9e0fce0" + name = "gopkg.in/tomb.v1" + packages = ["."] + pruneopts = "UT" + revision = "c131134a1947e9afd9cecfe11f4c6dff0732ae58" + +[[projects]] + digest = "1:4d2e5a73dc1500038e504a8d78b986630e3626dc027bc030ba5c75da257cdb96" name = "gopkg.in/yaml.v2" packages = ["."] - pruneopts = "" - revision = "e4d366fc3c7938e2958e662b4258c7a89e1f0e3e" + pruneopts = "UT" + revision = "51d6538a90f86fe93ac480b35f37b2be17fef232" + version = "v2.2.2" [solve-meta] analyzer-name = "dep" diff --git a/Gopkg.toml b/Gopkg.toml index 8fdc806c..ddd73b3d 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -1,7 +1,6 @@ - # Gopkg.toml example # -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md +# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html # for detailed Gopkg.toml documentation. # # required = ["github.com/user/thing/cmd/thing"] @@ -17,13 +16,18 @@ # source = "github.com/myfork/project2" # # [[override]] -# name = "github.com/x/y" -# version = "2.4.0" +# name = "github.com/x/y" +# version = "2.4.0" +# +# [prune] +# non-go = false +# go-tests = true +# unused-packages = true [[constraint]] name = "code.cloudfoundry.org/lager" - branch = "master" + version = "2.0.0" [[constraint]] name = "github.com/drewolson/testflight" @@ -31,20 +35,24 @@ [[constraint]] name = "github.com/gorilla/mux" - version = "1.6.0" + version = "1.6.2" [[constraint]] name = "github.com/onsi/ginkgo" - branch = "master" + version = "1.7.0" [[constraint]] name = "github.com/onsi/gomega" - branch = "master" + version = "1.4.3" [[constraint]] - branch = "master" name = "github.com/pborman/uuid" + version = "1.2.0" [[constraint]] name = "github.com/pkg/errors" - version = "^0.8.0" + version = "0.8.0" + +[prune] + go-tests = true + unused-packages = true diff --git a/README.md b/README.md index abd7a9eb..f9f50365 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # brokerapi -[![Build Status](https://travis-ci.org/pivotal-cf/brokerapi.svg?branch=master)](https://travis-ci.org/pivotal-cf/brokerapi) +[![Build Status](https://travis-ci.org/sharma-tapas/brokerapi.svg?branch=master)](https://travis-ci.org/sharma-tapas/brokerapi) A Go package for building [V2 Open Service Broker API](https://github.com/openservicebrokerapi/servicebroker/) compliant Service Brokers. -## [Docs](https://godoc.org/github.com/pivotal-cf/brokerapi) +## [Docs](https://godoc.org/github.com/sharma-tapas/brokerapi) ## Dependencies @@ -16,9 +16,9 @@ We use [dep](https://github.com/golang/dep) to manager our dependencies. Use `de ## Usage -`brokerapi` defines a [`ServiceBroker`](https://godoc.org/github.com/pivotal-cf/brokerapi#ServiceBroker) interface. Pass an implementation of this to [`brokerapi.New`](https://godoc.org/github.com/pivotal-cf/brokerapi#New), which returns an `http.Handler` that you can use to serve handle HTTP requests. +`brokerapi` defines a [`ServiceBroker`](https://godoc.org/github.com/sharma-tapas/brokerapi#ServiceBroker) interface. Pass an implementation of this to [`brokerapi.New`](https://godoc.org/github.com/sharma-tapas/brokerapi#New), which returns an `http.Handler` that you can use to serve handle HTTP requests. -Alternatively, if you already have a `*mux.Router` that you want to attach service broker routes to, you can use [`brokerapi.AttachRoutes`](https://godoc.org/github.com/pivotal-cf/brokerapi#AttachRoutes). +Alternatively, if you already have a `*mux.Router` that you want to attach service broker routes to, you can use [`brokerapi.AttachRoutes`](https://godoc.org/github.com/sharma-tapas/brokerapi#AttachRoutes). ## Error types @@ -30,4 +30,4 @@ Alternatively, if you already have a `*mux.Router` that you want to attach servi ## Example Service Broker -You can see the [cf-redis](https://github.com/pivotal-cf/cf-redis-broker/blob/2f0e9a8ebb1012a9be74bbef2d411b0b3b60352f/broker/broker.go) service broker uses the BrokerAPI package to create a service broker for Redis. +You can see the [cf-redis](https://github.com/sharma-tapas/cf-redis-broker/blob/2f0e9a8ebb1012a9be74bbef2d411b0b3b60352f/broker/broker.go) service broker uses the BrokerAPI package to create a service broker for Redis. diff --git a/api.go b/api.go index 27ccbebe..95c1bbbe 100644 --- a/api.go +++ b/api.go @@ -24,7 +24,7 @@ import ( "code.cloudfoundry.org/lager" "github.com/gorilla/mux" - "github.com/pivotal-cf/brokerapi/auth" + "github.com/sharma-tapas/brokerapi/auth" ) const ( diff --git a/api_test.go b/api_test.go index 17aba6d2..ba05b913 100644 --- a/api_test.go +++ b/api_test.go @@ -31,8 +31,8 @@ import ( "github.com/drewolson/testflight" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi" - "github.com/pivotal-cf/brokerapi/fakes" + "github.com/sharma-tapas/brokerapi" + "github.com/sharma-tapas/brokerapi/fakes" ) var _ = Describe("Service Broker API", func() { diff --git a/auth/auth_test.go b/auth/auth_test.go index 40eef9a5..53cd0151 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -21,8 +21,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - - "github.com/pivotal-cf/brokerapi/auth" + "github.com/sharma-tapas/brokerapi/auth" ) var _ = Describe("Auth Wrapper", func() { diff --git a/catalog.go b/catalog.go index d7a212b3..83406346 100644 --- a/catalog.go +++ b/catalog.go @@ -36,6 +36,7 @@ type Service struct { Requires []RequiredPermission `json:"requires,omitempty"` Metadata *ServiceMetadata `json:"metadata,omitempty"` DashboardClient *ServiceDashboardClient `json:"dashboard_client,omitempty"` + AdditionalMetadata map[string]interface{} } type ServiceDashboardClient struct { @@ -223,3 +224,46 @@ func (sm *ServiceMetadata) UnmarshalJSON(data []byte) error { } return nil } + +func (s Service) MarshalJSON() ([]byte, error) { + type Alias Service + + b, err := json.Marshal((Alias)(s)) + if err != nil { + return []byte{}, errors.Wrap(err, "unmarshallable content in AdditionalMetadata") + } + + var m map[string]interface{} + json.Unmarshal(b, &m) + delete(m, additionalMetadataName) + + for k, v := range s.AdditionalMetadata { + m[k] = v + } + return json.Marshal(m) +} + +func (s *Service) UnmarshalJSON(data []byte) error { + type Alias Service + + if err := json.Unmarshal(data, (*Alias)(s)); err != nil { + return err + } + + additionalMetadata := map[string]interface{}{} + if err := json.Unmarshal(data, &additionalMetadata); err != nil { + return err + } + + for _, jsonName := range GetJsonNames(reflect.ValueOf(s).Elem()) { + if jsonName == additionalMetadataName { + continue + } + delete(additionalMetadata, jsonName) + } + + if len(additionalMetadata) > 0 { + s.AdditionalMetadata = additionalMetadata + } + return nil +} diff --git a/catalog_test.go b/catalog_test.go index 790c7425..9b69d3f3 100644 --- a/catalog_test.go +++ b/catalog_test.go @@ -17,12 +17,13 @@ package brokerapi_test import ( "encoding/json" + "fmt" "reflect" "sync" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi" + "github.com/sharma-tapas/brokerapi" ) var _ = Describe("Catalog", func() { @@ -43,6 +44,10 @@ var _ = Describe("Catalog", func() { Secret: "dashboardsecret", RedirectURI: "the.dashboa.rd", }, + AdditionalMetadata: map[string]interface{}{ + "baz": 1, + "foo": "bar", + }, } jsonString := `{ "id":"ID-1", @@ -57,11 +62,15 @@ var _ = Describe("Catalog", func() { "secret":"dashboardsecret", "redirect_uri":"the.dashboa.rd" }, - "metadata":{ - - } + "metadata":{}, + "foo": "bar", + "baz": 1 }` + b, _ := json.Marshal(service) + fmt.Println(string(b)) Expect(json.Marshal(service)).To(MatchJSON(jsonString)) + By("not mutating the AdditionalMetadata during custom JSON marshalling") + Expect(len(service.AdditionalMetadata)).To(Equal(2)) }) }) @@ -85,6 +94,10 @@ var _ = Describe("Catalog", func() { Secret: "dashboardsecret", RedirectURI: "the.dashboa.rd", }, + AdditionalMetadata: map[string]interface{}{ + "baz": 1, + "foo": "bar", + }, } jsonString := `{ "id":"ID-1", @@ -100,11 +113,13 @@ var _ = Describe("Catalog", func() { "secret":"dashboardsecret", "redirect_uri":"the.dashboa.rd" }, - "metadata":{ - - } + "metadata":{}, + "foo": "bar", + "baz": 1 }` Expect(json.Marshal(service)).To(MatchJSON(jsonString)) + By("not mutating the AdditionalMetadata during custom JSON marshalling") + Expect(len(service.AdditionalMetadata)).To(Equal(2)) }) }) diff --git a/failure_response_test.go b/failure_response_test.go index 8a203335..917444cc 100644 --- a/failure_response_test.go +++ b/failure_response_test.go @@ -16,7 +16,7 @@ package brokerapi_test import ( - "github.com/pivotal-cf/brokerapi" + "github.com/sharma-tapas/brokerapi" "errors" diff --git a/fakes/fake_service_broker.go b/fakes/fake_service_broker.go index 2f06d816..ac978b1b 100644 --- a/fakes/fake_service_broker.go +++ b/fakes/fake_service_broker.go @@ -4,7 +4,7 @@ import ( "context" "errors" - "github.com/pivotal-cf/brokerapi" + "github.com/sharma-tapas/brokerapi" ) type FakeServiceBroker struct { diff --git a/response_test.go b/response_test.go index adc2338d..dc59b8d7 100644 --- a/response_test.go +++ b/response_test.go @@ -20,7 +20,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/pivotal-cf/brokerapi" + "github.com/sharma-tapas/brokerapi" ) var _ = Describe("Catalog Response", func() {