Skip to content

Commit 18da45e

Browse files
committed
[API] Adds indices.add_block endpoint
1 parent 7b76f68 commit 18da45e

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 API
20+
module Indices
21+
module Actions
22+
# Adds a block to an index.
23+
#
24+
# @option arguments [List] :index A comma separated list of indices to add a block to
25+
# @option arguments [String] :block The block to add (one of read, write, read_only or metadata)
26+
# @option arguments [Time] :timeout Explicit operation timeout
27+
# @option arguments [Time] :master_timeout Specify timeout for connection to master
28+
# @option arguments [Boolean] :ignore_unavailable Whether specified concrete indices should be ignored when unavailable (missing or closed)
29+
# @option arguments [Boolean] :allow_no_indices Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)
30+
# @option arguments [String] :expand_wildcards Whether to expand wildcard expression to concrete indices that are open, closed or both.
31+
# (options: open,closed,hidden,none,all)
32+
33+
# @option arguments [Hash] :headers Custom HTTP headers
34+
#
35+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-blocks.html
36+
#
37+
def add_block(arguments = {})
38+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
39+
raise ArgumentError, "Required argument 'block' missing" unless arguments[:block]
40+
41+
headers = arguments.delete(:headers) || {}
42+
43+
arguments = arguments.clone
44+
45+
_index = arguments.delete(:index)
46+
47+
_block = arguments.delete(:block)
48+
49+
method = Elasticsearch::API::HTTP_PUT
50+
path = "#{Utils.__listify(_index)}/_block/#{Utils.__listify(_block)}"
51+
params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
52+
53+
body = nil
54+
perform_request(method, path, params, body, headers).body
55+
end
56+
57+
# Register this action with its valid params when the module is loaded.
58+
#
59+
# @since 6.2.0
60+
ParamsRegistry.register(:add_block, [
61+
:timeout,
62+
:master_timeout,
63+
:ignore_unavailable,
64+
:allow_no_indices,
65+
:expand_wildcards
66+
].freeze)
67+
end
68+
end
69+
end
70+
end
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 'spec_helper'
19+
20+
describe 'client.indices#add_block' do
21+
let(:expected_args) do
22+
[
23+
'PUT',
24+
url,
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
let(:url) { "#{index}/_block/#{block}"}
31+
let(:index) { 'test_index' }
32+
let(:block) { 'test_block' }
33+
34+
it 'performs the request' do
35+
expect(
36+
client_double.indices.add_block(index: index, block: block)
37+
).to eq({})
38+
end
39+
40+
context 'when an index is not specified' do
41+
let(:client) do
42+
Class.new { include Elasticsearch::API }.new
43+
end
44+
45+
it 'raises an argument error' do
46+
expect do
47+
client.indices.add_block(block: block)
48+
end.to raise_exception(ArgumentError)
49+
end
50+
end
51+
52+
context 'when a block is not specified' do
53+
let(:client) do
54+
Class.new { include Elasticsearch::API }.new
55+
end
56+
57+
it 'raises an argument error' do
58+
expect do
59+
client.indices.add_block(index: index)
60+
end.to raise_exception(ArgumentError)
61+
end
62+
end
63+
end

0 commit comments

Comments
 (0)