X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=capifcore%2Finternal%2Fdiscoverservice%2Fdiscoverservice.go;h=797eaa7cf2e4f126135b918694118721e40bf9e0;hb=d0199885b0bc379f22dbb7012545f0049f979bac;hp=0c0f431cc096461fe9cff69c8250148ce67eb076;hpb=c9e08b2a2f647f9f870040570c5e71305f0fb5d2;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/internal/discoverservice/discoverservice.go b/capifcore/internal/discoverservice/discoverservice.go index 0c0f431..797eaa7 100644 --- a/capifcore/internal/discoverservice/discoverservice.go +++ b/capifcore/internal/discoverservice/discoverservice.go @@ -23,9 +23,9 @@ package discoverservice import ( "net/http" + "oransc.org/nonrtric/capifcore/internal/common29122" discoverapi "oransc.org/nonrtric/capifcore/internal/discoverserviceapi" - - "oransc.org/nonrtric/capifcore/internal/publishservice" + "oransc.org/nonrtric/capifcore/internal/invokermanagement" "github.com/labstack/echo/v4" @@ -33,20 +33,23 @@ import ( ) type DiscoverService struct { - apiRegister publishservice.APIRegister + invokerRegister invokermanagement.InvokerRegister } -func NewDiscoverService(apiRegister publishservice.APIRegister) *DiscoverService { +func NewDiscoverService(invokerRegister invokermanagement.InvokerRegister) *DiscoverService { return &DiscoverService{ - apiRegister: apiRegister, + invokerRegister: invokerRegister, } } func (ds *DiscoverService) GetAllServiceAPIs(ctx echo.Context, params discoverapi.GetAllServiceAPIsParams) error { - allApis := *ds.apiRegister.GetAPIs() + allApis := ds.invokerRegister.GetInvokerApiList(params.ApiInvokerId) + if allApis == nil { + return sendCoreError(ctx, http.StatusNotFound, "Invoker not registered") + } filteredApis := []publishapi.ServiceAPIDescription{} gatewayDomain := "r1-expo-func-aef" - for _, api := range allApis { + for _, api := range *allApis { if !matchesFilter(api, params) { continue } @@ -73,18 +76,92 @@ func matchesFilter(api publishapi.ServiceAPIDescription, filter discoverapi.GetA if filter.ApiName != nil && *filter.ApiName != api.ApiName { return false } + if filter.ApiCat != nil && (api.ServiceAPICategory == nil || *filter.ApiCat != *api.ServiceAPICategory) { + return false + } profiles := *api.AefProfiles - match := false for _, profile := range profiles { - if filter.ApiVersion != nil { - for _, version := range profile.Versions { - if *filter.ApiVersion == version.ApiVersion { - match = true - } + if checkAefId(filter, profile) && checkVersionAndCommType(profile, filter) && checkProtocol(filter, profile) && checkDataFormat(filter, profile) { + return true + } + } + return false +} + +func checkAefId(filter discoverapi.GetAllServiceAPIsParams, profile publishapi.AefProfile) bool { + if filter.AefId != nil { + return *filter.AefId == profile.AefId + } + return true +} + +func checkVersionAndCommType(profile publishapi.AefProfile, filter discoverapi.GetAllServiceAPIsParams) bool { + match := false + if filter.ApiVersion != nil { + for _, version := range profile.Versions { + match = checkVersion(version, filter.ApiVersion, filter.CommType) + if match { + break } + } + } else if filter.CommType != nil { + for _, version := range profile.Versions { + match = checkCommType(version.Resources, filter.CommType) + } + } else { + match = true + } + return match +} + +func checkProtocol(filter discoverapi.GetAllServiceAPIsParams, profile publishapi.AefProfile) bool { + if filter.Protocol != nil { + return profile.Protocol != nil && *filter.Protocol == *profile.Protocol + } + return true +} + +func checkDataFormat(filter discoverapi.GetAllServiceAPIsParams, profile publishapi.AefProfile) bool { + if filter.DataFormat != nil { + return profile.DataFormat != nil && *filter.DataFormat == *profile.DataFormat + } + return true +} + +func checkVersion(version publishapi.Version, wantedVersion *string, commType *publishapi.CommunicationType) bool { + match := false + if *wantedVersion == version.ApiVersion { + if commType != nil { + match = checkCommType(version.Resources, commType) } else { match = true } } return match } + +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 + } + } + } else { + match = true + } + return match +} + +// This function wraps sending of an error in the Error format, and +// handling the failure to marshal that. +func sendCoreError(ctx echo.Context, code int, message string) error { + pd := common29122.ProblemDetails{ + Cause: &message, + Status: &code, + } + err := ctx.JSON(code, pd) + return err +}