Skip to content

Commit 17d661a

Browse files
committed
Added Elastic cloud API key and Token API
1 parent dcb42ab commit 17d661a

File tree

1 file changed

+16
-0
lines changed
  • lib/Search/Elasticsearch/Role

1 file changed

+16
-0
lines changed

lib/Search/Elasticsearch/Role/Cxn.pm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,22 @@ sub BUILDARGS {
158158
$default_headers{'Content-Type'} = 'application/vnd.elasticsearch+json; compatible-with=7';
159159
}
160160

161+
if (defined $params->{elastic_cloud_api_key} && defined $params->{token_api}) {
162+
throw( 'Request',
163+
"You cannot set elastic_cloud_api_key and token_api together" );
164+
}
165+
166+
# Elastic cloud API key
167+
if (defined $params->{elastic_cloud_api_key}) {
168+
$default_headers{'Authorization'} = sprintf("ApiKey %s", $params->{elastic_cloud_api_key});
169+
}
170+
171+
# Elasticsearch token API (https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-token.html)
172+
if (defined $params->{token_api}) {
173+
$default_headers{'Authorization'} = sprintf("Bearer %s", $params->{token_api});
174+
}
175+
176+
# Elasticsearch
161177
$params->{scheme} = $scheme;
162178
$params->{is_https} = $scheme eq 'https';
163179
$params->{host} = $host;

0 commit comments

Comments
 (0)