Build returns the configured Plugin, or an error if any builder step found a fault. MustBuild panics on the same error. The Restrict + FailOpen mismatch is checked here, not in the chained setters, because the two methods may be called in either order.
()
| 151 | // The Restrict + FailOpen mismatch is checked here, not in the chained |
| 152 | // setters, because the two methods may be called in either order. |
| 153 | func (b *Builder) Build() (Plugin, error) { |
| 154 | if len(b.rules) > 0 && b.caps.FailurePolicy == FailOpen { |
| 155 | b.errs = append(b.errs, errors.New( |
| 156 | "Restrict() requires FailClosed; do not call FailOpen() after Restrict()")) |
| 157 | } |
| 158 | if len(b.errs) > 0 { |
| 159 | return nil, errors.Join(b.errs...) |
| 160 | } |
| 161 | return &builtPlugin{ |
| 162 | name: b.name, |
| 163 | version: b.version, |
| 164 | caps: b.caps, |
| 165 | actions: b.actions, |
| 166 | rules: b.rules, |
| 167 | }, nil |
| 168 | } |
| 169 | |
| 170 | // MustBuild panics if Build() would return an error. Designed for |
| 171 | // init(): |