-
Notifications
You must be signed in to change notification settings - Fork 0
/
broker.go
executable file
·64 lines (53 loc) · 1.48 KB
/
broker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package broker
import (
"context"
"fmt"
"code.cloudfoundry.org/lager"
brokerapi "github.com/pivotal-cf/brokerapi/domain"
"github.com/starkandwayne/scs-broker/config"
)
const (
ArtifactsDir string = "artifacts"
)
type SCSBroker struct {
Config config.Config
Logger lager.Logger
}
func (broker *SCSBroker) GetServiceByServiceID(serviceID string) (config.Service, error) {
for _, service := range broker.Config.Services {
if service.ServiceID == serviceID {
return service, nil
}
}
return config.Service{}, fmt.Errorf("No valid service found for %s", serviceID)
}
func (broker *SCSBroker) Services(ctx context.Context) ([]brokerapi.Service, error) {
services := []brokerapi.Service{}
for _, service := range broker.Config.Services {
brokerService := brokerapi.Service{
ID: service.ServiceID,
Name: service.ServiceName,
Description: service.ServiceDescription,
Bindable: true,
Plans: []brokerapi.ServicePlan{
{
ID: service.ServicePlanID,
Name: service.ServicePlanName,
Description: service.ServiceDescription,
Metadata: &brokerapi.ServicePlanMetadata{
DisplayName: service.ServicePlanName,
},
}},
Metadata: &brokerapi.ServiceMetadata{
DisplayName: service.ServiceName,
ImageUrl: fmt.Sprintf("data:image/png;base64,%s", broker.Config.IconImage),
},
Tags: []string{
"snw",
service.ServiceName,
},
}
services = append(services, brokerService)
}
return services, nil
}