2828#include " dnsdist-protobuf.hh"
2929#include " dnsdist-rule-chains.hh"
3030#include " dnstap.hh"
31+ #include " dolog.hh"
3132#include " remote_logger.hh"
3233#include < memory>
3334#include < optional>
@@ -267,7 +268,7 @@ void setupLuaActions(LuaContext& luaCtx)
267268 // Used for both RemoteLogAction and RemoteLogResponseAction
268269 static const std::array<std::string, 2 > s_validIpEncryptMethods = {" legacy" , " ipcrypt-pfx" };
269270
270- luaCtx.writeFunction (" RemoteLogAction" , [](std::shared_ptr<RemoteLoggerInterface> logger, std::optional<dnsdist::actions::ProtobufAlterFunction> alterFunc, std::optional<LuaAssociativeTable<std::string>> vars, std::optional<LuaAssociativeTable<std::string>> metas) {
271+ luaCtx.writeFunction (" RemoteLogAction" , [](std::shared_ptr<RemoteLoggerInterface> logger, std::optional<dnsdist::actions::ProtobufAlterFunction> alterFunc, std::optional<LuaAssociativeTable<boost::variant< std::string, bool > >> vars, std::optional<LuaAssociativeTable<std::string>> metas) {
271272 if (logger) {
272273 // avoids potentially-evaluated-expression warning with clang.
273274 RemoteLoggerInterface& remoteLoggerRef = *logger;
@@ -283,10 +284,25 @@ void setupLuaActions(LuaContext& luaCtx)
283284 if (alterFunc) {
284285 config.alterQueryFunc = std::move (*alterFunc);
285286 }
286- getOptionalValue<std::string>(vars, " serverID" , config.serverID );
287- getOptionalValue<std::string>(vars, " ipEncryptKey" , config.ipEncryptKey );
288- getOptionalValue<std::string>(vars, " ipEncryptMethod" , config.ipEncryptMethod );
289- getOptionalValue<std::string>(vars, " exportTags" , tags);
287+ if (getOptionalValue<std::string>(vars, " serverID" , config.serverID ) < 0 ) {
288+ throw std::runtime_error (" serverID in RemoteLogAction is not a string" );
289+ }
290+ if (getOptionalValue<std::string>(vars, " ipEncryptKey" , config.ipEncryptKey ) < 0 ) {
291+ throw std::runtime_error (" ipEncryptKey in RemoteLogAction is not a string" );
292+ }
293+ if (getOptionalValue<std::string>(vars, " ipEncryptMethod" , config.ipEncryptMethod ) < 0 ) {
294+ throw std::runtime_error (" ipEncryptMethod in RemoteLogAction is not a string" );
295+ }
296+ if (getOptionalValue<std::string>(vars, " exportTags" , tags) < 0 ) {
297+ throw std::runtime_error (" exportTags in RemoteLogAction is not a string" );
298+ }
299+ if (getOptionalValue<bool >(vars, " useServerID" , config.useServerID ) < 0 ) {
300+ throw std::runtime_error (" useServerID in RemoteLogAction is not a string" );
301+ }
302+
303+ if (config.useServerID && !config.serverID .empty ()) {
304+ warnlog (" useServerID and serverID set in RemoteLogAction configuration. value for serverID will not be used" );
305+ }
290306
291307 if (metas) {
292308 for (const auto & [key, value] : *metas) {
@@ -314,7 +330,7 @@ void setupLuaActions(LuaContext& luaCtx)
314330 return dnsdist::actions::getRemoteLogAction (config);
315331 });
316332
317- luaCtx.writeFunction (" RemoteLogResponseAction" , [](std::shared_ptr<RemoteLoggerInterface> logger, std::optional<dnsdist::actions::ProtobufAlterResponseFunction> alterFunc, std::optional<bool > includeCNAME, std::optional<LuaAssociativeTable<std::string>> vars, std::optional<LuaAssociativeTable<std::string>> metas, std::optional<bool > delay) {
333+ luaCtx.writeFunction (" RemoteLogResponseAction" , [](std::shared_ptr<RemoteLoggerInterface> logger, std::optional<dnsdist::actions::ProtobufAlterResponseFunction> alterFunc, std::optional<bool > includeCNAME, std::optional<LuaAssociativeTable<boost::variant< std::string, bool > >> vars, std::optional<LuaAssociativeTable<std::string>> metas, std::optional<bool > delay) {
318334 if (logger) {
319335 // avoids potentially-evaluated-expression warning with clang.
320336 RemoteLoggerInterface& remoteLoggerRef = *logger;
@@ -331,11 +347,28 @@ void setupLuaActions(LuaContext& luaCtx)
331347 config.alterResponseFunc = std::move (*alterFunc);
332348 }
333349 config.includeCNAME = includeCNAME ? *includeCNAME : false ;
334- getOptionalValue<std::string>(vars, " serverID" , config.serverID );
335- getOptionalValue<std::string>(vars, " ipEncryptKey" , config.ipEncryptKey );
336- getOptionalValue<std::string>(vars, " ipEncryptMethod" , config.ipEncryptMethod );
337- getOptionalValue<std::string>(vars, " exportTags" , tags);
338- getOptionalValue<std::string>(vars, " exportExtendedErrorsToMeta" , config.exportExtendedErrorsToMeta );
350+ if (getOptionalValue<std::string>(vars, " serverID" , config.serverID ) < 0 ) {
351+ throw std::runtime_error (" serverID in RemoteLogResponseAction is not a string" );
352+ }
353+ if (getOptionalValue<std::string>(vars, " ipEncryptKey" , config.ipEncryptKey ) < 0 ) {
354+ throw std::runtime_error (" ipEncryptKey in RemoteLogResponseAction is not a string" );
355+ }
356+ if (getOptionalValue<std::string>(vars, " ipEncryptMethod" , config.ipEncryptMethod ) < 0 ) {
357+ throw std::runtime_error (" ipEncryptMethod in RemoteLogResponseAction is not a string" );
358+ }
359+ if (getOptionalValue<std::string>(vars, " exportTags" , tags) < 0 ) {
360+ throw std::runtime_error (" exportTags in RemoteLogResponseAction is not a string" );
361+ }
362+ if (getOptionalValue<std::string>(vars, " exportExtendedErrorsToMeta" , config.exportExtendedErrorsToMeta ) < 0 ) {
363+ throw std::runtime_error (" exportExtendedErrorsToMeta in RemoteLogResponseAction is not a string" );
364+ }
365+ if (getOptionalValue<bool >(vars, " useServerID" , config.useServerID ) < 0 ) {
366+ throw std::runtime_error (" useServerID in RemoteLogResponseAction is not a string" );
367+ }
368+
369+ if (config.useServerID && !config.serverID .empty ()) {
370+ warnlog (" useServerID and serverID set in RemoteLogResponseAction configuration. value for serverID will not be used" );
371+ }
339372
340373 if (metas) {
341374 for (const auto & [key, value] : *metas) {
0 commit comments