diplomat 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ea44efec4bbbbd7dcea08226f4c1e85ee3d0c74
4
- data.tar.gz: 686a774e0ff66b40516eb75f905a9ffb463e4317
3
+ metadata.gz: 445cf50cabc901de363e7692e3ab395c24fc0f16
4
+ data.tar.gz: e2977150c4927b89d3c4dedf415ed69d0a022fa4
5
5
  SHA512:
6
- metadata.gz: 96a3c918192148440c80515a0e49cadd8422ead23a814c12d9e21e66907654c6d07a6dbf5e6b1a33864165644245442eb0b36ac8fb9ac8a9acbc87d10e52cfb6
7
- data.tar.gz: 54a7dc66263f1dadb005e6ba4ef402551e5c5244d492d9f83e01d3dab27164384b865c98c451d4f25305a843542a23797b16bd32b3aea3b1cda1cb96099f79a1
6
+ metadata.gz: af47156e803a93218c018178b758e8dba6730156914f8c8eaabaf5d87d4b5f32db99352b5c1c95b5426c7a5f098b7991d7d79fe93ba282397d458892f2100c73
7
+ data.tar.gz: 953d8fd1908d93753588d907f0984ad98d6bb8365aebcc4c13fbe019c081398e207d89a11d8f7f2bf616868b758c71e48c83a3b84b4252906d2dee002e0089f0
data/README.md CHANGED
@@ -39,6 +39,10 @@ production:
39
39
 
40
40
  [See here](http://www.consul.io/intro/). I managed to roll it out on my production machines with the help of [Ansible](http://www.ansible.com/) in one working day.
41
41
 
42
+ ### Which versions of Ruby does Diplomat support?
43
+
44
+ Check out [Travis](https://travis-ci.org/WeAreFarmGeek/diplomat) to see which versions of ruby we currently test when we're making builds.
45
+
42
46
  ## Usage
43
47
 
44
48
  [The most up to date place to read about the API is here.](http://rubydoc.info/github/WeAreFarmGeek/diplomat)
@@ -82,6 +86,12 @@ Diplomat::Kv.get('foo/', recurse: true)
82
86
  # => [{:key=>"foo/a", :value=>"lorem"}, {:key=>"foo/b", :value=>"ipsum"}, {:key=>"foo/c", :value=>"dolor"}]
83
87
  ```
84
88
 
89
+ Or list all available keys:
90
+
91
+ ```ruby
92
+ Diplomat::Kv.get('/', :keys => true) # => ['foo/a', 'foo/b']
93
+ ```
94
+
85
95
  ### Nodes
86
96
 
87
97
  #### Getting
@@ -100,6 +110,13 @@ nodes = Diplomat::Node.get_all
100
110
  # => [#<OpenStruct Address="10.1.10.12", Node="foo">, #<OpenStruct Address="10.1.10.13", Node="bar">]
101
111
  ```
102
112
 
113
+ Get all nodes for a particular datacenter
114
+
115
+ ```ruby
116
+ nodes = Diplomat::Node.get_all({ :dc => 'My_Datacenter' })
117
+ # => [#<OpenStruct Address="10.1.10.12", Node="foo">, #<OpenStruct Address="10.1.10.13", Node="bar">]
118
+ ```
119
+
103
120
  Register a node:
104
121
 
105
122
  ```ruby
data/lib/diplomat.rb CHANGED
@@ -18,6 +18,8 @@ module Diplomat
18
18
  alias require_lib require_libs
19
19
  end
20
20
 
21
+ raise 'Diplomat only supports ruby >= 2.0.0' unless RUBY_VERSION.to_f >= 2.0
22
+
21
23
  self.root_path = File.expand_path "..", __FILE__
22
24
  self.lib_path = File.expand_path "../diplomat", __FILE__
23
25
 
data/lib/diplomat/acl.rb CHANGED
@@ -46,14 +46,8 @@ module Diplomat
46
46
  def list
47
47
  url = ["/v1/acl/list"]
48
48
  url += check_acl_token
49
- raw = @conn_no_err.get concat_url url
50
-
51
- if raw.status == 200
52
- @raw = raw
53
- return parse_body
54
- else
55
- raise Diplomat::UnknownStatus, "status #{raw.status}"
56
- end
49
+ @raw = @conn_no_err.get concat_url url
50
+ return parse_body
57
51
  end
58
52
 
59
53
  # Update an Acl definition, create if not present
@@ -69,7 +63,7 @@ module Diplomat
69
63
  req.url concat_url url
70
64
  req.body = value.to_json
71
65
  end
72
- JSON.parse(@raw.body)
66
+ return parse_body
73
67
  end
74
68
 
75
69
  # Create an Acl definition
@@ -83,7 +77,7 @@ module Diplomat
83
77
  req.url concat_url url
84
78
  req.body = value.to_json
85
79
  end
86
- JSON.parse(@raw.body)
80
+ return parse_body
87
81
  end
88
82
 
89
83
  # Destroy an ACl token by its id
@@ -94,7 +88,7 @@ module Diplomat
94
88
  url = ["/v1/acl/destroy/#{@id}"]
95
89
  url += check_acl_token
96
90
  @raw = @conn.put concat_url url
97
- @raw.body == "true"
91
+ return @raw.body == "true"
98
92
  end
99
93
  end
100
94
  end
@@ -76,13 +76,16 @@ module Diplomat
76
76
  when :reject
77
77
  raise Diplomat::EventAlreadyExists, name
78
78
  when :return
79
- parse_body
79
+ # Always set the response to 200 so we always return
80
+ # the response body.
81
+ @raw.status = 200
82
+ @raw = parse_body
80
83
  return return_payload
81
84
  end
82
85
  end
83
86
 
84
87
  @raw = wait_for_next_event(url)
85
- parse_body
88
+ @raw = parse_body
86
89
  return_payload
87
90
  end
88
91
 
@@ -130,7 +133,7 @@ module Diplomat
130
133
  event_token = :last
131
134
  when :wait
132
135
  @raw = wait_for_next_event(url)
133
- parse_body
136
+ @raw = parse_body
134
137
  # If it's possible for two events to arrive at once,
135
138
  # this needs to #find again:
136
139
  event = @raw.last
@@ -45,10 +45,12 @@ module Diplomat
45
45
  # Get service health
46
46
  # @param s [String] the service
47
47
  # @param options [Hash] :dc string for dc specific query
48
+ # @param options [Hash] :state string for specific service state
48
49
  # @return [OpenStruct] all data associated with the node
49
50
  def service s, options=nil
50
51
  url = ["/v1/health/service/#{s}"]
51
52
  url << use_named_parameter('dc', options[:dc]) if options and options[:dc]
53
+ url << options[:state] if options and options[:state]
52
54
 
53
55
  # If the request fails, it's probably due to a bad path
54
56
  # so return a PathNotFound error.
data/lib/diplomat/kv.rb CHANGED
@@ -74,7 +74,7 @@ module Diplomat
74
74
  raise Diplomat::KeyAlreadyExists, key
75
75
  when :return
76
76
  @raw = raw
77
- parse_body
77
+ @raw = parse_body
78
78
  if @options and @options[:modify_index]
79
79
  return @raw.first['ModifyIndex']
80
80
  end
data/lib/diplomat/node.rb CHANGED
@@ -29,11 +29,13 @@ module Diplomat
29
29
  end
30
30
 
31
31
  # Get all the nodes
32
+ # @param options [Hash] :dc string for dc specific query
32
33
  # @return [OpenStruct] the list of all nodes
33
- def get_all
34
- url = "/v1/catalog/nodes"
34
+ def get_all options=nil
35
+ url = ["/v1/catalog/nodes"]
36
+ url << use_named_parameter('dc', options[:dc]) if options and options[:dc]
35
37
  begin
36
- ret = @conn.get url
38
+ ret = @conn.get concat_url url
37
39
  rescue Faraday::ClientError
38
40
  raise Diplomat::PathNotFound
39
41
  end
@@ -71,7 +71,8 @@ module Diplomat
71
71
 
72
72
  # Parse the body, apply it to the raw attribute
73
73
  def parse_body
74
- @raw = JSON.parse(@raw.body)
74
+ return JSON.parse(@raw.body) if @raw.status == 200
75
+ raise Diplomat::UnknownStatus, "status #{@raw.status}"
75
76
  end
76
77
 
77
78
  # Return @raw with Value fields decoded
@@ -27,8 +27,8 @@ module Diplomat
27
27
  # so return a PathNotFound error.
28
28
  begin
29
29
  ret = @conn.get concat_url url
30
- rescue Faraday::ClientError
31
- raise Diplomat::PathNotFound
30
+ rescue Faraday::ClientError => e
31
+ raise Diplomat::PathNotFound, e
32
32
  end
33
33
 
34
34
  if meta and ret.headers
@@ -1,3 +1,3 @@
1
1
  module Diplomat
2
- VERSION = "0.18.0"
2
+ VERSION = "0.19.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diplomat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hamelink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-24 00:00:00.000000000 Z
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler