Improvements 67/9567/1
authorelinuxhenrik <henrik.b.andersson@est.tech>
Thu, 10 Nov 2022 09:24:02 +0000 (10:24 +0100)
committerelinuxhenrik <henrik.b.andersson@est.tech>
Thu, 10 Nov 2022 09:24:06 +0000 (10:24 +0100)
Issue-ID: NONRTRIC-814
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Change-Id: Ib1548369492338f8d660e5dd7890d967da1e24dc

capifcore/internal/discoverservice/discoverservice.go
capifcore/internal/invokermanagement/invokermanagement.go

index 797eaa7..4ab8a92 100644 (file)
@@ -141,18 +141,12 @@ func checkVersion(version publishapi.Version, wantedVersion *string, commType *p
 }
 
 func checkCommType(resources *[]publishapi.Resource, commType *publishapi.CommunicationType) bool {
-       match := false
-       if commType != nil {
-               for _, resource := range *resources {
-                       if resource.CommType == *commType {
-                               match = true
-                               break
-                       }
+       for _, resource := range *resources {
+               if resource.CommType == *commType {
+                       return true
                }
-       } else {
-               match = true
        }
-       return match
+       return false
 }
 
 // This function wraps sending of an error in the Error format, and
index 2de6ca6..20bba33 100644 (file)
@@ -93,8 +93,8 @@ func (im *InvokerManager) PostOnboardedInvokers(ctx echo.Context) error {
                return sendCoreError(ctx, http.StatusBadRequest, "Invalid format for invoker")
        }
 
-       coreError := im.validateInvoker(newInvoker, ctx)
-       if coreError != nil {
+       shouldReturn, coreError := im.validateInvoker(newInvoker, ctx)
+       if shouldReturn {
                return coreError
        }
 
@@ -143,8 +143,8 @@ func (im *InvokerManager) PutOnboardedInvokersOnboardingId(ctx echo.Context, onb
                return sendCoreError(ctx, http.StatusBadRequest, "Invoker ApiInvokerId not matching")
        }
 
-       coreError := im.validateInvoker(invoker, ctx)
-       if coreError != nil {
+       shouldReturn, coreError := im.validateInvoker(invoker, ctx)
+       if shouldReturn {
                return coreError
        }
 
@@ -170,20 +170,20 @@ func (im *InvokerManager) ModifyIndApiInvokeEnrolment(ctx echo.Context, onboardi
        return ctx.NoContent(http.StatusNotImplemented)
 }
 
-func (im *InvokerManager) validateInvoker(invoker invokerapi.APIInvokerEnrolmentDetails, ctx echo.Context) error {
+func (im *InvokerManager) validateInvoker(invoker invokerapi.APIInvokerEnrolmentDetails, ctx echo.Context) (bool, error) {
        if invoker.NotificationDestination == "" {
-               return sendCoreError(ctx, http.StatusBadRequest, "Invoker missing required NotificationDestination")
+               return true, sendCoreError(ctx, http.StatusBadRequest, "Invoker missing required NotificationDestination")
        }
 
        if invoker.OnboardingInformation.ApiInvokerPublicKey == "" {
-               return sendCoreError(ctx, http.StatusBadRequest, "Invoker missing required OnboardingInformation.ApiInvokerPublicKey")
+               return true, sendCoreError(ctx, http.StatusBadRequest, "Invoker missing required OnboardingInformation.ApiInvokerPublicKey")
        }
 
        if !im.areAPIsRegistered(invoker.ApiList) {
-               return sendCoreError(ctx, http.StatusBadRequest, "Some APIs needed by invoker are not registered")
+               return true, sendCoreError(ctx, http.StatusBadRequest, "Some APIs needed by invoker are not registered")
        }
 
-       return nil
+       return false, nil
 }
 
 func (im *InvokerManager) areAPIsRegistered(apis *invokerapi.APIList) bool {