pub(crate) fn validate(
    property_spec: &HashMap<PropertyName, PropertySpec>,
    config_spec: &ProductConfigSpecProperties,
    merged_properties: &HashMap<String, String>,
    product_version: &Version,
    role: Option<&str>,
    property_name: &PropertyName,
    property_value: &str,
) -> PropertyValidationResult {
    // a missing / wrong property stops us from doing any other validation
    let property = match property_spec.get(&property_name) {
        None => {
            return PropertyValidationResult::Error(Error::PropertyNotFound {
                property_name: property_name.clone(),
            });
        }
        Some(opt) => opt,
    };

    let check_version = check_version_supported_or_deprecated(
        &property_name,
        product_version,
        &property.as_of_version[..],
        &property.deprecated_since,
    );

    if check_version.is_err() {
        return PropertyValidationResult::Error(check_version.err().unwrap());
    }

    // for an empty value (""), ignore checks for the value (check_datatype, check_allowed_values..)
    if !property_value.is_empty() {
        let check_datatype = check_datatype(
            &config_spec.units,
            &property_name,
            property_value,
            &property.datatype,
        );
        if check_datatype.is_err() {
            return PropertyValidationResult::Error(check_datatype.err().unwrap());
        }

        let check_allowed_values =
            check_allowed_values(&property_name, property_value, &property.allowed_values);
        if check_allowed_values.is_err() {
            return PropertyValidationResult::Error(check_allowed_values.err().unwrap());
        }
    }

    let check_dependencies = check_dependencies(property_name, property, &merged_properties);
    if check_dependencies.is_err() {
        match check_dependencies.err() {
            None => {}
            Some(err) => {
                return match err {
                    Error::PropertyDependencyUserValueNotRequired { .. } => {
                        PropertyValidationResult::Warn(property_value.to_string(), err)
                    }
                    _ => PropertyValidationResult::Error(err),
                }
            }
        }
    }

    let check_role = check_role(property_name, &property.roles, role);
    if check_role.is_err() {
        return PropertyValidationResult::Warn(
            property_value.to_string(),
            check_role.err().unwrap(),
        );
    }

    // was provided by recommended value?
    if Ok(true)
        == check_property_value_used(
            property_name,
            property_value,
            &property.recommended_values,
            &product_version,
        )
    {
        return PropertyValidationResult::RecommendedDefault(property_value.to_string());
    }

    // was provided by default value?
    if Ok(true)
        == check_property_value_used(
            property_name,
            property_value,
            &property.default_values,
            &product_version,
        )
    {
        return PropertyValidationResult::Default(property_value.to_string());
    }

    PropertyValidationResult::Valid(property_value.to_string())
}
/// Returns the provided property_value if no validation errors appear
///
/// # Arguments
/// * `property_spec` - map with PropertyName as key and the corresponding PropertySpec as value
/// * `config_spec` - config spec that contains customizable data like e.g. unit and regex
/// * `merged_properties` - merged user and property spec (matching role, kind etc.)
/// * `product_version` - version of the currently active product version
/// * `role` - the user role to validate against
/// * `property_name` - name of the property
/// * `property_value` - property value to be validated
///
Returns the provided property_value if no validation errors appear
Returns the provided property_value if no validation errors appear
pub(crate) fn validate(
    property_spec: &HashMap<PropertyName, PropertySpec>,
    config_spec: &ProductConfigSpecProperties,
    merged_properties: &HashMap<String, String>,
    product_version: &Version,
    role: Option<&str>,
    property_name: &PropertyName,
    property_value: &str,
) -> PropertyValidationResult {
    // a missing / wrong property stops us from doing any other validation
    let property = match property_spec.get(&property_name) {
        None => {
            return PropertyValidationResult::Error(Error::PropertyNotFound {
                property_name: property_name.clone(),
            });
        }
        Some(opt) => opt,
    };
    let check_version = check_version_supported_or_deprecated(
        &property_name,
        product_version,
        &property.as_of_version[..],
        &property.deprecated_since,
    );
    if check_version.is_err() {
        return PropertyValidationResult::Error(check_version.err().unwrap());
    }
    // for an empty value (""), ignore checks for the value (check_datatype, check_allowed_values..)
    if !property_value.is_empty() {
        let check_datatype = check_datatype(
            &config_spec.units,
            &property_name,
            property_value,
            &property.datatype,
        );
        if check_datatype.is_err() {
            return PropertyValidationResult::Error(check_datatype.err().unwrap());
        }
        let check_allowed_values =
            check_allowed_values(&property_name, property_value, &property.allowed_values);
        if check_allowed_values.is_err() {
            return PropertyValidationResult::Error(check_allowed_values.err().unwrap());
        }
    }
    let check_dependencies = check_dependencies(property_name, property, &merged_properties);
    if check_dependencies.is_err() {
        match check_dependencies.err() {
            None => {}
            Some(err) => {
                return match err {
                    Error::PropertyDependencyUserValueNotRequired { .. } => {
                        PropertyValidationResult::Warn(property_value.to_string(), err)
                    }
                    _ => PropertyValidationResult::Error(err),
                }
            }
        }
    }
    let check_role = check_role(property_name, &property.roles, role);
    if check_role.is_err() {
        return PropertyValidationResult::Warn(
            property_value.to_string(),
            check_role.err().unwrap(),
        );
    }
    // was provided by recommended value?
    if Ok(true)
        == check_property_value_used(
            property_name,
            property_value,
            &property.recommended_values,
            &product_version,
        )
    {
        return PropertyValidationResult::RecommendedDefault(property_value.to_string());
    }
    // was provided by default value?
    if Ok(true)
        == check_property_value_used(
            property_name,
            property_value,
            &property.default_values,
            &product_version,
        )
    {
        return PropertyValidationResult::Default(property_value.to_string());
    }
    PropertyValidationResult::Valid(property_value.to_string())
}
pub ( crate ) fn validate ( property_spec : & HashMap < PropertyName , PropertySpec > , config_spec : & ProductConfigSpecProperties , merged_properties : & HashMap < String , String > , product_version : & Version , role : Option < & str > , property_name : & PropertyName , property_value : & str , ) -> PropertyValidationResult { // a missing / wrong property stops us from doing any other validation let property = match property_spec . get ( & property_name ) { None => { return PropertyValidationResult :: Error ( Error :: PropertyNotFound { property_name : property_name . clone ( ) , } ) ; } Some ( opt ) => opt , } ; let check_version = check_version_supported_or_deprecated ( & property_name , product_version , & property . as_of_version [ .. ] , & property . deprecated_since , ) ; if check_version . is_err ( ) { return PropertyValidationResult :: Error ( check_version . err ( ) . unwrap ( ) ) ; } // for an empty value (""), ignore checks for the value (check_datatype, check_allowed_values..) if ! property_value . is_empty ( ) { let check_datatype = check_datatype ( & config_spec . units , & property_name , property_value , & property . datatype , ) ; if check_datatype . is_err ( ) { return PropertyValidationResult :: Error ( check_datatype . err ( ) . unwrap ( ) ) ; } let check_allowed_values = check_allowed_values ( & property_name , property_value , & property . allowed_values ) ; if check_allowed_values . is_err ( ) { return PropertyValidationResult :: Error ( check_allowed_values . err ( ) . unwrap ( ) ) ; } } let check_dependencies = check_dependencies ( property_name , property , & merged_properties ) ; if check_dependencies . is_err ( ) { match check_dependencies . err ( ) { None => { } Some ( err ) => { return match err { Error :: PropertyDependencyUserValueNotRequired { .. } => { PropertyValidationResult :: Warn ( property_value . to_string ( ) , err ) } _ => PropertyValidationResult :: Error ( err ) , } } } } let check_role = check_role ( property_name , & property . roles , role ) ; if check_role . is_err ( ) { return PropertyValidationResult :: Warn ( property_value . to_string ( ) , check_role . err ( ) . unwrap ( ) , ) ; } // was provided by recommended value? if Ok ( true ) == check_property_value_used ( property_name , property_value , & property . recommended_values , & product_version , ) { return PropertyValidationResult :: RecommendedDefault ( property_value . to_string ( ) ) ; } // was provided by default value? if Ok ( true ) == check_property_value_used ( property_name , property_value , & property . default_values , & product_version , ) { return PropertyValidationResult :: Default ( property_value . to_string ( ) ) ; } PropertyValidationResult :: Valid ( property_value . to_string ( ) ) }
Returns the provided property_value if no validation errors appear
Returns the provided property_value if no validation errors appear
property_spec
&HashMap<PropertyName, PropertySpec>
config_spec
&ProductConfigSpecProperties
merged_properties
&HashMap<String, String>
product_version
&Version
role
Option<&str>
property_name
&PropertyName
property_value
&str