63 inline static const char *plugin_prefix =
"ADC_CURL_PLUGIN_";
64 inline static const std::map< const string, const string > plugin_config_defaults =
73 const std::vector<string> tags;
84 if (mode != pi_config)
88 fdir = dir +
string(
"/") + std::to_string(ui);
93 std::stringstream ss(sdebug);
99 std::cout<<
"curl plugin configured" <<std::endl;
105 const string get(
const std::map< string, string >& m,
108 auto it = m.find(field);
112 string en =
string(env_prefix) += field;
113 char *ec = getenv(en.c_str());
115 return plugin_config_defaults.at(field);
121 string get_temp_file_name() {
122 string tplt = fdir +
"/json-curl-msg-XXXXXX";
123 char * cstr =
new char [tplt.length()+1];
124 std::strcpy (cstr, tplt.c_str());
125 int fd = mkstemp(cstr);
133 std::cout<<
"mkstemp failed" <<std::endl;
140 int curl_send(
string& f)
144 string cmd =
"(" + prog +
145 " -X POST -s -w \"\n%{http_code}\n\" -H \"Content-Type: application/json\" -d @"
146 + f +
" " + url +
" || /bin/rm -f " + f +
") &";
147 int err1 = std::system(cmd.c_str());
148 std::cout <<
"cmd:" << cmd << std::endl;
149 std::cout << err1 << std::endl;
150 std::cout << f << std::endl;
153 string qcmd =
"(" + prog +
154 " -X POST -s -w \"\n%{http_code}\n\" -H \"Content-Type: application/json\" -d @"
156 " > /dev/null 2>&1 ; /bin/rm -f " + f +
") &";
157 int err2 = std::system(qcmd.c_str());
159 std::cout << err2 << std::endl;
166 curl_plugin() : vers(
"1.0.0") , state(ok), paused(false), mode(pi_config) { }
175 if (mode != pi_pub_or_final)
180 string fname = get_temp_file_name();
182 std::cout <<
"name: " << fname <<std::endl;
185 std::ofstream out(fname);
187 out << b->serialize() << std::endl;
190 std::cout <<
"'curl' wrote" << std::endl;
196 std::cout <<
"failed write" << std::endl;
200 std::filesystem::remove(fname);
201 std::cout <<
"failed open " << fname << std::endl;
207 int config(
const std::map< std::string, std::string >& m) {
208 return config(m, plugin_prefix);
214 string d = get(m,
"DIRECTORY", env_prefix);
215 string url = get(m,
"URL", env_prefix);
216 string port = get(m,
"PORT", env_prefix);
217 string prog = get(m,
"PROG", env_prefix);
218 string sdebug = get(m,
"DEBUG", env_prefix);
219 return config(d, url, port, prog, sdebug);
223 return plugin_config_defaults;
227 std::map <string, string >m;
231 if (mode != pi_init) {
234 if ( state == err ) {
235 std::cout <<
"curl plugin initialize found pre-existing error" << std::endl;
239 std::filesystem::create_directories(fdir, ec);
240 if (ec.value() != 0 && ec.value() != EEXIST ) {
242 std::cout <<
"unable to create scratch directory for plugin 'curl'; "
243 << fdir <<
" : " << ec.message() << std::endl;
247 std::cout <<
"created " << fdir <<std::endl;
249 mode = pi_pub_or_final;
255 if (mode == pi_pub_or_final) {
261 std::cout <<
"curl plugin finalize on non-running plugin" << std::endl;
284 std::cout <<
"Destructing curl_plugin" << std::endl;
Curl utility publisher_api implementation. This plugin generates a scratch file (in-memory) and async...
int config(const std::map< std::string, std::string > &m, string_view env_prefix)
Configure the plugin with the options given and the corresponding environment variables.
void pause()
Pause publishing until a call to resume. Duplicate calls are allowed.
static const char * adc_curl_plugin_prog_default
default full path to curl utility This program should be world accessible. Overridden with env("ADC_C...
int initialize()
Ready the plugin to publish following the configuration options set or defaulted.
string_view version() const
int config(const std::map< std::string, std::string > &m)
Configure the plugin with the options given.
const std::map< const std::string, const std::string > & get_option_defaults()
Look up the settable options and their defaults.
static const char * adc_curl_plugin_debug_default
ADC curl plugin enable debug messages; (default "0": none) "2" provides message send debugging "1" pr...
void resume()
Resume publishing Duplicate calls are allowed.
void finalize()
Stop publishing and release any resources held for managing publication.
int publish(std::shared_ptr< builder_api > b)
Publish the content of the builder.
static const char * adc_curl_plugin_directory_default
default scratch directory for curl utility messages. This directory must be globally writable and sho...
static const char * adc_curl_plugin_port_default
default ADC server https port. The server should be highly available. Overridden with env("ADC_CURL_P...
static const char * adc_curl_plugin_url_default
ADC data ingest server host. The server should be highly available; the default value of https://loca...
Publisher plugin interface.
std::string_view string_view