etcdv3 0.3.2 → 0.4.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: 443472175a4cc4232c56f54afac01f0ca3bd1ae8
4
- data.tar.gz: 3e5a3264ddb63003b330133e1e2ed0bc4b51716e
3
+ metadata.gz: 5f86e90b466cc1cf9999d8f9cbf08f5df1e2ac86
4
+ data.tar.gz: f8f237e1253a7218dfba6eae660e1553f54b07f6
5
5
  SHA512:
6
- metadata.gz: 9d87445129496ab8919e580b652818a4f136f552e84215812a3a31348ae54f0eabe209bc09ce7a677fa9d8bb590e2c7657c324fb17158a1c84c950c55208bad2
7
- data.tar.gz: bb48f8937f5edcaf62231a1ed46c17af1c1a1f5a95735b3db100660d3b93450850bebada9830ea75cc51ba5ca3e1c67220d5d3341ed4d6ce3cc1782d59ae5ea6
6
+ metadata.gz: 57d227117a3f8f82ae8d2a6691ed3468d7c8faf0a071d12182b2980c7784c456277315fb9945931ffa9c81882da7c748c188635d6dddf172ddbd9cc1aaf380e3
7
+ data.tar.gz: f53b3f71bb23e3961eaef3858f7cf22b69182835072fc1936146cd88b9d499cd6ed118538945a274e694e392f28ca57ae5bc1e29c73111a350a30afeaba9e59a
data/README.md CHANGED
@@ -10,13 +10,13 @@ Ruby client for Etcd V3
10
10
  [RubyDocs](http://www.rubydoc.info/gems/etcdv3/0.1.1/Etcd)
11
11
 
12
12
  To install etcdv3, run the following command:
13
- ```
13
+ ```ruby
14
14
  gem install etcdv3
15
15
  ```
16
16
 
17
- **Establishing a connection**
17
+ ## Establishing a connection
18
18
 
19
- ```
19
+ ```ruby
20
20
  require 'etcdv3'
21
21
 
22
22
  # Insecure connection
@@ -32,8 +32,8 @@ conn = Etcdv3.new(url: 'https://hostname:port', user: "gary", password: "secret"
32
32
  # Coming soon...
33
33
  ```
34
34
 
35
- **Adding, Fetching and Deleting Keys**
36
- ```
35
+ ## Adding, Fetching and Deleting Keys
36
+ ```ruby
37
37
  # Put
38
38
  conn.put("my", "value")
39
39
 
@@ -50,8 +50,8 @@ conn = Etcdv3.new(url: 'https://hostname:port', user: "gary", password: "secret"
50
50
  conn.del('my', range_end: 'myyy')
51
51
  ```
52
52
 
53
- **User Management**
54
- ```
53
+ ## User Management
54
+ ```ruby
55
55
  # Add User
56
56
  conn.add_user('admin', 'secret')
57
57
 
@@ -62,8 +62,8 @@ conn.delete_user('admin')
62
62
  conn.user_list
63
63
  ```
64
64
 
65
- **Role Management**
66
- ```
65
+ ## Role Management
66
+ ```ruby
67
67
  # Add Role
68
68
  conn.add_role('rolename')
69
69
 
@@ -77,8 +77,8 @@ conn.delete_role('rolename')
77
77
  conn.role_list
78
78
  ```
79
79
 
80
- **Authentication Management**
81
- ```
80
+ ## Authentication Management
81
+ ```ruby
82
82
  # Configure a root user
83
83
  conn.add_user('root', 'mysecretpassword')
84
84
 
@@ -89,7 +89,7 @@ conn.grant_role_to_user('root', 'root')
89
89
  conn.enable_auth
90
90
  ```
91
91
  After you enable authentication, you must authenticate.
92
- ```
92
+ ```ruby
93
93
  # This will generate and assign an auth token that will be used in future requests.
94
94
  conn.authenticate('root', 'mysecretpassword')
95
95
  ```
@@ -98,8 +98,8 @@ Disabling auth will clear the auth token and all previously attached user inform
98
98
  conn.disable_auth
99
99
  ```
100
100
 
101
- **Leases**
102
- ```
101
+ ## Leases
102
+ ```ruby
103
103
  # Grant a lease with a 100 second TTL
104
104
  conn.grant_lease(100)
105
105
 
@@ -113,8 +113,25 @@ conn.lease_ttl(1234566789)
113
113
  conn.revoke_lease(1234566789)
114
114
  ```
115
115
 
116
- **Alarms**
116
+ ## Watch
117
+ ```ruby
118
+ # Watch for changes on a specified key and return
119
+ events = conn.watch('names')
120
+
121
+ # Watch for changes on a specified key range and return
122
+ events = conn.watch('boom', range_end: 'booooooom')
123
+
124
+ # Watches for changes continuously until killed.
125
+ event_count = 0
126
+ conn.watch('boom') do |events|
127
+ puts events
128
+ event_count = event_count + 1
129
+ break if event_count >= 10
130
+ end
117
131
  ```
132
+
133
+ ## Alarms
134
+ ```ruby
118
135
  # List all active Alarms
119
136
  conn.alarm_list
120
137
 
@@ -1,5 +1,3 @@
1
- require 'ostruct'
2
-
3
1
  class Etcdv3
4
2
  class Maintenance
5
3
  # Sadly these are the only alarm types supported by the api right now.
@@ -37,5 +37,9 @@ class Etcdv3
37
37
  @lease ||= Etcdv3::Lease.new(@hostname, @credentials, @metadata)
38
38
  end
39
39
 
40
+ def watch
41
+ @watch ||= Etcdv3::Watch.new(@hostname, @credentials, @metadata)
42
+ end
43
+
40
44
  end
41
45
  end
@@ -1,3 +1,3 @@
1
1
  class Etcdv3
2
- VERSION = '0.3.2'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -0,0 +1,26 @@
1
+ class Etcdv3
2
+ class Watch
3
+
4
+ def initialize(hostname, credentials, metadata = {})
5
+ @stub = Etcdserverpb::Watch::Stub.new(hostname, credentials)
6
+ @metadata = metadata
7
+ end
8
+
9
+ def watch(key, range_end, block)
10
+ create_req = Etcdserverpb::WatchCreateRequest.new(key: key, range_end: range_end)
11
+ watch_req = Etcdserverpb::WatchRequest.new(create_request: create_req)
12
+ events = nil
13
+ @stub.watch([watch_req]).each do |resp|
14
+ next if resp.events.empty?
15
+ if block
16
+ block.call(resp.events)
17
+ else
18
+ events = resp.events
19
+ break
20
+ end
21
+ end
22
+ events
23
+ end
24
+
25
+ end
26
+ end
data/lib/etcdv3.rb CHANGED
@@ -9,6 +9,7 @@ require 'etcdv3/kv'
9
9
  require 'etcdv3/maintenance'
10
10
  require 'etcdv3/lease'
11
11
  require 'etcdv3/request'
12
+ require 'etcdv3/watch'
12
13
 
13
14
  class Etcdv3
14
15
 
@@ -65,6 +66,11 @@ class Etcdv3
65
66
  request.handle(:maintenance, 'member_status').leader
66
67
  end
67
68
 
69
+ # Watches for changes on a specified key range.
70
+ def watch(key, range_end: '', &block)
71
+ request.handle(:watch, 'watch', [key, range_end, block])
72
+ end
73
+
68
74
  # List active alarms
69
75
  def alarm_list
70
76
  request.handle(:maintenance, 'alarms', [:get, leader_id])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etcdv3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun Davis
@@ -68,6 +68,7 @@ files:
68
68
  - lib/etcdv3/protos/rpc.proto
69
69
  - lib/etcdv3/request.rb
70
70
  - lib/etcdv3/version.rb
71
+ - lib/etcdv3/watch.rb
71
72
  - spec/etcdv3/auth_spec.rb
72
73
  - spec/etcdv3/kv_spec.rb
73
74
  - spec/etcdv3/lease_spec.rb