loadModelFromConfig loads the model from a config interface. It loads all sections defined in sectionNameMap and validates that required sections are present. If constraint_definition section exists, it validates all constraints against the current policy. Note: Constraint validation is performed du
(cfg config.ConfigInterface)
| 185 | // Note: Constraint validation is performed during model loading, which may affect loading performance |
| 186 | // and can cause model loading to fail if constraints are violated or invalid. |
| 187 | func (model Model) loadModelFromConfig(cfg config.ConfigInterface) error { |
| 188 | for s := range sectionNameMap { |
| 189 | loadSection(model, cfg, s) |
| 190 | } |
| 191 | ms := make([]string, 0) |
| 192 | for _, rs := range requiredSections { |
| 193 | if !model.hasSection(rs) { |
| 194 | ms = append(ms, sectionNameMap[rs]) |
| 195 | } |
| 196 | } |
| 197 | if len(ms) > 0 { |
| 198 | return fmt.Errorf("missing required sections: %s", strings.Join(ms, ",")) |
| 199 | } |
| 200 | |
| 201 | // Validate constraints after model is loaded |
| 202 | if err := model.ValidateConstraints(); err != nil { |
| 203 | return err |
| 204 | } |
| 205 | |
| 206 | return nil |
| 207 | } |
| 208 | |
| 209 | func (model Model) hasSection(sec string) bool { |
| 210 | section := model[sec] |