Skip to content

Commit d9e8733

Browse files
committed
[API] Adds indices.remove_block
1 parent f5fa9b5 commit d9e8733

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
# This code was automatically generated from the Elasticsearch Specification
19+
# See https://github.com/elastic/elasticsearch-specification
20+
# See Elasticsearch::ES_SPECIFICATION_COMMIT for commit hash.
21+
module Elasticsearch
22+
module API
23+
module Indices
24+
module Actions
25+
# Remove an index block.
26+
# Remove an index block from an index.
27+
# Index blocks limit the operations allowed on an index by blocking specific operation types.
28+
#
29+
# @option arguments [String] :index A comma-separated list or wildcard expression of index names used to limit the request.
30+
# By default, you must explicitly name the indices you are removing blocks from.
31+
# To allow the removal of blocks from indices with `_all`, `*`, or other wildcard expressions, change the `action.destructive_requires_name` setting to `false`.
32+
# You can update this setting in the `elasticsearch.yml` file or by using the cluster update settings API. (*Required*)
33+
# @option arguments [String] :block The block type to remove from the index. (*Required*)
34+
# @option arguments [Boolean] :allow_no_indices If `false`, the request returns an error if any wildcard expression, index alias, or `_all` value targets only missing or closed indices.
35+
# This behavior applies even if the request targets other open indices.
36+
# For example, a request targeting `foo*,bar*` returns an error if an index starts with `foo` but no index starts with `bar`. Server default: true.
37+
# @option arguments [String, Array<String>] :expand_wildcards The type of index that wildcard patterns can match.
38+
# If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams.
39+
# It supports comma-separated values, such as `open,hidden`. Server default: open.
40+
# @option arguments [Boolean] :ignore_unavailable If `false`, the request returns an error if it targets a missing or closed index.
41+
# @option arguments [Time] :master_timeout The period to wait for the master node.
42+
# If the master node is not available before the timeout expires, the request fails and returns an error.
43+
# It can also be set to `-1` to indicate that the request should never timeout. Server default: 30s.
44+
# @option arguments [Time] :timeout The period to wait for a response from all relevant nodes in the cluster after updating the cluster metadata.
45+
# If no response is received before the timeout expires, the cluster metadata update still applies but the response will indicate that it was not completely acknowledged.
46+
# It can also be set to `-1` to indicate that the request should never timeout. Server default: 30s.
47+
# @option arguments [Boolean] :error_trace When set to `true` Elasticsearch will include the full stack trace of errors
48+
# when they occur.
49+
# @option arguments [String, Array<String>] :filter_path Comma-separated list of filters in dot notation which reduce the response
50+
# returned by Elasticsearch.
51+
# @option arguments [Boolean] :human When set to `true` will return statistics in a format suitable for humans.
52+
# For example `"exists_time": "1h"` for humans and
53+
# `"exists_time_in_millis": 3600000` for computers. When disabled the human
54+
# readable values will be omitted. This makes sense for responses being consumed
55+
# only by machines.
56+
# @option arguments [Boolean] :pretty If set to `true` the returned JSON will be "pretty-formatted". Only use
57+
# this option for debugging only.
58+
# @option arguments [Hash] :headers Custom HTTP headers
59+
#
60+
# @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-remove-block
61+
#
62+
def remove_block(arguments = {})
63+
request_opts = { endpoint: arguments[:endpoint] || 'indices.remove_block' }
64+
65+
defined_params = [:index, :block].each_with_object({}) do |variable, set_variables|
66+
set_variables[variable] = arguments[variable] if arguments.key?(variable)
67+
end
68+
request_opts[:defined_params] = defined_params unless defined_params.empty?
69+
70+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
71+
raise ArgumentError, "Required argument 'block' missing" unless arguments[:block]
72+
73+
arguments = arguments.clone
74+
headers = arguments.delete(:headers) || {}
75+
76+
body = nil
77+
78+
_index = arguments.delete(:index)
79+
80+
_block = arguments.delete(:block)
81+
82+
method = Elasticsearch::API::HTTP_DELETE
83+
path = "#{Utils.listify(_index)}/_block/#{Utils.listify(_block)}"
84+
params = Utils.process_params(arguments)
85+
86+
Elasticsearch::API::Response.new(
87+
perform_request(method, path, params, body, headers, request_opts)
88+
)
89+
end
90+
end
91+
end
92+
end
93+
end
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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#remove_block' do
21+
let(:expected_args) do
22+
[
23+
'DELETE',
24+
url,
25+
{},
26+
nil,
27+
{},
28+
{ defined_params: { block: 'test_block', index: 'test_index' },
29+
endpoint: 'indices.remove_block' }
30+
]
31+
end
32+
let(:url) { "#{index}/_block/#{block}" }
33+
let(:index) { 'test_index' }
34+
let(:block) { 'test_block' }
35+
36+
it 'performs the request' do
37+
expect(
38+
client_double.indices.remove_block(index: index, block: block)
39+
).to be_a Elasticsearch::API::Response
40+
end
41+
42+
context 'when an index is not specified' do
43+
let(:client) do
44+
Class.new { include Elasticsearch::API }.new
45+
end
46+
47+
it 'raises an argument error' do
48+
expect do
49+
client.indices.remove_block(block: block)
50+
end.to raise_exception(ArgumentError)
51+
end
52+
end
53+
54+
context 'when a block is not specified' do
55+
let(:client) do
56+
Class.new { include Elasticsearch::API }.new
57+
end
58+
59+
it 'raises an argument error' do
60+
expect do
61+
client.indices.remove_block(index: index)
62+
end.to raise_exception(ArgumentError)
63+
end
64+
end
65+
end

0 commit comments

Comments
 (0)