forked from kyma-project/control-plane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
services.go
86 lines (75 loc) · 2.43 KB
/
services.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package broker
import (
"context"
"encoding/json"
"github.com/kyma-project/control-plane/components/kyma-environment-broker/internal/middleware"
"github.com/pkg/errors"
"github.com/pivotal-cf/brokerapi/v7/domain"
"github.com/sirupsen/logrus"
)
type ServicesEndpoint struct {
log logrus.FieldLogger
cfg Config
servicesConfig ServicesConfig
enabledPlanIDs map[string]struct{}
}
func NewServices(cfg Config, servicesConfig ServicesConfig, log logrus.FieldLogger) *ServicesEndpoint {
enabledPlanIDs := map[string]struct{}{}
for _, planName := range cfg.EnablePlans {
id := PlanIDsMapping[planName]
enabledPlanIDs[id] = struct{}{}
}
return &ServicesEndpoint{
log: log.WithField("service", "ServicesEndpoint"),
cfg: cfg,
servicesConfig: servicesConfig,
enabledPlanIDs: enabledPlanIDs,
}
}
// Services gets the catalog of services offered by the service broker
// GET /v2/catalog
func (b *ServicesEndpoint) Services(ctx context.Context) ([]domain.Service, error) {
var availableServicePlans []domain.ServicePlan
// we scope to the kymaruntime service only
class, ok := b.servicesConfig[KymaServiceName]
if !ok {
return nil, errors.Errorf("while getting %s class data", KymaServiceName)
}
provider, ok := middleware.ProviderFromContext(ctx)
for _, plan := range Plans(class.Plans, provider) {
// filter out not enabled plans
if _, exists := b.enabledPlanIDs[plan.PlanDefinition.ID]; !exists {
continue
}
p := plan.PlanDefinition
err := json.Unmarshal(plan.provisioningRawSchema, &p.Schemas.Instance.Create.Parameters)
if err != nil {
b.log.Errorf("while unmarshal schema: %s", err)
return nil, err
}
availableServicePlans = append(availableServicePlans, p)
}
return []domain.Service{
{
ID: KymaServiceID,
Name: KymaServiceName,
Description: class.Description,
Bindable: true,
InstancesRetrievable: true,
Tags: []string{
"SAP",
"Kyma",
},
Plans: availableServicePlans,
Metadata: &domain.ServiceMetadata{
DisplayName: class.Metadata.DisplayName,
ImageUrl: class.Metadata.ImageUrl,
LongDescription: class.Metadata.LongDescription,
ProviderDisplayName: class.Metadata.ProviderDisplayName,
DocumentationUrl: class.Metadata.DocumentationUrl,
SupportUrl: class.Metadata.SupportUrl,
},
AllowContextUpdates: true,
},
}, nil
}