NONRTRIC-946: Make GET for GetApfIdServiceApis stateless
[nonrtric/plt/sme.git] / capifcore / internal / invokermanagementapi / typevalidation.go
index b12ddfb..10db338 100644 (file)
@@ -22,6 +22,8 @@ package invokermanagementapi
 
 import (
        "errors"
+       "fmt"
+       "net/url"
 )
 
 func (ied *APIInvokerEnrolmentDetails) Validate() error {
@@ -29,9 +31,20 @@ func (ied *APIInvokerEnrolmentDetails) Validate() error {
                return errors.New("APIInvokerEnrolmentDetails missing required NotificationDestination")
        }
 
+       if _, err := url.ParseRequestURI(string(ied.NotificationDestination)); err != nil {
+               return fmt.Errorf("APIInvokerEnrolmentDetails has invalid NotificationDestination, err=%s", err)
+       }
+
        if ied.OnboardingInformation.ApiInvokerPublicKey == "" {
                return errors.New("APIInvokerEnrolmentDetails missing required OnboardingInformation.ApiInvokerPublicKey")
        }
 
        return nil
 }
+
+func (ied *APIInvokerEnrolmentDetails) ValidateAlreadyOnboarded(otherInvoker APIInvokerEnrolmentDetails) error {
+       if ied.OnboardingInformation.ApiInvokerPublicKey == otherInvoker.OnboardingInformation.ApiInvokerPublicKey {
+               return errors.New("invoker with identical public key already onboarded")
+       }
+       return nil
+}