@@ -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 )
@@ -875,11 +896,17 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk,
875896    flb_http_add_header (c , "Content-Type" , 12 , "application/x-ndjson" , 20 );
876897
877898    if  (ctx -> http_user  &&  ctx -> http_passwd ) {
899+         flb_plg_debug (ctx -> ins , "using http basic auth" );
878900        flb_http_basic_auth (c , ctx -> http_user , ctx -> http_passwd );
879901    }
880902    else  if  (ctx -> cloud_user  &&  ctx -> cloud_passwd ) {
903+         flb_plg_debug (ctx -> ins , "using elastic cloud auth" );
881904        flb_http_basic_auth (c , ctx -> cloud_user , ctx -> cloud_passwd );
882905    }
906+     else  if  (ctx -> cloud_apikey ) {
907+         flb_plg_debug (ctx -> ins , "using elastic cloud apikey" );
908+         es_http_add_cloud_apikey (c , ctx -> cloud_apikey );
909+     }
883910
884911#ifdef  FLB_HAVE_AWS 
885912    if  (ctx -> has_aws_auth  ==  FLB_TRUE ) {
@@ -937,7 +964,7 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk,
937964                    /* 
938965                     * If trace_error is set, trace the actual 
939966                     * response from Elasticsearch explaining the problem. 
940-                      * Trace_Output can be used to see the request.   
967+                      * Trace_Output can be used to see the request. 
941968                     */ 
942969                    if  (pack_size  <  4000 ) {
943970                        flb_plg_debug (ctx -> ins , "error caused by: Input\n%.*s\n" ,
@@ -1102,7 +1129,7 @@ static struct flb_config_map config_map[] = {
11021129     "Set payload compression mechanism. Option available is 'gzip'" 
11031130    },
11041131
1105-     /* Cloud Authentication */ 
1132+     /* Elastic  Cloud Authentication */ 
11061133    {
11071134     FLB_CONFIG_MAP_STR , "cloud_id" , NULL ,
11081135     0 , FLB_FALSE , 0 ,
@@ -1113,6 +1140,11 @@ static struct flb_config_map config_map[] = {
11131140     0 , FLB_FALSE , 0 ,
11141141     "Elastic cloud authentication credentials" 
11151142    },
1143+     {
1144+      FLB_CONFIG_MAP_STR , "cloud_apikey" , NULL ,
1145+      0 , FLB_FALSE , 0 ,
1146+      "Elastic cloud apikey credentials" 
1147+     },
11161148
11171149    /* AWS Authentication */ 
11181150#ifdef  FLB_HAVE_AWS 
0 commit comments