Skip to content

Commit dea819a

Browse files
committed
[XPACK] Updates API, adds grant_api_key
1 parent b6069e5 commit dea819a

File tree

4 files changed

+99
-2
lines changed

4 files changed

+99
-2
lines changed

elasticsearch-xpack/lib/elasticsearch/xpack/api/actions/security/get_role.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Security
2222
module Actions
2323
# Retrieves roles in the native realm.
2424
#
25-
# @option arguments [String] :name Role name
25+
# @option arguments [List] :name A comma-separated list of role names
2626
# @option arguments [Hash] :headers Custom HTTP headers
2727
#
2828
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-get-role.html

elasticsearch-xpack/lib/elasticsearch/xpack/api/actions/security/get_role_mapping.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Security
2222
module Actions
2323
# Retrieves role mappings.
2424
#
25-
# @option arguments [String] :name Role-Mapping name
25+
# @option arguments [List] :name A comma-separated list of role-mapping names
2626
# @option arguments [Hash] :headers Custom HTTP headers
2727
#
2828
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-get-role-mapping.html
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module Security
22+
module Actions
23+
# Creates an API key on behalf of another user.
24+
#
25+
# @option arguments [String] :refresh If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. (options: true, false, wait_for)
26+
# @option arguments [Hash] :headers Custom HTTP headers
27+
# @option arguments [Hash] :body The api key request to create an API key (*Required*)
28+
#
29+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-grant-api-key.html
30+
#
31+
def grant_api_key(arguments = {})
32+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
33+
34+
headers = arguments.delete(:headers) || {}
35+
36+
arguments = arguments.clone
37+
38+
method = Elasticsearch::API::HTTP_POST
39+
path = "_security/api_key/grant"
40+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
41+
42+
body = arguments[:body]
43+
perform_request(method, path, params, body, headers).body
44+
end
45+
46+
# Register this action with its valid params when the module is loaded.
47+
#
48+
# @since 6.2.0
49+
ParamsRegistry.register(:grant_api_key, [
50+
:refresh
51+
].freeze)
52+
end
53+
end
54+
end
55+
end
56+
end
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'test_helper'
19+
20+
module Elasticsearch
21+
module Test
22+
class XPackSecurityGrantApiKey < Minitest::Test
23+
context "XPack Security: Grant API Key" do
24+
subject { FakeClient.new }
25+
should "perform correct request" do
26+
subject.expects(:perform_request).with do |method, url, params, body|
27+
assert_equal('POST', method)
28+
assert_equal('_security/api_key/grant', url)
29+
assert_equal(Hash.new, params)
30+
assert_equal(body, {access_token: 'access_token', api_key: 'api_key', grant_type: 'access_token'})
31+
true
32+
end.returns(FakeResponse.new)
33+
34+
subject.xpack.security.grant_api_key(
35+
body: {access_token: 'access_token', api_key: 'api_key', grant_type: 'access_token'}
36+
)
37+
end
38+
end
39+
end
40+
end
41+
end

0 commit comments

Comments
 (0)