mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 04:28:20 +00:00
Expand Supervisor to support loading additional scripts before user scripts
In supervised nodes, the Supervisor's NodeConfig$scripts vector adds scripts to the end of the user-provided scripts (options.scripts_to_load), so they load _after_ any user-provided ones. This can cause confusing redef pitfalls when users expect their customizations to run last, as they normally do. This adds two members in Supervisor::NodeConfig, `addl_base_scripts` and `addl_user_scripts`, to store scripts to load before and after the user scripts, respectively. The latter serves the same purpose as the old `scripts` member, which is still there but deprecated (in scriptland only). It functions as before, after any scripts added via `addl_user_scripts`.
This commit is contained in:
parent
61c001a57e
commit
c7860e3238
5 changed files with 107 additions and 12 deletions
|
@ -1256,6 +1256,22 @@ Supervisor::NodeConfig Supervisor::NodeConfig::FromRecord(const RecordVal* node)
|
|||
if ( bare_mode_val )
|
||||
rval.bare_mode = bare_mode_val->AsBool();
|
||||
|
||||
auto addl_base_scripts_val = node->GetField("addl_base_scripts")->AsVectorVal();
|
||||
|
||||
for ( auto i = 0u; i < addl_base_scripts_val->Size(); ++i )
|
||||
{
|
||||
auto script = addl_base_scripts_val->StringValAt(i)->ToStdString();
|
||||
rval.addl_base_scripts.emplace_back(std::move(script));
|
||||
}
|
||||
|
||||
auto addl_user_scripts_val = node->GetField("addl_user_scripts")->AsVectorVal();
|
||||
|
||||
for ( auto i = 0u; i < addl_user_scripts_val->Size(); ++i )
|
||||
{
|
||||
auto script = addl_user_scripts_val->StringValAt(i)->ToStdString();
|
||||
rval.addl_user_scripts.emplace_back(std::move(script));
|
||||
}
|
||||
|
||||
auto scripts_val = node->GetField("scripts")->AsVectorVal();
|
||||
|
||||
for ( auto i = 0u; i < scripts_val->Size(); ++i )
|
||||
|
@ -1332,6 +1348,16 @@ Supervisor::NodeConfig Supervisor::NodeConfig::FromJSON(std::string_view json)
|
|||
if ( auto it = j.FindMember("bare_mode"); it != j.MemberEnd() )
|
||||
rval.bare_mode = it->value.GetBool();
|
||||
|
||||
auto& addl_base_scripts = j["addl_base_scripts"];
|
||||
|
||||
for ( auto it = addl_base_scripts.Begin(); it != addl_base_scripts.End(); ++it )
|
||||
rval.addl_base_scripts.emplace_back(it->GetString());
|
||||
|
||||
auto& addl_user_scripts = j["addl_user_scripts"];
|
||||
|
||||
for ( auto it = addl_user_scripts.Begin(); it != addl_user_scripts.End(); ++it )
|
||||
rval.addl_user_scripts.emplace_back(it->GetString());
|
||||
|
||||
auto& scripts = j["scripts"];
|
||||
|
||||
for ( auto it = scripts.Begin(); it != scripts.End(); ++it )
|
||||
|
@ -1396,6 +1422,22 @@ RecordValPtr Supervisor::NodeConfig::ToRecord() const
|
|||
if ( bare_mode )
|
||||
rval->AssignField("bare_mode", *bare_mode);
|
||||
|
||||
auto abs_t = rt->GetFieldType<VectorType>("addl_base_scripts");
|
||||
auto addl_base_scripts_val = make_intrusive<VectorVal>(std::move(abs_t));
|
||||
|
||||
for ( const auto& s : addl_base_scripts )
|
||||
addl_base_scripts_val->Assign(addl_base_scripts_val->Size(), make_intrusive<StringVal>(s));
|
||||
|
||||
rval->AssignField("addl_base_scripts", std::move(addl_base_scripts_val));
|
||||
|
||||
auto aus_t = rt->GetFieldType<VectorType>("addl_user_scripts");
|
||||
auto addl_user_scripts_val = make_intrusive<VectorVal>(std::move(aus_t));
|
||||
|
||||
for ( const auto& s : addl_user_scripts )
|
||||
addl_user_scripts_val->Assign(addl_user_scripts_val->Size(), make_intrusive<StringVal>(s));
|
||||
|
||||
rval->AssignField("addl_user_scripts", std::move(addl_user_scripts_val));
|
||||
|
||||
auto st = rt->GetFieldType<VectorType>("scripts");
|
||||
auto scripts_val = make_intrusive<VectorVal>(std::move(st));
|
||||
|
||||
|
@ -1601,8 +1643,11 @@ void SupervisedNode::Init(Options* options) const
|
|||
if ( config.interface )
|
||||
options->interface = *config.interface;
|
||||
|
||||
for ( const auto& s : config.scripts )
|
||||
options->scripts_to_load.emplace_back(s);
|
||||
auto& stl = options->scripts_to_load;
|
||||
|
||||
stl.insert(stl.begin(), config.addl_base_scripts.begin(), config.addl_base_scripts.end());
|
||||
stl.insert(stl.end(), config.addl_user_scripts.begin(), config.addl_user_scripts.end());
|
||||
stl.insert(stl.end(), config.scripts.begin(), config.scripts.end());
|
||||
}
|
||||
|
||||
RecordValPtr Supervisor::Status(std::string_view node_name)
|
||||
|
|
|
@ -198,9 +198,20 @@ public:
|
|||
*/
|
||||
std::optional<bool> bare_mode;
|
||||
/**
|
||||
* Additional script filename/paths that the node should load.
|
||||
* Additional script filenames/paths that the node should load
|
||||
* after the base scripts, and prior to any user-specified ones.
|
||||
*/
|
||||
std::vector<std::string> scripts;
|
||||
std::vector<std::string> addl_base_scripts;
|
||||
/**
|
||||
* Additional script filename/paths that the node should load
|
||||
* after any user-specified scripts.
|
||||
*/
|
||||
std::vector<std::string> addl_user_scripts;
|
||||
/**
|
||||
* The former name for addl_user_scripts, now deprecated.
|
||||
*/
|
||||
std::vector<std::string> scripts
|
||||
[[deprecated("Remove in v6.1. Use NodeConfig::addl_user_scripts.")]];
|
||||
/**
|
||||
* Environment variables and values to define in the node.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue