X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Finternal%2Fdiscoverservice%2Fdiscoverservice.go;fp=capifcore%2Finternal%2Fdiscoverservice%2Fdiscoverservice.go;h=0c0f431cc096461fe9cff69c8250148ce67eb076;hb=c9e08b2a2f647f9f870040570c5e71305f0fb5d2;hp=0000000000000000000000000000000000000000;hpb=8fcfa4ecde6d95ead33c34b0e7efc4933ad44444;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/internal/discoverservice/discoverservice.go b/capifcore/internal/discoverservice/discoverservice.go new file mode 100644 index 0000000..0c0f431 --- /dev/null +++ b/capifcore/internal/discoverservice/discoverservice.go @@ -0,0 +1,90 @@ +// - +// ========================LICENSE_START================================= +// O-RAN-SC +// %% +// Copyright (C) 2022: Nordix Foundation +// %% +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ========================LICENSE_END=================================== +// + +package discoverservice + +import ( + "net/http" + + discoverapi "oransc.org/nonrtric/capifcore/internal/discoverserviceapi" + + "oransc.org/nonrtric/capifcore/internal/publishservice" + + "github.com/labstack/echo/v4" + + publishapi "oransc.org/nonrtric/capifcore/internal/publishserviceapi" +) + +type DiscoverService struct { + apiRegister publishservice.APIRegister +} + +func NewDiscoverService(apiRegister publishservice.APIRegister) *DiscoverService { + return &DiscoverService{ + apiRegister: apiRegister, + } +} + +func (ds *DiscoverService) GetAllServiceAPIs(ctx echo.Context, params discoverapi.GetAllServiceAPIsParams) error { + allApis := *ds.apiRegister.GetAPIs() + filteredApis := []publishapi.ServiceAPIDescription{} + gatewayDomain := "r1-expo-func-aef" + for _, api := range allApis { + if !matchesFilter(api, params) { + continue + } + profiles := *api.AefProfiles + for i, profile := range profiles { + profile.DomainName = &gatewayDomain // Hardcoded for now. Should be provided through some other mechanism. + profiles[i] = profile + } + filteredApis = append(filteredApis, api) + } + discoveredApis := discoverapi.DiscoveredAPIs{ + ServiceAPIDescriptions: &filteredApis, + } + err := ctx.JSON(http.StatusOK, discoveredApis) + if err != nil { + // Something really bad happened, tell Echo that our handler failed + return err + } + + return nil +} + +func matchesFilter(api publishapi.ServiceAPIDescription, filter discoverapi.GetAllServiceAPIsParams) bool { + if filter.ApiName != nil && *filter.ApiName != api.ApiName { + 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 + } + } + } else { + match = true + } + } + return match +}