67 inline static const char *plugin_prefix =
"ADC_CURL_PLUGIN_";
68 inline static const std::map< const string, const string > plugin_config_defaults =
77 const std::vector<string> tags;
88 if (mode != pi_config)
92 fdir = dir +
string(
"/") + std::to_string(ui);
97 std::stringstream ss(sdebug);
103 std::cout<<
"curl plugin configured" <<std::endl;
109 const string get(
const std::map< string, string >& m,
112 auto it = m.find(field);
116 string en =
string(env_prefix) += field;
117 char *ec = getenv(en.c_str());
119 return plugin_config_defaults.at(field);
125 string get_temp_file_name() {
126 string tplt = fdir +
"/json-curl-msg-XXXXXX";
127 char * cstr =
new char [tplt.length()+1];
128 std::strcpy (cstr, tplt.c_str());
129 int fd = mkstemp(cstr);
137 std::cout<<
"mkstemp failed" <<std::endl;
144 int curl_send(
string& f)
148 string cmd =
"(" + prog +
149 " -X POST -s -w \"\n%{http_code}\n\" -H \"Content-Type: application/json\" -d @"
150 + f +
" " + url +
" || /bin/rm -f " + f +
") &";
151 int err1 = std::system(cmd.c_str());
152 std::cout <<
"cmd:" << cmd << std::endl;
153 std::cout << err1 << std::endl;
154 std::cout << f << std::endl;
157 string qcmd =
"(" + prog +
158 " -X POST -s -w \"\n%{http_code}\n\" -H \"Content-Type: application/json\" -d @"
160 " > /dev/null 2>&1 ; /bin/rm -f " + f +
") &";
161 int err2 = std::system(qcmd.c_str());
163 std::cout << err2 << std::endl;
170 curl_plugin() : vers(
"1.0.0") , state(ok), paused(false), mode(pi_config) { }
179 if (mode != pi_pub_or_final)
184 string fname = get_temp_file_name();
186 std::cout <<
"name: " << fname <<std::endl;
189 std::ofstream out(fname);
191 out << b->serialize() << std::endl;
194 std::cout <<
"'curl' wrote" << std::endl;
200 std::cout <<
"failed write" << std::endl;
204 std::filesystem::remove(fname);
205 std::cout <<
"failed open " << fname << std::endl;
211 int config(
const std::map< std::string, std::string >& m) {
212 return config(m, plugin_prefix);
218 string d = get(m,
"DIRECTORY", env_prefix);
219 string url = get(m,
"URL", env_prefix);
220 string port = get(m,
"PORT", env_prefix);
221 string prog = get(m,
"PROG", env_prefix);
222 string sdebug = get(m,
"DEBUG", env_prefix);
223 return config(d, url, port, prog, sdebug);
227 return plugin_config_defaults;
231 std::map <string, string >m;
235 if (mode != pi_init) {
238 if ( state == err ) {
239 std::cout <<
"curl plugin initialize found pre-existing error" << std::endl;
243 std::filesystem::create_directories(fdir, ec);
244 if (ec.value() != 0 && ec.value() != EEXIST ) {
246 std::cout <<
"unable to create scratch directory for plugin 'curl'; "
247 << fdir <<
" : " << ec.message() << std::endl;
251 std::cout <<
"created " << fdir <<std::endl;
253 mode = pi_pub_or_final;
259 if (mode == pi_pub_or_final) {
265 std::cout <<
"curl plugin finalize on non-running plugin" << std::endl;
288 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