Skip to content

Commit

Permalink
dded AdditionalMetadata to the catalog.Service struct
Browse files Browse the repository at this point in the history
- pass more information regarding different cloud providers.

Signed-off-by: Tapas Sharma <[email protected]>
  • Loading branch information
Tapas Sharma committed Jan 3, 2019
1 parent 588de80 commit cb861c3
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 68 deletions.
115 changes: 77 additions & 38 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 18 additions & 10 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -17,34 +16,43 @@
# 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"
version = "1.0.0"

[[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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand All @@ -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.
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 1 addition & 2 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
44 changes: 44 additions & 0 deletions catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Loading

0 comments on commit cb861c3

Please sign in to comment.