// ========================LICENSE_START=================================
// O-RAN-SC
// %%
-// Copyright (C) 2022: Nordix Foundation
+// Copyright (C) 2022-2023: Nordix Foundation
+// Copyright (C) 2024: OpenInfra Foundation Europe
// %%
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
}
func (im *InvokerManager) prepareNewInvoker(newInvoker *invokerapi.APIInvokerEnrolmentDetails) {
- var apiList invokerapi.APIList = im.publishRegister.GetAllPublishedServices()
- newInvoker.ApiList = &apiList
+ var apiListRequestedServices invokerapi.APIList = nil
+ if newInvoker.ApiList != nil {
+ apiListRequestedServices = *newInvoker.ApiList
+ }
+ var allowedPublishedServices invokerapi.APIList = im.publishRegister.GetAllowedPublishedServices(apiListRequestedServices)
+ newInvoker.ApiList = &allowedPublishedServices
im.lock.Lock()
defer im.lock.Unlock()
newInvoker.PrepareNewInvoker()
-
im.addClientInKeycloak(newInvoker)
-
im.onboardedInvokers[*newInvoker.ApiInvokerId] = *newInvoker
}
// ========================LICENSE_START=================================
// O-RAN-SC
// %%
-// Copyright (C) 2022: Nordix Foundation
+// Copyright (C) 2022-2023: Nordix Foundation
+// Copyright (C) 2024: OpenInfra Foundation Europe
// %%
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
var client keycloak.Client
client.Secret = &wantedInvokerSecret
publishRegisterMock := publishmocks.PublishRegister{}
- publishRegisterMock.On("GetAllPublishedServices").Return(publishedServices)
+ publishRegisterMock.On("GetAllowedPublishedServices", mock.AnythingOfType("[]publishserviceapi.ServiceAPIDescription")).Return(publishedServices)
accessMgmMock := keycloackmocks.AccessManagement{}
accessMgmMock.On("AddClient", mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(nil)
assert.Equal(t, "http://example.com/onboardedInvokers/"+*resultInvoker.ApiInvokerId, result.Recorder.Header().Get(echo.HeaderLocation))
assert.True(t, invokerUnderTest.IsInvokerRegistered(wantedInvokerId))
assert.True(t, invokerUnderTest.VerifyInvokerSecret(wantedInvokerId, wantedInvokerSecret))
- publishRegisterMock.AssertCalled(t, "GetAllPublishedServices")
+
+ publishRegisterMock.AssertCalled(t, "GetAllowedPublishedServices", mock.AnythingOfType("[]publishserviceapi.ServiceAPIDescription"))
+
assert.Equal(t, invokermanagementapi.APIList(publishedServices), *resultInvoker.ApiList)
if invokerEvent, timeout := waitForEvent(eventChannel, 1*time.Second); timeout {
assert.Fail(t, "No event sent")
return r0
}
+// GetAllowedPublishedServices provides a mock function with given fields: invokerApiList
+func (_m *PublishRegister) GetAllowedPublishedServices(invokerApiList []publishserviceapi.ServiceAPIDescription) []publishserviceapi.ServiceAPIDescription {
+ ret := _m.Called(invokerApiList)
+
+ var r0 []publishserviceapi.ServiceAPIDescription
+ if rf, ok := ret.Get(0).(func([]publishserviceapi.ServiceAPIDescription) []publishserviceapi.ServiceAPIDescription); ok {
+ r0 = rf(invokerApiList)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).([]publishserviceapi.ServiceAPIDescription)
+ }
+ }
+
+ return r0
+}
+
// IsAPIPublished provides a mock function with given fields: aefId, path
func (_m *PublishRegister) IsAPIPublished(aefId string, path string) bool {
ret := _m.Called(aefId, path)
// 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 {
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) {
assert.Len(t, result, 2)
}
+func TestGetAllowedServices(t *testing.T) {
+ serviceUnderTest := NewPublishService(nil, nil, nil)
+
+ aefProfiles1 := []publishapi.AefProfile{
+ }
+ apiId1 := "apiId1"
+ aefProfiles2 := []publishapi.AefProfile{
+ }
+ apiId2 := "apiId2"
+ aefProfiles3 := []publishapi.AefProfile{
+ }
+ apiId3 := "apiId3"
+ aefProfiles4 := []publishapi.AefProfile{
+ }
+ apiId4 := "apiId4"
+
+ serviceUnderTest.publishedServices["publisher1"] = []publishapi.ServiceAPIDescription{
+ {
+ ApiId: &apiId1,
+ AefProfiles: &aefProfiles1,
+ },
+ {
+ ApiId: &apiId2,
+ AefProfiles: &aefProfiles2,
+ },
+ {
+ ApiId: &apiId3,
+ AefProfiles: &aefProfiles3,
+ },
+ {
+ ApiId: &apiId4,
+ AefProfiles: &aefProfiles4,
+ },
+ }
+
+ serviceDescription := publishapi.ServiceAPIDescription{
+ ApiId: &apiId4,
+ AefProfiles: &aefProfiles4,
+ }
+ serviceUnderTest.publishedServices["publisher2"] = []publishapi.ServiceAPIDescription{
+ serviceDescription,
+ }
+
+ allowedApiList := []publishapi.ServiceAPIDescription{
+ {
+ ApiId: &apiId2,
+ AefProfiles: &aefProfiles2,
+ },
+ {
+ ApiId: &apiId3,
+ AefProfiles: &aefProfiles3,
+ },
+ }
+
+ result := serviceUnderTest.GetAllowedPublishedServices(allowedApiList)
+ assert.Len(t, result, 2)
+}
+
func TestUpdateDescription(t *testing.T) {
apfId := "apfId"
serviceApiId := "serviceApiId"