github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/broker/services.go (about) 1 package broker 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/kyma-project/kyma-environment-broker/internal/euaccess" 8 9 "github.com/kyma-project/kyma-environment-broker/internal/middleware" 10 11 "github.com/pivotal-cf/brokerapi/v8/domain" 12 "github.com/sirupsen/logrus" 13 ) 14 15 const ( 16 ControlsOrderKey = "_controlsOrder" 17 PropertiesKey = "properties" 18 ) 19 20 type ServicesEndpoint struct { 21 log logrus.FieldLogger 22 cfg Config 23 servicesConfig ServicesConfig 24 25 enabledPlanIDs map[string]struct{} 26 } 27 28 func NewServices(cfg Config, servicesConfig ServicesConfig, log logrus.FieldLogger) *ServicesEndpoint { 29 enabledPlanIDs := map[string]struct{}{} 30 for _, planName := range cfg.EnablePlans { 31 id := PlanIDsMapping[planName] 32 enabledPlanIDs[id] = struct{}{} 33 } 34 35 return &ServicesEndpoint{ 36 log: log.WithField("service", "ServicesEndpoint"), 37 cfg: cfg, 38 servicesConfig: servicesConfig, 39 enabledPlanIDs: enabledPlanIDs, 40 } 41 } 42 43 // Services gets the catalog of services offered by the service broker 44 // 45 // GET /v2/catalog 46 func (b *ServicesEndpoint) Services(ctx context.Context) ([]domain.Service, error) { 47 var availableServicePlans []domain.ServicePlan 48 // we scope to the kymaruntime service only 49 class, ok := b.servicesConfig[KymaServiceName] 50 if !ok { 51 return nil, fmt.Errorf("while getting %s class data", KymaServiceName) 52 } 53 54 provider, ok := middleware.ProviderFromContext(ctx) 55 platformRegion, ok := middleware.RegionFromContext(ctx) 56 regionRequired := b.cfg.ExposeSchemaWithRegionRequired || b.cfg.RegionParameterIsRequired 57 modulesEnabled := b.cfg.AllowModulesParameters 58 for _, plan := range Plans(class.Plans, provider, b.cfg.IncludeAdditionalParamsInSchema, euaccess.IsEURestrictedAccess(platformRegion), regionRequired, modulesEnabled) { 59 // filter out not enabled plans 60 if _, exists := b.enabledPlanIDs[plan.ID]; !exists { 61 continue 62 } 63 // p := plan.PlanDefinition 64 65 availableServicePlans = append(availableServicePlans, plan) 66 } 67 68 return []domain.Service{ 69 { 70 ID: KymaServiceID, 71 Name: KymaServiceName, 72 Description: class.Description, 73 Bindable: false, 74 InstancesRetrievable: true, 75 Tags: []string{ 76 "SAP", 77 "Kyma", 78 }, 79 Plans: availableServicePlans, 80 Metadata: &domain.ServiceMetadata{ 81 DisplayName: class.Metadata.DisplayName, 82 ImageUrl: class.Metadata.ImageUrl, 83 LongDescription: class.Metadata.LongDescription, 84 ProviderDisplayName: class.Metadata.ProviderDisplayName, 85 DocumentationUrl: class.Metadata.DocumentationUrl, 86 SupportUrl: class.Metadata.SupportUrl, 87 }, 88 AllowContextUpdates: true, 89 }, 90 }, nil 91 }