Class: ElastomerClient::Client::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/elastomer_client/client/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, name = nil) ⇒ Repository

Create a new index client for making API requests that pertain to the health and management individual indexes.

client - ElastomerClient::Client used for HTTP requests to the server name - The name of the index as a String or an Array of names



17
18
19
20
# File 'lib/elastomer_client/client/repository.rb', line 17

def initialize(client, name = nil)
  @client = client
  @name   = @client.assert_param_presence(name, "repository name") unless name.nil?
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



22
23
24
# File 'lib/elastomer_client/client/repository.rb', line 22

def client
  @client
end

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/elastomer_client/client/repository.rb', line 22

def name
  @name
end

Instance Method Details

#create(body, params = {}) ⇒ Object

Create the repository. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories

body - The repository type and settings as a Hash or a JSON encoded String params - Parameters Hash

Returns the response body as a Hash



49
50
51
52
# File 'lib/elastomer_client/client/repository.rb', line 49

def create(body, params = {})
  response = client.put "/_snapshot/{repository}", update_params(params, body:, action: "repository.create", rest_api: "snapshot.create_repository")
  response.body
end

#defaultsObject

Internal: Returns a Hash containing default parameters.



124
125
126
# File 'lib/elastomer_client/client/repository.rb', line 124

def defaults
  { repository: name }
end

#delete(params = {}) ⇒ Object

Delete the repository. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories

params - Parameters Hash

Returns the response body as a Hash



94
95
96
97
# File 'lib/elastomer_client/client/repository.rb', line 94

def delete(params = {})
  response = client.delete "/_snapshot/{repository}", update_params(params, action: "repository.delete", rest_api: "snapshot.delete_repository")
  response.body
end

#exists?(params = {}) ⇒ Boolean Also known as: exist?

Check for the existence of the repository. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories

params - Parameters Hash

Returns true if the repository exists

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
# File 'lib/elastomer_client/client/repository.rb', line 30

def exists?(params = {})
  response = client.get "/_snapshot{/repository}", update_params(params, action: "repository.exists", rest_api: "snapshot.get_repository")
  response.success?
rescue ElastomerClient::Client::Error => err
  if err.error && err.error.dig("root_cause", 0, "type") == "repository_missing_exception"
    false
  else
    raise err
  end
end

#get(params = {}) ⇒ Object

Get repository type and settings. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories

params - Parameters Hash

Returns the response body as a Hash



60
61
62
63
# File 'lib/elastomer_client/client/repository.rb', line 60

def get(params = {})
  response = client.get "/_snapshot{/repository}", update_params(params, action: "repository.get", rest_api: "snapshot.get_repository")
  response.body
end

#snapshot(snapshot = nil) ⇒ Object Also known as: snapshots

Provides access to snapshot API commands. These commands will be scoped to this repository and the given snapshot name.

snapshot - The snapshot name as a String, or nil for all snapshots.

Returns a Snapshot instance.



105
106
107
# File 'lib/elastomer_client/client/repository.rb', line 105

def snapshot(snapshot = nil)
  client.snapshot(name, snapshot)
end

#status(params = {}) ⇒ Object

Get status information on snapshots in progress. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories

params - Parameters Hash

Returns the response body as a Hash



71
72
73
74
# File 'lib/elastomer_client/client/repository.rb', line 71

def status(params = {})
  response = client.get "/_snapshot{/repository}/_status", update_params(params, action: "repository.status", rest_api: "snapshot.status")
  response.body
end

#update(body, params = {}) ⇒ Object

Update the repository. See www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html#_repositories

body - The repository type and settings as a Hash or a JSON encoded String params - Parameters Hash

Returns the response body as a Hash



83
84
85
86
# File 'lib/elastomer_client/client/repository.rb', line 83

def update(body, params = {})
  response = client.put "/_snapshot/{repository}", update_params(params, body:, action: "repository.update", rest_api: "snapshot.create_repository")
  response.body
end

#update_params(params, overrides = nil) ⇒ Object

Internal: Add default parameters to the ‘params` Hash and then apply `overrides` to the params if any are given.

params - Parameters Hash overrides - Optional parameter overrides as a Hash

Returns a new params Hash.



117
118
119
120
121
# File 'lib/elastomer_client/client/repository.rb', line 117

def update_params(params, overrides = nil)
  h = defaults.update params
  h.update overrides unless overrides.nil?
  h
end