2 // ========================LICENSE_START=================================
5 // Copyright (C) 2023: Nordix Foundation
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // ========================LICENSE_END===================================
30 func (es EventSubscription) Validate() error {
31 if len(es.Events) == 0 {
32 return errors.New("required attribute EventSubscription:events must contain at least one element")
35 for _, event := range es.Events {
36 if err := validateEvent(event); err != nil {
37 return errors.New("EventSubscription events contains invalid event")
41 if len(strings.TrimSpace(string(es.NotificationDestination))) == 0 {
42 return errors.New("EventSubscription missing required notificationDestination")
44 if _, err := url.ParseRequestURI(string(es.NotificationDestination)); err != nil {
45 return fmt.Errorf("APIInvokerEnrolmentDetails has invalid notificationDestination, err=%s", err)
51 func validateEvent(event CAPIFEvent) error {
53 case CAPIFEventACCESSCONTROLPOLICYUNAVAILABLE:
54 case CAPIFEventACCESSCONTROLPOLICYUPDATE:
55 case CAPIFEventAPIINVOKERAUTHORIZATIONREVOKED:
56 case CAPIFEventAPIINVOKEROFFBOARDED:
57 case CAPIFEventAPIINVOKERONBOARDED:
58 case CAPIFEventAPIINVOKERUPDATED:
59 case CAPIFEventAPITOPOLOGYHIDINGCREATED:
60 case CAPIFEventAPITOPOLOGYHIDINGREVOKED:
61 case CAPIFEventSERVICEAPIAVAILABLE:
62 case CAPIFEventSERVICEAPIINVOCATIONFAILURE:
63 case CAPIFEventSERVICEAPIINVOCATIONSUCCESS:
64 case CAPIFEventSERVICEAPIUNAVAILABLE:
65 case CAPIFEventSERVICEAPIUPDATE:
67 return errors.New("wrong event type")