github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/orchestration/handlers/handlers.go (about) 1 package handlers 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/gorilla/mux" 8 "github.com/kyma-project/kyma-environment-broker/common/orchestration" 9 "github.com/kyma-project/kyma-environment-broker/internal/process" 10 "github.com/kyma-project/kyma-environment-broker/internal/storage" 11 "github.com/pkg/errors" 12 "github.com/sirupsen/logrus" 13 ) 14 15 type Handler interface { 16 AttachRoutes(router *mux.Router) 17 } 18 19 type handler struct { 20 handlers []Handler 21 } 22 23 func NewOrchestrationHandler(db storage.BrokerStorage, kymaQueue *process.Queue, clusterQueue *process.Queue, defaultMaxPage int, log logrus.FieldLogger) Handler { 24 return &handler{ 25 handlers: []Handler{ 26 NewKymaHandler(db.Orchestrations(), kymaQueue, log), 27 NewClusterHandler(db.Orchestrations(), clusterQueue, log), 28 NewOrchestrationStatusHandler(db.Operations(), db.Orchestrations(), db.RuntimeStates(), kymaQueue, clusterQueue, defaultMaxPage, log), 29 }, 30 } 31 } 32 33 func (h *handler) AttachRoutes(router *mux.Router) { 34 for _, handler := range h.handlers { 35 handler.AttachRoutes(router) 36 } 37 } 38 39 func validateTarget(spec orchestration.TargetSpec) error { 40 if spec.Include == nil || len(spec.Include) == 0 { 41 return errors.New("targets.include array must be not empty") 42 } 43 return nil 44 } 45 46 // ValidateDeprecatedParameters cheks if `maintenanceWindow` parameter is used as schedule. 47 func ValidateDeprecatedParameters(params orchestration.Parameters) error { 48 if params.Strategy.Schedule == string(orchestration.MaintenanceWindow) { 49 return fmt.Errorf("{\"strategy\":{\"schedule\": \"maintenanceWindow\"} is deprecated use {\"strategy\":{\"MaintenanceWindow\": true} instead") 50 } 51 return nil 52 } 53 54 // ValidateScheduleParameter cheks if the schedule parameter is valid. 55 func ValidateScheduleParameter(params *orchestration.Parameters) error { 56 switch params.Strategy.Schedule { 57 case "immediate": 58 case "now": 59 params.Strategy.ScheduleTime = time.Now() 60 default: 61 parsedTime, err := time.Parse(time.RFC3339, params.Strategy.Schedule) 62 if err == nil { 63 params.Strategy.ScheduleTime = parsedTime 64 } else { 65 return fmt.Errorf("the schedule filed does not contain 'imediate'/'now' nor is a date: %w", err) 66 } 67 } 68 return nil 69 }