-
Notifications
You must be signed in to change notification settings - Fork 849
Adds a run-plugin operator to HRW #11320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,10 @@ | |
| #include <arpa/inet.h> | ||
| #include <cstring> | ||
| #include <algorithm> | ||
| #include <iomanip> | ||
|
|
||
| #include "ts/ts.h" | ||
| #include "swoc/swoc_file.h" | ||
|
|
||
| #include "operators.h" | ||
| #include "ts/apidefs.h" | ||
|
|
@@ -1092,6 +1094,7 @@ OperatorSetHttpCntl::initialize_hooks() | |
| static const char *const HttpCntls[] = { | ||
| "LOGGING", "INTERCEPT_RETRY", "RESP_CACHEABLE", "REQ_CACHEABLE", "SERVER_NO_STORE", "TXN_DEBUG", "SKIP_REMAP", | ||
| }; | ||
|
|
||
| void | ||
| OperatorSetHttpCntl::exec(const Resources &res) const | ||
| { | ||
|
|
@@ -1103,3 +1106,73 @@ OperatorSetHttpCntl::exec(const Resources &res) const | |
| Dbg(pi_dbg_ctl, " Turning OFF %s for transaction", HttpCntls[static_cast<size_t>(_cntl_qual)]); | ||
| } | ||
| } | ||
|
|
||
| void | ||
| OperatorRunPlugin::initialize(Parser &p) | ||
| { | ||
| Operator::initialize(p); | ||
|
|
||
| auto plugin_name = p.get_arg(); | ||
| auto plugin_args = p.get_value(); | ||
|
|
||
| if (plugin_name.empty()) { | ||
| TSError("[%s] missing plugin name", PLUGIN_NAME); | ||
| return; | ||
| } | ||
|
|
||
| std::vector<std::string> tokens; | ||
| std::istringstream iss(plugin_args); | ||
| std::string token; | ||
|
|
||
| while (iss >> std::quoted(token)) { | ||
| tokens.push_back(token); | ||
| } | ||
|
|
||
| // Create argc and argv | ||
| int argc = tokens.size() + 2; | ||
| char **argv = new char *[argc]; | ||
|
|
||
| argv[0] = p.from_url(); | ||
| argv[1] = p.to_url(); | ||
|
|
||
| for (int i = 0; i < argc; ++i) { | ||
| argv[i + 2] = const_cast<char *>(tokens[i].c_str()); | ||
| } | ||
|
|
||
| std::string error; | ||
|
|
||
| // We have to escalate access while loading these plugins, just as done when loading remap.config | ||
| { | ||
| uint32_t elevate_access = 0; | ||
|
|
||
| REC_ReadConfigInteger(elevate_access, "proxy.config.plugin.load_elevated"); | ||
| ElevateAccess access(elevate_access ? ElevateAccess::FILE_PRIVILEGE : 0); | ||
|
|
||
| _plugin = plugin_factory.getRemapPlugin(swoc::file::path(plugin_name), argc, const_cast<char **>(argv), error, | ||
| isPluginDynamicReloadEnabled()); | ||
| } // done elevating access | ||
|
|
||
| delete[] argv; | ||
|
|
||
| if (!_plugin) { | ||
| TSError("[%s] Unable to load plugin '%s': %s", PLUGIN_NAME, plugin_name.c_str(), error.c_str()); | ||
| } | ||
| } | ||
|
|
||
| void | ||
| OperatorRunPlugin::initialize_hooks() | ||
| { | ||
| add_allowed_hook(TS_REMAP_PSEUDO_HOOK); | ||
|
|
||
| require_resources(RSRC_CLIENT_REQUEST_HEADERS); // Need this for the txnp | ||
| } | ||
|
|
||
| void | ||
| OperatorRunPlugin::exec(const Resources &res) const | ||
| { | ||
| TSReleaseAssert(_plugin != nullptr); | ||
|
|
||
| if (res._rri && res.txnp) { | ||
| _plugin->doRemap(res.txnp, res._rri); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious. should we pass on the return status of the doRemap() function somewhere?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now it is just ignored.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeh, so we kinda butchered this a bit in all the refactoring and dealings with "chaining" remap plugins. In most cases, this return code is obsoleted, and we don't' really use it. So, I made a choice to ignore it in HRW, whereas in Cripts, the caller can chose to look at it and do something with it (albeit, I think that's unlikely). I'm not sure the stop / continue works any more either, but almost no plugin that's in use uses that. |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this run on any hook other than the remap hook?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it can only run in a remap hook, but the plugin it runs can setup other hooks.