github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/notification/bundle.go (about) 1 package notification 2 3 import ( 4 kebError "github.com/kyma-project/kyma-environment-broker/internal/error" 5 ) 6 7 type ( 8 Config struct { 9 Url string `envconfig:"default="` 10 } 11 12 NotificationClient interface { 13 CreateEvent(CreateEventRequest) error 14 UpdateEvent(UpdateEventRequest) error 15 CancelEvent(CancelEventRequest) error 16 } 17 18 NotificationParams struct { 19 OrchestrationID string `json:"orchestrationId"` 20 EventType string `json:"eventType"` 21 Tenants []NotificationTenant `json:"tenants"` 22 } 23 24 NotificationBundle struct { 25 client NotificationClient 26 config Config 27 notificationParams NotificationParams 28 } 29 ) 30 31 func NewNotificationBundle(bundleIdentifier string, notificationParams NotificationParams, c NotificationClient, cfg Config) *NotificationBundle { 32 return &NotificationBundle{ 33 client: c, 34 config: cfg, 35 notificationParams: notificationParams, 36 } 37 } 38 39 func (b *NotificationBundle) CreateNotificationEvent() error { 40 request := CreateEventRequest{ 41 OrchestrationID: b.notificationParams.OrchestrationID, 42 EventType: b.notificationParams.EventType, 43 Tenants: b.notificationParams.Tenants, 44 } 45 err := b.client.CreateEvent(request) 46 if err != nil { 47 return kebError.NewTemporaryError("failed to create event") 48 } 49 50 return nil 51 } 52 53 func (b *NotificationBundle) UpdateNotificationEvent() error { 54 request := UpdateEventRequest{ 55 OrchestrationID: b.notificationParams.OrchestrationID, 56 Tenants: b.notificationParams.Tenants, 57 } 58 err := b.client.UpdateEvent(request) 59 if err != nil { 60 return kebError.NewTemporaryError("failed to update event") 61 } 62 63 return nil 64 } 65 66 func (b *NotificationBundle) CancelNotificationEvent() error { 67 request := CancelEventRequest{OrchestrationID: b.notificationParams.OrchestrationID} 68 err := b.client.CancelEvent(request) 69 if err != nil { 70 return kebError.NewTemporaryError("failed to cancel event") 71 } 72 73 return nil 74 }