NONRTRIC-946: Get Allowed Publishers
[nonrtric/plt/sme.git] / capifcore / internal / providermanagement / providermanagement.go
index d5e7a63..ebdfa9a 100644 (file)
@@ -26,18 +26,18 @@ import (
        "path"
        "sync"
 
-       "github.com/labstack/echo/v4"
+       echo "github.com/labstack/echo/v4"
+       log "github.com/sirupsen/logrus"
 
        "oransc.org/nonrtric/capifcore/internal/common29122"
        provapi "oransc.org/nonrtric/capifcore/internal/providermanagementapi"
-
-       log "github.com/sirupsen/logrus"
 )
 
 //go:generate mockery --name ServiceRegister
 type ServiceRegister interface {
        IsFunctionRegistered(functionId string) bool
        GetAefsForPublisher(apfId string) []string
+       IsPublishingFunctionRegistered(apiProvFuncId string) bool
 }
 
 type ProviderManager struct {
@@ -69,6 +69,15 @@ func (pm *ProviderManager) GetAefsForPublisher(apfId string) []string {
        return nil
 }
 
+func (pm *ProviderManager) IsPublishingFunctionRegistered(apiProvFuncId string) bool {
+       for _, provider := range pm.registeredProviders {
+               if provider.IsPublishingFunctionRegistered(apiProvFuncId) {
+                       return true
+               }
+       }
+       return false
+}
+
 func (pm *ProviderManager) PostRegistrations(ctx echo.Context) error {
        var newProvider provapi.APIProviderEnrolmentDetails
        errMsg := "Unable to register provider due to %s"
@@ -143,6 +152,12 @@ func (pm *ProviderManager) PutRegistrationsRegistrationId(ctx echo.Context, regi
                return sendCoreError(ctx, http.StatusBadRequest, fmt.Sprintf(errMsg, err))
        }
 
+       // Additional validation for PUT
+       if (updatedProvider.ApiProvDomId == nil) || (*updatedProvider.ApiProvDomId != registrationId) {
+               errDetail := "APIProviderEnrolmentDetails ApiProvDomId doesn't match path parameter"
+               return sendCoreError(ctx, http.StatusBadRequest, fmt.Sprintf(errMsg, errDetail))
+       }
+
        if err = pm.updateProvider(updatedProvider, registeredProvider); err != nil {
                return sendCoreError(ctx, http.StatusBadRequest, fmt.Sprintf(errMsg, err))
        }