package invokermanagement
import (
- "errors"
"fmt"
"net/http"
"path"
"sync"
"oransc.org/nonrtric/capifcore/internal/eventsapi"
- publishapi "oransc.org/nonrtric/capifcore/internal/publishserviceapi"
"oransc.org/nonrtric/capifcore/internal/common29122"
invokerapi "oransc.org/nonrtric/capifcore/internal/invokermanagementapi"
return sendCoreError(ctx, http.StatusBadRequest, fmt.Sprintf(errMsg, "invalid format for invoker"))
}
- if im.isInvokerOnboarded(newInvoker) {
- return sendCoreError(ctx, http.StatusForbidden, fmt.Sprintf(errMsg, "invoker already onboarded"))
+ if err := im.isInvokerOnboarded(newInvoker); err != nil {
+ return sendCoreError(ctx, http.StatusForbidden, fmt.Sprintf(errMsg, err))
}
if err := im.validateInvoker(newInvoker, ctx); err != nil {
return nil
}
-func (im *InvokerManager) isInvokerOnboarded(newInvoker invokerapi.APIInvokerEnrolmentDetails) bool {
+func (im *InvokerManager) isInvokerOnboarded(newInvoker invokerapi.APIInvokerEnrolmentDetails) error {
for _, invoker := range im.onboardedInvokers {
- if newInvoker.OnboardingInformation.ApiInvokerPublicKey == invoker.OnboardingInformation.ApiInvokerPublicKey {
- return true
+ if err := invoker.ValidateAlreadyOnboarded(newInvoker); err != nil {
+ return err
}
}
- return false
+ return nil
}
func (im *InvokerManager) prepareNewInvoker(newInvoker *invokerapi.APIInvokerEnrolmentDetails) {
if err := invoker.Validate(); err != nil {
return err
}
- if !im.areAPIsPublished(invoker.ApiList) {
- return errors.New("some APIs needed by invoker are not registered")
- }
return nil
}
-func (im *InvokerManager) areAPIsPublished(apis *invokerapi.APIList) bool {
- if apis == nil {
- return true
- }
- return im.publishRegister.AreAPIsPublished((*[]publishapi.ServiceAPIDescription)(apis))
-}
-
func (im *InvokerManager) sendEvent(invokerId string, eventType eventsapi.CAPIFEvent) {
invokerIds := []string{invokerId}
event := eventsapi.EventNotification{