|
| 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 |
0 commit comments