Skip to content

Commit 8756a20

Browse files
committed
refactor: update ZeroBus plugin to require URL scheme for endpoint
Changed the configuration property from 'zerobus_endpoint' to 'endpoint' to enforce the inclusion of a URL scheme (http:// or https://). Updated related error messages and context handling to reflect this change. The workspace_url will now automatically prepend https:// if no scheme is provided. Signed-off-by: [Your Name] <your.email@example.com>
1 parent 411556a commit 8756a20

2 files changed

Lines changed: 24 additions & 18 deletions

File tree

plugins/out_zerobus/zerobus.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,22 @@ static int cb_zerobus_init(struct flb_output_instance *ins,
268268
}
269269

270270
/*
271-
* URL fields need https:// prepending when no scheme is present
272-
* (the ZeroBus SDK requires a scheme), so they are read manually.
271+
* endpoint must include a URL scheme (https:// or http://).
272+
* workspace_url gets https:// prepended when no scheme is present.
273273
*/
274-
tmp = flb_output_get_property("zerobus_endpoint", ins);
274+
tmp = flb_output_get_property("endpoint", ins);
275275
if (!tmp || strlen(tmp) == 0) {
276-
flb_plg_error(ins, "'zerobus_endpoint' is required");
276+
flb_plg_error(ins, "'endpoint' is required");
277277
goto init_error;
278278
}
279-
ctx->zerobus_endpoint = ensure_url_scheme(tmp);
280-
if (!ctx->zerobus_endpoint) {
279+
if (strncmp(tmp, "https://", 8) != 0 && strncmp(tmp, "http://", 7) != 0) {
280+
flb_plg_error(ins,
281+
"'endpoint' must include a URL scheme "
282+
"(e.g. https://...), got: %s", tmp);
283+
goto init_error;
284+
}
285+
ctx->endpoint = flb_sds_create(tmp);
286+
if (!ctx->endpoint) {
281287
goto init_error;
282288
}
283289

@@ -305,15 +311,15 @@ static int cb_zerobus_init(struct flb_output_instance *ins,
305311
}
306312

307313
memset(&result, 0, sizeof(result));
308-
ctx->sdk = zerobus_sdk_new(ctx->zerobus_endpoint,
314+
ctx->sdk = zerobus_sdk_new(ctx->endpoint,
309315
ctx->workspace_url,
310316
&result);
311317
if (!ctx->sdk || !result.success) {
312318
log_cresult_error(ins, &result, "failed to create ZeroBus SDK");
313319
goto init_error;
314320
}
315321

316-
if (strncmp(ctx->zerobus_endpoint, "http://", 7) == 0) {
322+
if (strncmp(ctx->endpoint, "http://", 7) == 0) {
317323
zerobus_sdk_set_use_tls(ctx->sdk, false);
318324
}
319325

@@ -336,14 +342,14 @@ static int cb_zerobus_init(struct flb_output_instance *ins,
336342
}
337343

338344
flb_plg_info(ins, "connected to %s, table: %s",
339-
ctx->zerobus_endpoint, ctx->table_name);
345+
ctx->endpoint, ctx->table_name);
340346

341347
flb_output_set_context(ins, ctx);
342348
return 0;
343349

344350
init_error:
345-
if (ctx->zerobus_endpoint) {
346-
flb_sds_destroy(ctx->zerobus_endpoint);
351+
if (ctx->endpoint) {
352+
flb_sds_destroy(ctx->endpoint);
347353
}
348354
if (ctx->workspace_url) {
349355
flb_sds_destroy(ctx->workspace_url);
@@ -500,8 +506,8 @@ static int cb_zerobus_exit(void *data, struct flb_config *config)
500506
zerobus_sdk_free(ctx->sdk);
501507
}
502508

503-
if (ctx->zerobus_endpoint) {
504-
flb_sds_destroy(ctx->zerobus_endpoint);
509+
if (ctx->endpoint) {
510+
flb_sds_destroy(ctx->endpoint);
505511
}
506512
if (ctx->workspace_url) {
507513
flb_sds_destroy(ctx->workspace_url);
@@ -513,9 +519,9 @@ static int cb_zerobus_exit(void *data, struct flb_config *config)
513519

514520
static struct flb_config_map config_map[] = {
515521
{
516-
FLB_CONFIG_MAP_STR, "zerobus_endpoint", NULL,
522+
FLB_CONFIG_MAP_STR, "endpoint", NULL,
517523
0, FLB_FALSE, 0,
518-
"ZeroBus gRPC endpoint URL"
524+
"ZeroBus gRPC endpoint URL (must include https:// scheme)"
519525
},
520526
{
521527
FLB_CONFIG_MAP_STR, "workspace_url", NULL,

plugins/out_zerobus/zerobus.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ struct flb_out_zerobus {
110110
CZerobusSdk *sdk;
111111
CZerobusStream *stream;
112112

113-
/* Required config -- URL fields are built manually (need scheme fix) */
114-
flb_sds_t zerobus_endpoint;
115-
flb_sds_t workspace_url;
113+
/* Required config -- URL fields are read manually */
114+
flb_sds_t endpoint; /* must include https:// scheme */
115+
flb_sds_t workspace_url; /* https:// auto-prepended if missing */
116116

117117
/* Required config -- auto-populated by config_map */
118118
flb_sds_t table_name;

0 commit comments

Comments
 (0)