Module: Consulkit::Client::Session

Included in:
Consulkit::Client
Defined in:
lib/consulkit/client/session.rb

Overview

Methods for creating, deleting, and querying sessions.

Instance Method Summary collapse

Instance Method Details

#session_create(session_opts = {}) ⇒ Object

Creates a session.

Examples:

Create a session with a 60 second TTL and the ‘delete’ behavior.

session_create(ttl: "60s", behavior: 'delete')

Parameters:

  • session_opts (Hash) (defaults to: {})

    options to create the session with.

Options Hash (session_opts):

  • :lock_delay (String)
  • :node (String)
  • :name (String)
  • :node_checks (Array<String>)
  • :service_checks (Array<Hash>)
  • :behavior (String)
  • :ttl (String)

Returns:

  • String the ID of the created session.

See Also:



25
26
27
# File 'lib/consulkit/client/session.rb', line 25

def session_create(session_opts = {})
  put('/v1/session/create', camel_case_keys(session_opts)).body['ID']
end

#session_delete(session_id) ⇒ Boolean

Deletes a session.

Parameters:

  • session_id (String)

    the ID of the session to delete.

Returns:

  • (Boolean)


34
35
36
# File 'lib/consulkit/client/session.rb', line 34

def session_delete(session_id)
  put("/v1/session/destroy/#{session_id}").body == true
end

#session_read(session_id) ⇒ Hash

Reads a session.

Parameters:

  • session_id (String)

    the ID of the session to read.

Returns:

  • (Hash)


43
44
45
# File 'lib/consulkit/client/session.rb', line 43

def session_read(session_id)
  get("/v1/session/info/#{session_id}").body.first
end

#session_renew(session_id) ⇒ Hash

Renews a session.

Parameters:

  • session_id (String)

    the ID of the session to renew.

Returns:

  • (Hash)


52
53
54
# File 'lib/consulkit/client/session.rb', line 52

def session_renew(session_id)
  put("/v1/session/renew/#{session_id}").body.first
end