| 539 | } |
| 540 | |
| 541 | swoc::Errata |
| 542 | IpAllow::YAMLBuildTable(std::string const &content) |
| 543 | { |
| 544 | YAML::Node root{YAML::Load(content)}; |
| 545 | if (!root.IsMap()) { |
| 546 | return swoc::Errata("{} - top level object was not a map. All IP Addresses will be blocked", this); |
| 547 | } |
| 548 | |
| 549 | // IP categories are optional. Load them if specified. Note that the rules, |
| 550 | // if they use categories, depend upon the categories being defined. So the |
| 551 | // categories have to be processed first before the rules are. |
| 552 | YAML::Node categories{root[YAML_TAG_CATEGORY_ROOT.data()]}; |
| 553 | if (auto errata = this->YAMLLoadCategoryRoot(categories); !errata.is_ok()) { |
| 554 | return errata; |
| 555 | } |
| 556 | |
| 557 | // Now load the IPAllow rules. |
| 558 | YAML::Node rules{root[YAML_TAG_ROOT.data()]}; |
| 559 | if (!rules) { |
| 560 | return swoc::Errata("{} - root tag '{}' not found. All IP Addresses will be blocked", this, YAML_TAG_ROOT); |
| 561 | } else if (rules.IsSequence()) { |
| 562 | for (auto const &entry : rules) { |
| 563 | if (auto errata = this->YAMLLoadEntry(entry); !errata.is_ok()) { |
| 564 | return errata; |
| 565 | } |
| 566 | } |
| 567 | } else if (rules.IsMap()) { |
| 568 | return this->YAMLLoadEntry(rules); // singleton, just load it. |
| 569 | } else { |
| 570 | return swoc::Errata("{} - root tag '{}' is not an map or sequence. All IP Addresses will be blocked", this, YAML_TAG_ROOT); |
| 571 | } |
| 572 | return {}; |
| 573 | } |
| 574 | |
| 575 | swoc::Errata |
| 576 | IpAllow::BuildCategories() |
no test coverage detected