MCPcopy Create free account
hub / github.com/apache/trafficserver / YAMLLoadEntry

Method YAMLLoadEntry

src/proxy/IPAllow.cc:414–539  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

412}
413
414swoc::Errata
415IpAllow::YAMLLoadEntry(const YAML::Node &entry)
416{
417 AclOp op = ACL_OP_DENY; // "shut up", I explained to the compiler.
418 YAML::Node node;
419 auto record = _arena.make<Record>();
420 IpMap *map = nullptr; // src or dst map.
421
422 if (!entry.IsMap()) {
423 return swoc::Errata(ERRATA_ERROR, "{} {} - ACL items must be maps.", this, entry.Mark());
424 }
425
426 if (YAML::Node apply_node{entry[YAML_TAG_APPLY]}; apply_node) {
427 if (apply_node.IsScalar()) {
428 swoc::TextView value{apply_node.Scalar()};
429 if (0 == strcasecmp(value, YAML_VALUE_APPLY_IN)) {
430 map = &_src_map;
431 } else if (0 == strcasecmp(value, YAML_VALUE_APPLY_OUT)) {
432 map = &_dst_map;
433 } else {
434 return swoc::Errata(ERRATA_ERROR, R"("{}" value at {} must be "{}" or "{}")", YAML_TAG_APPLY, entry.Mark(),
435 YAML_VALUE_APPLY_IN, YAML_VALUE_APPLY_OUT);
436 }
437 } else {
438 return swoc::Errata(ERRATA_ERROR, R"("{}" value at {} must be a scalar, "{}" or "{}")", YAML_TAG_APPLY, entry.Mark(),
439 YAML_VALUE_APPLY_IN, YAML_VALUE_APPLY_OUT);
440 }
441 } else {
442 return swoc::Errata(ERRATA_ERROR, R"(Object at {} must have a "{}" key.)", entry.Mark(), YAML_TAG_APPLY);
443 }
444
445 if (node = entry[YAML_TAG_ACTION]; node) {
446 if (node.IsScalar()) {
447 swoc::TextView value(node.Scalar());
448 if (!this->_is_legacy_action_policy &&
449 (value == YAML_VALUE_ACTION_ALLOW_OLD_NAME || value == YAML_VALUE_ACTION_DENY_OLD_NAME)) {
450 return swoc::Errata(
451 ERRATA_FATAL, R"(Legacy action name of "{}" detected at {}. Use "set_allow" or "set_deny" instead of "allow" or "deny".)",
452 value, entry.Mark());
453 }
454 if (value == YAML_VALUE_ACTION_ALLOW || value == YAML_VALUE_ACTION_ALLOW_OLD_NAME) {
455 op = ACL_OP_ALLOW;
456 } else if (value == YAML_VALUE_ACTION_DENY || value == YAML_VALUE_ACTION_DENY_OLD_NAME) {
457 op = ACL_OP_DENY;
458 } else {
459 return swoc::Errata(ERRATA_ERROR, "{} {} - item ignored, value for tag '{}' must be '{}' or '{}'", this, node.Mark(),
460 YAML_TAG_ACTION, YAML_VALUE_ACTION_ALLOW, YAML_VALUE_ACTION_DENY);
461 }
462 } else {
463 return swoc::Errata(ERRATA_ERROR, "{} {} - item ignored, value for tag '{}' must be a string", this, node.Mark(),
464 YAML_TAG_ACTION);
465 }
466 } else {
467 return swoc::Errata(ERRATA_ERROR, "{} {} - item ignored, required '{}' key not found.", this, entry.Mark(), YAML_TAG_ACTION);
468 }
469
470 if (entry[YAML_TAG_IP_ADDRS] && entry[YAML_TAG_IP_CATEGORIES]) {
471 return swoc::Errata(ERRATA_ERROR, "{} {} - '{}' and '{}' cannot both be used in the same rule.", this, entry.Mark(),

Callers 1

YAMLBuildTableMethod · 0.95

Calls 9

YAMLLoadIPAddrRangeMethod · 0.95
YAMLLoadIPCategoryMethod · 0.95
YAMLLoadMethodMethod · 0.95
ErrataClass · 0.85
strcasecmpFunction · 0.85
ScalarMethod · 0.80
MarkMethod · 0.45
is_okMethod · 0.45
noteMethod · 0.45

Tested by

no test coverage detected