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
29 func (ri RegistrationInformation) Validate() error {
30 if len(strings.TrimSpace(ri.ApiProvPubKey)) == 0 {
31 return errors.New("RegistrationInformation missing required apiProvPubKey")
36 func (fd APIProviderFunctionDetails) Validate() error {
37 if len(strings.TrimSpace(string(fd.ApiProvFuncRole))) == 0 {
38 return errors.New("APIProviderFunctionDetails missing required apiProvFuncRole")
40 switch role := fd.ApiProvFuncRole; role {
41 case ApiProviderFuncRoleAEF:
42 case ApiProviderFuncRoleAPF:
43 case ApiProviderFuncRoleAMF:
45 return errors.New("APIProviderFunctionDetails has invalid apiProvFuncRole")
48 return fd.RegInfo.Validate()
51 func (pd APIProviderEnrolmentDetails) Validate() error {
52 if len(strings.TrimSpace(pd.RegSec)) == 0 {
53 return errors.New("APIProviderEnrolmentDetails missing required regSec")
55 if pd.ApiProvFuncs != nil {
56 return pd.validateFunctions()
61 func (pd APIProviderEnrolmentDetails) validateFunctions() error {
62 for _, function := range *pd.ApiProvFuncs {
63 err := function.Validate()
65 return fmt.Errorf("apiProvFuncs contains invalid function: %s", err)
71 func (pd APIProviderEnrolmentDetails) ValidateAlreadyRegistered(otherProvider APIProviderEnrolmentDetails) error {
72 if pd.RegSec == otherProvider.RegSec {
73 return errors.New("provider with identical regSec already registered")