2 // ========================LICENSE_START=================================
5 // Copyright (C) 2022: Nordix Foundation
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // ========================LICENSE_END===================================
21 package discoverservice
26 discoverapi "oransc.org/nonrtric/capifcore/internal/discoverserviceapi"
28 "oransc.org/nonrtric/capifcore/internal/publishservice"
30 "github.com/labstack/echo/v4"
32 publishapi "oransc.org/nonrtric/capifcore/internal/publishserviceapi"
35 type DiscoverService struct {
36 apiRegister publishservice.APIRegister
39 func NewDiscoverService(apiRegister publishservice.APIRegister) *DiscoverService {
40 return &DiscoverService{
41 apiRegister: apiRegister,
45 func (ds *DiscoverService) GetAllServiceAPIs(ctx echo.Context, params discoverapi.GetAllServiceAPIsParams) error {
46 allApis := *ds.apiRegister.GetAPIs()
47 filteredApis := []publishapi.ServiceAPIDescription{}
48 gatewayDomain := "r1-expo-func-aef"
49 for _, api := range allApis {
50 if !matchesFilter(api, params) {
53 profiles := *api.AefProfiles
54 for i, profile := range profiles {
55 profile.DomainName = &gatewayDomain // Hardcoded for now. Should be provided through some other mechanism.
58 filteredApis = append(filteredApis, api)
60 discoveredApis := discoverapi.DiscoveredAPIs{
61 ServiceAPIDescriptions: &filteredApis,
63 err := ctx.JSON(http.StatusOK, discoveredApis)
65 // Something really bad happened, tell Echo that our handler failed
72 func matchesFilter(api publishapi.ServiceAPIDescription, filter discoverapi.GetAllServiceAPIsParams) bool {
73 if filter.ApiName != nil && *filter.ApiName != api.ApiName {
76 profiles := *api.AefProfiles
78 for _, profile := range profiles {
79 if filter.ApiVersion != nil {
80 for _, version := range profile.Versions {
81 if *filter.ApiVersion == version.ApiVersion {