Skip to content

Commit

Permalink
es opensearch: update ignored header delete logic
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewfala committed Dec 19, 2022
1 parent 4839595 commit b4d38b9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
4 changes: 2 additions & 2 deletions plugins/out_es/es.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,8 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk,
flb_http_add_header(c, "User-Agent", 10, "Fluent-Bit", 10);
#endif

flb_http_add_header(c, "Content-Type", 12, "application/x-ndjson", 20);

if (ctx->http_user && ctx->http_passwd) {
flb_http_basic_auth(c, ctx->http_user, ctx->http_passwd);
}
Expand All @@ -850,8 +852,6 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk,
}
#endif

flb_http_add_header(c, "Content-Type", 12, "application/x-ndjson", 20);

/* Map debug callbacks */
flb_http_client_debug(c, ctx->ins->callback);

Expand Down
1 change: 1 addition & 0 deletions plugins/out_es/es.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct flb_elasticsearch {
struct flb_tls *aws_sts_tls;
char *aws_session_name;
char *aws_service_name;
struct mk_list *aws_unsigned_headers;
#endif

/* HTTP Client Setup */
Expand Down
17 changes: 17 additions & 0 deletions plugins/out_es/es_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,19 @@ struct flb_elasticsearch *flb_es_conf_create(struct flb_output_instance *ins,
}

#ifdef FLB_HAVE_AWS

/* AWS Auth Unsigned Headers */
ctx->aws_unsigned_headers = flb_malloc(sizeof(struct mk_list));
if (ret != 0) {
flb_es_conf_destroy(ctx);
}
flb_slist_create(ctx->aws_unsigned_headers);
ret = flb_slist_add(ctx->aws_unsigned_headers, "Content-Length");
if (ret != 0) {
flb_es_conf_destroy(ctx);
return NULL;
}

/* AWS Auth */
ctx->has_aws_auth = FLB_FALSE;
tmp = flb_output_get_property("aws_auth", ins);
Expand Down Expand Up @@ -444,6 +457,10 @@ int flb_es_conf_destroy(struct flb_elasticsearch *ctx)
if (ctx->aws_sts_tls) {
flb_tls_destroy(ctx->aws_sts_tls);
}

if (ctx->aws_unsigned_headers) {
flb_slist_destroy(ctx->aws_unsigned_headers);
}
#endif

if (ctx->ra_prefix_key) {
Expand Down
6 changes: 3 additions & 3 deletions plugins/out_opensearch/opensearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static flb_sds_t add_aws_auth(struct flb_http_client *c,

signature = flb_signv4_do(c, FLB_TRUE, FLB_TRUE, time(NULL),
ctx->aws_region, ctx->aws_service_name,
S3_MODE_SIGNED_PAYLOAD, &ctx->aws_unsigned_headers,
S3_MODE_SIGNED_PAYLOAD, ctx->aws_unsigned_headers,
ctx->aws_provider);
if (!signature) {
flb_plg_error(ctx->ins, "could not sign request with sigv4");
Expand Down Expand Up @@ -851,6 +851,8 @@ static void cb_opensearch_flush(struct flb_event_chunk *event_chunk,
flb_http_add_header(c, "User-Agent", 10, "Fluent-Bit", 10);
#endif

flb_http_add_header(c, "Content-Type", 12, "application/x-ndjson", 20);

if (ctx->http_user && ctx->http_passwd) {
flb_http_basic_auth(c, ctx->http_user, ctx->http_passwd);
}
Expand All @@ -867,8 +869,6 @@ static void cb_opensearch_flush(struct flb_event_chunk *event_chunk,
}
#endif

flb_http_add_header(c, "Content-Type", 12, "application/x-ndjson", 20);

/* Map debug callbacks */
flb_http_client_debug(c, ctx->ins->callback);

Expand Down
2 changes: 1 addition & 1 deletion plugins/out_opensearch/opensearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct flb_opensearch {
struct flb_tls *aws_sts_tls;
char *aws_session_name;
char *aws_service_name;
struct mk_list aws_unsigned_headers;
struct mk_list *aws_unsigned_headers;
#endif

/* HTTP Client Setup */
Expand Down
13 changes: 10 additions & 3 deletions plugins/out_opensearch/os_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,13 @@ struct flb_opensearch *flb_os_conf_create(struct flb_output_instance *ins,

#ifdef FLB_HAVE_AWS
/* AWS Auth Unsigned Headers */
flb_slist_create(&ctx->aws_unsigned_headers);
ret = flb_slist_add(&ctx->aws_unsigned_headers, "Content-Length");
ctx->aws_unsigned_headers = flb_malloc(sizeof(struct mk_list));
if (!ctx->aws_unsigned_headers) {
flb_os_conf_destroy(ctx);
return NULL;
}
flb_slist_create(ctx->aws_unsigned_headers);
ret = flb_slist_add(ctx->aws_unsigned_headers, "Content-Length");
if (ret != 0) {
flb_os_conf_destroy(ctx);
return NULL;
Expand Down Expand Up @@ -357,7 +362,9 @@ int flb_os_conf_destroy(struct flb_opensearch *ctx)
flb_tls_destroy(ctx->aws_sts_tls);
}

flb_slist_destroy(&ctx->aws_unsigned_headers);
if (ctx->aws_unsigned_headers) {
flb_slist_destroy(ctx->aws_unsigned_headers);
}
#endif

if (ctx->ra_prefix_key) {
Expand Down

0 comments on commit b4d38b9

Please sign in to comment.