Skip to content

Commit

Permalink
out_es: add support for HTTP Basic Auth (#248)
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed May 22, 2017
1 parent 82673e2 commit 99e76b1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugins/out_es/es.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ void cb_es_flush(void *data, size_t bytes,
pack, bytes_out, NULL, 0, NULL, 0);
flb_http_add_header(c, "User-Agent", 10, "Fluent-Bit", 10);

if (ctx->http_user && ctx->http_passwd) {
flb_http_basic_auth(c, ctx->http_user, ctx->http_passwd);
}

ret = flb_http_do(c, &b_sent);
if (ret == 0) {
flb_debug("[out_es] HTTP Status=%i", c->resp.status);
Expand Down
4 changes: 4 additions & 0 deletions plugins/out_es/es.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ struct flb_elasticsearch {
char *index;
char *type;

/* HTTP Auth */
char *http_user;
char *http_passwd;

/*
* Logstash compatibility options
* ==============================
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 @@ -121,6 +121,20 @@ struct flb_elasticsearch *flb_es_conf_create(struct flb_output_instance *ins,
}
}

/* HTTP Auth */
tmp = flb_output_get_property("http_user", ins);
if (tmp) {
ctx->http_user = flb_strdup(tmp);

tmp = flb_output_get_property("http_passwd", ins);
if (tmp) {
ctx->http_passwd = flb_strdup(tmp);
}
else {
ctx->http_passwd = flb_strdup("");
}
}

/*
* Logstash compatibility options
* ==============================
Expand Down Expand Up @@ -212,6 +226,9 @@ int flb_es_conf_destroy(struct flb_elasticsearch *ctx)
flb_free(ctx->index);
flb_free(ctx->type);

flb_free(ctx->http_user);
flb_free(ctx->http_passwd);

flb_free(ctx->logstash_prefix);
flb_free(ctx->logstash_dateformat);
flb_free(ctx->time_key);
Expand Down

0 comments on commit 99e76b1

Please sign in to comment.