2 // ========================LICENSE_START=================================
5 // Copyright (C) 2023: 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 providermanagementapi
27 "github.com/google/uuid"
30 var uuidFunc = getUUID
32 func (ed *APIProviderEnrolmentDetails) UpdateFuncs(registeredProvider APIProviderEnrolmentDetails) error {
33 for pos, function := range *ed.ApiProvFuncs {
34 if function.ApiProvFuncId == nil {
35 (*ed.ApiProvFuncs)[pos].ApiProvFuncId = getFuncId(function.ApiProvFuncRole, function.ApiProvFuncInfo)
37 if !registeredProvider.IsFunctionRegistered(*function.ApiProvFuncId) {
38 return fmt.Errorf("function with ID %s is not registered for the provider", *function.ApiProvFuncId)
45 func (ed *APIProviderEnrolmentDetails) PrepareNewProvider() {
46 ed.ApiProvDomId = ed.getDomainId()
48 ed.registerFunctions()
52 func (ed *APIProviderEnrolmentDetails) getDomainId() *string {
54 if ed.ApiProvDomInfo != nil {
55 idAsString = strings.ReplaceAll(*ed.ApiProvDomInfo, " ", "_")
57 idAsString = uuidFunc()
59 newId := "domain_id_" + idAsString
63 func (ed *APIProviderEnrolmentDetails) registerFunctions() {
64 if ed.ApiProvFuncs == nil {
67 for i, provFunc := range *ed.ApiProvFuncs {
68 (*ed.ApiProvFuncs)[i].ApiProvFuncId = getFuncId(provFunc.ApiProvFuncRole, provFunc.ApiProvFuncInfo)
72 func getFuncId(role ApiProviderFuncRole, funcInfo *string) *string {
75 case ApiProviderFuncRoleAPF:
77 case ApiProviderFuncRoleAMF:
79 case ApiProviderFuncRoleAEF:
84 id = strings.ReplaceAll(*funcInfo, " ", "_")
88 idAsString := idPrefix + id
92 func getUUID() string {
93 return uuid.NewString()