}
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
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
}
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
}
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 {