MCPcopy
hub / github.com/apache/casbin / loadModelFromConfig

Method loadModelFromConfig

model/model.go:187–207  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
187func (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
209func (model Model) hasSection(sec string) bool {
210 section := model[sec]

Callers 4

LoadModelMethod · 0.95
LoadModelFromTextMethod · 0.95
TestLoadModelFromConfigFunction · 0.95
TestHasSectionFunction · 0.95

Calls 3

hasSectionMethod · 0.95
ValidateConstraintsMethod · 0.95
loadSectionFunction · 0.85

Tested by 2

TestLoadModelFromConfigFunction · 0.76
TestHasSectionFunction · 0.76