Skip to content

Commit e89f0d5

Browse files
carlosdelestpicandocodigo
authored andcommitted
Use POST when token name is not present
1 parent 0d0b0bc commit e89f0d5

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

elasticsearch-api/lib/elasticsearch/api/actions/security/create_service_token.rb

+7-6
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ def create_service_token(arguments = {})
4747

4848
_name = arguments.delete(:name)
4949

50-
method = Elasticsearch::API::HTTP_PUT
51-
path = if _namespace && _service && _name
52-
"_security/service/#{Utils.__listify(_namespace)}/#{Utils.__listify(_service)}/credential/token/#{Utils.__listify(_name)}"
53-
else
54-
"_security/service/#{Utils.__listify(_namespace)}/#{Utils.__listify(_service)}/credential/token"
55-
end
50+
if _namespace && _service && _name
51+
method = Elasticsearch::API::HTTP_PUT
52+
path = "_security/service/#{Utils.__listify(_namespace)}/#{Utils.__listify(_service)}/credential/token/#{Utils.__listify(_name)}"
53+
else
54+
method = Elasticsearch::API::HTTP_POST
55+
path = "_security/service/#{Utils.__listify(_namespace)}/#{Utils.__listify(_service)}/credential/token"
56+
end
5657
params = Utils.process_params(arguments)
5758

5859
Elasticsearch::API::Response.new(

elasticsearch-api/spec/elasticsearch/api/actions/security/create_service_token_spec.rb

+17-2
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,31 @@
1818
require 'spec_helper'
1919

2020
describe 'client#security#create_service_token' do
21+
let(:expected_path) { '_security/service/foo/bar/credential/token' }
22+
let(:expected_request_method) { 'POST' }
2123
let(:expected_args) do
2224
[
23-
'PUT',
24-
'_security/service/foo/bar/credential/token',
25+
expected_request_method,
26+
expected_path,
2527
{},
2628
nil,
2729
{}
2830
]
2931
end
3032

33+
context 'with token name' do
34+
let(:expected_request_method) { 'PUT' }
35+
let(:token_name) { 'test-token' }
36+
let(:expected_path) { "#{super()}/#{token_name}" }
37+
it 'performs the request' do
38+
expect(
39+
client_double.security.create_service_token(
40+
namespace: 'foo', service: 'bar', name: token_name
41+
)
42+
).to be_a Elasticsearch::API::Response
43+
end
44+
end
45+
3146
it 'performs the request' do
3247
expect(
3348
client_double.security.create_service_token(

0 commit comments

Comments
 (0)