diplomatic_bag 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,75 +0,0 @@
1
- module Diplomat
2
- # Methods for interacting with the Consul session API endpoint
3
- class Session < Diplomat::RestClient
4
- @access_methods = %i[create destroy list renew info node]
5
-
6
- # Create a new session
7
- # @param value [Object] hash or json representation of the session arguments
8
- # @param options [Hash] session options
9
- # @return [String] The sesssion id
10
- def create(value = nil, options = {})
11
- # TODO: only certain keys are recognised in a session create request,
12
- # should raise an error on others.
13
- custom_params = []
14
- custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
15
- data = value.is_a?(String) ? value : JSON.generate(value) unless value.nil?
16
- raw = send_put_request(@conn, ['/v1/session/create'], options, data, custom_params)
17
- body = JSON.parse(raw.body)
18
- body['ID']
19
- end
20
-
21
- # Destroy a session
22
- # @param id [String] session id
23
- # @param options [Hash] session options
24
- # @return [String] Success or failure of the session destruction
25
- def destroy(id, options = {})
26
- custom_params = []
27
- custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
28
- raw = send_put_request(@conn, ["/v1/session/destroy/#{id}"], options, nil, custom_params)
29
- raw.body
30
- end
31
-
32
- # List sessions
33
- # @param options [Hash] session options
34
- # @return [OpenStruct]
35
- def list(options = {})
36
- custom_params = []
37
- custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
38
- raw = send_get_request(@conn, ['/v1/session/list'], options, custom_params)
39
- JSON.parse(raw.body).map { |session| OpenStruct.new session }
40
- end
41
-
42
- # Renew session
43
- # @param id [String] session id
44
- # @param options [Hash] session options
45
- # @return [OpenStruct]
46
- def renew(id, options = {})
47
- custom_params = []
48
- custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
49
- raw = send_put_request(@conn, ["/v1/session/renew/#{id}"], options, nil, custom_params)
50
- JSON.parse(raw.body).map { |session| OpenStruct.new session }
51
- end
52
-
53
- # Session information
54
- # @param id [String] session id
55
- # @param options [Hash] session options
56
- # @return [OpenStruct]
57
- def info(id, options = {})
58
- custom_params = []
59
- custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
60
- raw = send_get_request(@conn, ["/v1/session/info/#{id}"], options, custom_params)
61
- JSON.parse(raw.body).map { |session| OpenStruct.new session }
62
- end
63
-
64
- # Session information for a given node
65
- # @param name [String] node name
66
- # @param options [Hash] session options
67
- # @return [OpenStruct]
68
- def node(name, options = {})
69
- custom_params = []
70
- custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
71
- raw = send_get_request(@conn, ["/v1/session/node/#{name}"], options, custom_params)
72
- JSON.parse(raw.body).map { |session| OpenStruct.new session }
73
- end
74
- end
75
- end
@@ -1,22 +0,0 @@
1
- module Diplomat
2
- # Methods for interacting with the Consul status API endpoints, leader and peers
3
- class Status < Diplomat::RestClient
4
- @access_methods = %i[leader peers]
5
-
6
- # Get the raft leader for the datacenter in which the local consul agent is running
7
- # @param options [Hash] options parameter hash
8
- # @return [OpenStruct] the address of the leader
9
- def leader(options = {})
10
- ret = send_get_request(@conn, ['/v1/status/leader'], options)
11
- JSON.parse(ret.body)
12
- end
13
-
14
- # Get an array of Raft peers for the datacenter in which the agent is running
15
- # @param options [Hash] options parameter hash
16
- # @return [OpenStruct] an array of peers
17
- def peers(options = {})
18
- ret = send_get_request(@conn, ['/v1/status/peers'], options)
19
- JSON.parse(ret.body)
20
- end
21
- end
22
- end
@@ -1,3 +0,0 @@
1
- module Diplomat
2
- VERSION = '2.2.2'.freeze
3
- end
data/lib/diplomat.rb DELETED
@@ -1,62 +0,0 @@
1
- require 'json'
2
- require 'base64'
3
- require 'faraday'
4
-
5
- # Top level namespace ensures all required libraries are included and initializes the gem configration.
6
- module Diplomat
7
- class << self
8
- attr_accessor :root_path
9
- attr_accessor :lib_path
10
- attr_accessor :configuration
11
-
12
- # Internal: Requires internal Faraday libraries.
13
- # @param *libs One or more relative String names to Faraday classes.
14
- # @return [nil]
15
- def require_libs(*libs)
16
- libs.each do |lib|
17
- require "#{lib_path}/#{lib}"
18
- end
19
- end
20
-
21
- alias require_lib require_libs
22
- end
23
-
24
- raise 'Diplomat only supports ruby >= 2.0.0' unless RUBY_VERSION.to_f >= 2.0
25
-
26
- self.root_path = File.expand_path __dir__
27
- self.lib_path = File.expand_path 'diplomat', __dir__
28
-
29
- require_libs 'configuration', 'rest_client', 'kv', 'datacenter', 'service',
30
- 'members', 'node', 'nodes', 'check', 'health', 'session', 'lock',
31
- 'error', 'event', 'acl', 'maintenance', 'query', 'agent', 'status'
32
- self.configuration ||= Diplomat::Configuration.new
33
-
34
- class << self
35
- # Build optional configuration by yielding a block to configure
36
- # @yield [Diplomat::Configuration]
37
- def configure
38
- self.configuration ||= Diplomat::Configuration.new
39
- yield(configuration)
40
- end
41
-
42
- private
43
-
44
- # Send all other unknown commands to Diplomat::Kv
45
- # @deprecated Please use Diplomat::Kv instead.
46
- # @param name [Symbol] Method to send to Kv
47
- # @param *args List of arguments to send to Kv
48
- # @param &block block to send to Kv
49
- # @return [Object]
50
- def method_missing(name, *args, &block)
51
- Diplomat::Kv.new.send(name, *args, &block) || super
52
- end
53
-
54
- # Make `respond_to_missing?` fall back to super
55
- #
56
- # @param meth_id [Symbol] the tested method
57
- # @oaram with_private if private methods should be tested too
58
- def respond_to_missing?(meth_id, with_private = false)
59
- access_method?(meth_id) || super
60
- end
61
- end
62
- end