@@ -75,6 +75,27 @@ static flb_sds_t add_aws_auth(struct flb_http_client *c,
7575}
7676#endif /* FLB_HAVE_AWS */
7777
78+ static int es_http_add_cloud_apikey (struct flb_http_client * c ,
79+ const char * apikey )
80+ {
81+ flb_sds_t header ;
82+ int ret = 0 ;
83+
84+ if (apikey == NULL ) {
85+ return -1 ;
86+ }
87+
88+ header = flb_sds_create_size (256 + 7 );
89+ header = flb_sds_printf (& header , "%s %s" , "ApiKey" , apikey );
90+
91+ ret = flb_http_add_header (c , "Authorization" , 13 ,
92+ header , flb_sds_len (header ));
93+
94+ flb_sds_destroy (header );
95+
96+ return ret ;
97+ }
98+
7899static int es_pack_map_content (msgpack_packer * tmp_pck ,
79100 msgpack_object map ,
80101 struct flb_elasticsearch * ctx )
@@ -868,11 +889,17 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk,
868889 flb_http_add_header (c , "Content-Type" , 12 , "application/x-ndjson" , 20 );
869890
870891 if (ctx -> http_user && ctx -> http_passwd ) {
892+ flb_plg_debug (ctx -> ins , "using http basic auth" );
871893 flb_http_basic_auth (c , ctx -> http_user , ctx -> http_passwd );
872894 }
873895 else if (ctx -> cloud_user && ctx -> cloud_passwd ) {
896+ flb_plg_debug (ctx -> ins , "using elastic cloud auth" );
874897 flb_http_basic_auth (c , ctx -> cloud_user , ctx -> cloud_passwd );
875898 }
899+ else if (ctx -> cloud_apikey ) {
900+ flb_plg_debug (ctx -> ins , "using elastic cloud apikey" );
901+ es_http_add_cloud_apikey (c , ctx -> cloud_apikey );
902+ }
876903
877904#ifdef FLB_HAVE_AWS
878905 if (ctx -> has_aws_auth == FLB_TRUE ) {
@@ -926,7 +953,7 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk,
926953 /*
927954 * If trace_error is set, trace the actual
928955 * response from Elasticsearch explaining the problem.
929- * Trace_Output can be used to see the request.
956+ * Trace_Output can be used to see the request.
930957 */
931958 if (pack_size < 4000 ) {
932959 flb_plg_debug (ctx -> ins , "error caused by: Input\n%.*s\n" ,
@@ -1023,7 +1050,7 @@ static struct flb_config_map config_map[] = {
10231050 "Set payload compression mechanism. Option available is 'gzip'"
10241051 },
10251052
1026- /* Cloud Authentication */
1053+ /* Elastic Cloud Authentication */
10271054 {
10281055 FLB_CONFIG_MAP_STR , "cloud_id" , NULL ,
10291056 0 , FLB_FALSE , 0 ,
@@ -1034,6 +1061,11 @@ static struct flb_config_map config_map[] = {
10341061 0 , FLB_FALSE , 0 ,
10351062 "Elastic cloud authentication credentials"
10361063 },
1064+ {
1065+ FLB_CONFIG_MAP_STR , "cloud_apikey" , NULL ,
1066+ 0 , FLB_FALSE , 0 ,
1067+ "Elastic cloud apikey credentials"
1068+ },
10371069
10381070 /* AWS Authentication */
10391071#ifdef FLB_HAVE_AWS
0 commit comments