aboutsummaryrefslogtreecommitdiffstats
path: root/src/ncm/pkg/module/module_definitions.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/ncm/pkg/module/module_definitions.go')
-rw-r--r--src/ncm/pkg/module/module_definitions.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/ncm/pkg/module/module_definitions.go b/src/ncm/pkg/module/module_definitions.go
index 1e839014..729a9dbd 100644
--- a/src/ncm/pkg/module/module_definitions.go
+++ b/src/ncm/pkg/module/module_definitions.go
@@ -32,6 +32,9 @@ const CNI_TYPE_OVN4NFV string = "ovn4nfv"
var CNI_TYPES = [...]string{CNI_TYPE_OVN4NFV}
// It implements the interface for managing the ClusterProviders
+const MAX_DESCRIPTION_LEN int = 1024
+const MAX_USERDATA_LEN int = 4096
+
type Metadata struct {
Name string `json:"name"`
Description string `json:"description"`
@@ -65,6 +68,31 @@ type Vlan struct {
NodeLabelList []string `json:"nodeLabelList"`
}
+// Check for valid format Metadata
+func IsValidMetadata(metadata Metadata) error {
+ errs := validation.IsValidName(metadata.Name)
+ if len(errs) > 0 {
+ return pkgerrors.Errorf("Invalid Metadata name=[%v], errors: %v", metadata.Name, errs)
+ }
+
+ errs = validation.IsValidString(metadata.Description, 0, MAX_DESCRIPTION_LEN, validation.VALID_ANY_STR)
+ if len(errs) > 0 {
+ return pkgerrors.Errorf("Invalid Metadata description=[%v], errors: %v", metadata.Description, errs)
+ }
+
+ errs = validation.IsValidString(metadata.UserData1, 0, MAX_DESCRIPTION_LEN, validation.VALID_ANY_STR)
+ if len(errs) > 0 {
+ return pkgerrors.Errorf("Invalid Metadata description=[%v], errors: %v", metadata.UserData1, errs)
+ }
+
+ errs = validation.IsValidString(metadata.UserData2, 0, MAX_DESCRIPTION_LEN, validation.VALID_ANY_STR)
+ if len(errs) > 0 {
+ return pkgerrors.Errorf("Invalid Metadata description=[%v], errors: %v", metadata.UserData2, errs)
+ }
+
+ return nil
+}
+
// Check for valid format of an Ipv4Subnet
func ValidateSubnet(sub Ipv4Subnet) error {
// verify subnet is in valid cidr format