11#include <boost/algorithm/string.hpp>
19template <
typename ElementPtrType>
21 redact(ElementPtrType
const& element, list<string> json_path,
22 string obscure,
unsigned level) {
30 string const next_key(json_path.empty() ?
string() : json_path.front());
34 if (next_key ==
"*" || next_key ==
"[]") {
36 if (next_key ==
"[]") {
38 json_path.pop_front();
42 for (
ElementPtr const& child : element->listValue()) {
43 result->add(redact(child, json_path, obscure, level - 1));
50 if (next_key ==
"*" || json_path.empty()) {
53 for (
auto const& kv : element->mapValue()) {
54 std::string
const& key(kv.first);
57 if (boost::algorithm::ends_with(key,
"password") ||
58 boost::algorithm::ends_with(key,
"secret")) {
61 }
else if (key ==
"user-context") {
63 result->set(key, value);
65 if (json_path.empty()) {
68 result->set(key, value);
71 result->set(key, redact(value, json_path, obscure,
81 json_path.pop_front();
83 redact(child, json_path, obscure, level - 1));
99 string obscure,
unsigned max_nesting_depth) {
100 return (redact(element, json_path, obscure, max_nesting_depth));
static ElementPtr create(const Position &pos=ZERO_POSITION())
Create a NullElement.
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
ElementPtr copy(ConstElementPtr from, unsigned level)
Copy the data up to a nesting level.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
ConstElementPtr redactConfig(ConstElementPtr const &element, list< string > const &json_path, string obscure, unsigned max_nesting_depth)
Redact a configuration.
Defines the logger used by the top-level component of kea-lfc.