NONRTRIC-946: Get Allowed Publishers
[nonrtric/plt/sme.git] / capifcore / internal / publishservice / publishservice.go
index 0fa125f..372b1f8 100644 (file)
@@ -49,6 +49,7 @@ type PublishRegister interface {
        // Gets all published APIs.
        // Returns a list of all APIs that has been published.
        GetAllPublishedServices() []publishapi.ServiceAPIDescription
+       GetAllowedPublishedServices(invokerApiList []publishapi.ServiceAPIDescription) []publishapi.ServiceAPIDescription
 }
 
 type PublishService struct {
@@ -94,6 +95,29 @@ func (ps *PublishService) GetAllPublishedServices() []publishapi.ServiceAPIDescr
        return publishedDescriptions
 }
 
+func (ps *PublishService) GetAllowedPublishedServices(apiListRequestedServices []publishapi.ServiceAPIDescription) []publishapi.ServiceAPIDescription {
+       apiListAllPublished := ps.GetAllPublishedServices()
+       if apiListRequestedServices != nil {
+               allowedPublishedServices := intersection(apiListAllPublished, apiListRequestedServices)
+               return allowedPublishedServices
+       }
+       return []publishapi.ServiceAPIDescription{}
+}
+
+func intersection(a, b []publishapi.ServiceAPIDescription) []publishapi.ServiceAPIDescription {
+       var result []publishapi.ServiceAPIDescription
+
+       for _, itemA := range a {
+               for _, itemB := range b {
+                       if *itemA.ApiId == *itemB.ApiId {
+                               result = append(result, itemA)
+                               break
+                       }
+               }
+       }
+       return result
+}
+
 // Retrieve all published APIs.
 func (ps *PublishService) GetApfIdServiceApis(ctx echo.Context, apfId string) error {
        if !ps.serviceRegister.IsPublishingFunctionRegistered(apfId) {