From 712247934a771ca533b0febcca4b2702225b17cb Mon Sep 17 00:00:00 2001 From: elinuxhenrik Date: Thu, 10 Nov 2022 10:24:02 +0100 Subject: [PATCH] Improvements Issue-ID: NONRTRIC-814 Signed-off-by: elinuxhenrik Change-Id: Ib1548369492338f8d660e5dd7890d967da1e24dc --- capifcore/internal/discoverservice/discoverservice.go | 14 ++++---------- .../internal/invokermanagement/invokermanagement.go | 18 +++++++++--------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/capifcore/internal/discoverservice/discoverservice.go b/capifcore/internal/discoverservice/discoverservice.go index 797eaa7..4ab8a92 100644 --- a/capifcore/internal/discoverservice/discoverservice.go +++ b/capifcore/internal/discoverservice/discoverservice.go @@ -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 diff --git a/capifcore/internal/invokermanagement/invokermanagement.go b/capifcore/internal/invokermanagement/invokermanagement.go index 2de6ca6..20bba33 100644 --- a/capifcore/internal/invokermanagement/invokermanagement.go +++ b/capifcore/internal/invokermanagement/invokermanagement.go @@ -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 { -- 2.16.6