routemaster-client 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +3 -3
- data/CHANGELOG.md +19 -2
- data/Gemfile.lock +32 -30
- data/README.md +103 -12
- data/exe/rtm +11 -0
- data/routemaster-client.gemspec +5 -0
- data/routemaster/cli/base.rb +134 -0
- data/routemaster/cli/helper.rb +61 -0
- data/routemaster/cli/pub.rb +23 -0
- data/routemaster/cli/sub.rb +78 -0
- data/routemaster/cli/token.rb +52 -0
- data/routemaster/cli/top_level.rb +48 -0
- data/routemaster/client.rb +49 -22
- data/routemaster/client/backends/sidekiq/worker.rb +11 -1
- data/routemaster/client/configuration.rb +6 -0
- data/routemaster/client/connection.rb +10 -4
- data/routemaster/client/errors.rb +1 -0
- data/routemaster/client/subscription.rb +32 -0
- data/routemaster/client/topic.rb +22 -0
- data/routemaster/client/version.rb +1 -1
- data/spec/cli/pub_spec.rb +21 -0
- data/spec/cli/sub_spec.rb +61 -0
- data/spec/cli/token_spec.rb +50 -0
- data/spec/client/subscription_spec.rb +19 -0
- data/spec/{topic_spec.rb → client/topic_spec.rb} +2 -2
- data/spec/client_spec.rb +134 -56
- data/spec/spec_helper.rb +28 -0
- metadata +39 -8
- data/routemaster/topic.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f38e0d37b7b2438fdc823e0df9d08ae2a45df05
|
4
|
+
data.tar.gz: 9ebb5aacf9ac9cf1e806f29b8908fb1f2b1c13a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d9ae9d682feb8add9c4946e9fd2a8e1a2f803a6d6cd7802d255498df54f02ad763dd9f90f9a65ae6cbbaccc5f48efb2116ad05f9ba76348bdd7c036b36da74c
|
7
|
+
data.tar.gz: d02d9fd0b1cff7ccba425bc67efb38cd14e0a41cadea41c8d2ed28e3df0ffcd09b5e876148942f4a2fc8f4351859aad28c7e4868ae33937eb859214b94df34bb
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.1
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
|
-
|
1
|
+
## 3.1.1 (2017-08-15)
|
2
2
|
|
3
|
-
Features:
|
3
|
+
Features:
|
4
|
+
|
5
|
+
- Adds the `rtm` command-line API wrapper (#24)
|
6
|
+
- Adds the `#monitor_subscriptions` API (#17)
|
7
|
+
|
8
|
+
Changes:
|
9
|
+
|
10
|
+
- The `Routemaster::Topic` value object class is not namespaced as
|
11
|
+
`Routemaster::Client::Topic` (#17)
|
12
|
+
|
13
|
+
Bug fixes:
|
14
|
+
|
15
|
+
- Always send a timestamp when sending asynchronously (#20)
|
16
|
+
- Sidekiq 5 compatibility (#22)
|
17
|
+
|
18
|
+
## 3.1.0 (2017-03-28)
|
19
|
+
|
20
|
+
Features:
|
4
21
|
|
5
22
|
- Adds support for event payloads (#16)
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
routemaster-client (3.1.
|
4
|
+
routemaster-client (3.1.1)
|
5
5
|
faraday (>= 0.9.0)
|
6
|
+
hashie
|
6
7
|
oj (~> 2.17)
|
7
8
|
typhoeus (~> 1.1)
|
8
9
|
wisper (~> 1.6.1)
|
@@ -10,7 +11,7 @@ PATH
|
|
10
11
|
GEM
|
11
12
|
remote: https://rubygems.org/
|
12
13
|
specs:
|
13
|
-
addressable (2.5.
|
14
|
+
addressable (2.5.1)
|
14
15
|
public_suffix (~> 2.0, >= 2.0.2)
|
15
16
|
byebug (9.0.6)
|
16
17
|
codeclimate-test-reporter (1.0.8)
|
@@ -24,7 +25,7 @@ GEM
|
|
24
25
|
docile (1.1.5)
|
25
26
|
ethon (0.10.1)
|
26
27
|
ffi (>= 1.3.0)
|
27
|
-
faraday (0.
|
28
|
+
faraday (0.12.2)
|
28
29
|
multipart-post (>= 1.2, < 3)
|
29
30
|
ffi (1.9.18)
|
30
31
|
formatador (0.2.5)
|
@@ -42,20 +43,21 @@ GEM
|
|
42
43
|
guard (~> 2.1)
|
43
44
|
guard-compat (~> 1.1)
|
44
45
|
rspec (>= 2.99.0, < 4.0)
|
45
|
-
hashdiff (0.3.
|
46
|
-
|
46
|
+
hashdiff (0.3.4)
|
47
|
+
hashie (3.5.6)
|
48
|
+
json (2.1.0)
|
47
49
|
listen (3.1.5)
|
48
50
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
49
51
|
rb-inotify (~> 0.9, >= 0.9.7)
|
50
52
|
ruby_dep (~> 1.2)
|
51
|
-
lumberjack (1.0.
|
53
|
+
lumberjack (1.0.12)
|
52
54
|
method_source (0.8.2)
|
53
55
|
multipart-post (2.0.0)
|
54
56
|
nenv (0.3.0)
|
55
57
|
notiffany (0.1.1)
|
56
58
|
nenv (~> 0.1)
|
57
59
|
shellany (~> 0.0)
|
58
|
-
oj (2.18.
|
60
|
+
oj (2.18.5)
|
59
61
|
pry (0.10.4)
|
60
62
|
coderay (~> 1.1.0)
|
61
63
|
method_source (~> 0.8.1)
|
@@ -65,47 +67,47 @@ GEM
|
|
65
67
|
pry (~> 0.10)
|
66
68
|
psych (2.2.4)
|
67
69
|
public_suffix (2.0.5)
|
68
|
-
rack (2.0.
|
69
|
-
rack-protection (
|
70
|
+
rack (2.0.3)
|
71
|
+
rack-protection (2.0.0)
|
70
72
|
rack
|
71
|
-
rack-test (0.
|
72
|
-
rack (>= 1.0)
|
73
|
+
rack-test (0.7.0)
|
74
|
+
rack (>= 1.0, < 3)
|
73
75
|
rake (12.0.0)
|
74
|
-
rb-fsevent (0.
|
75
|
-
rb-inotify (0.9.
|
76
|
-
ffi (>= 0.5.0)
|
76
|
+
rb-fsevent (0.10.2)
|
77
|
+
rb-inotify (0.9.10)
|
78
|
+
ffi (>= 0.5.0, < 2)
|
77
79
|
redis (3.3.3)
|
78
|
-
rspec (3.
|
79
|
-
rspec-core (~> 3.
|
80
|
-
rspec-expectations (~> 3.
|
81
|
-
rspec-mocks (~> 3.
|
82
|
-
rspec-core (3.
|
83
|
-
rspec-support (~> 3.
|
84
|
-
rspec-expectations (3.
|
80
|
+
rspec (3.6.0)
|
81
|
+
rspec-core (~> 3.6.0)
|
82
|
+
rspec-expectations (~> 3.6.0)
|
83
|
+
rspec-mocks (~> 3.6.0)
|
84
|
+
rspec-core (3.6.0)
|
85
|
+
rspec-support (~> 3.6.0)
|
86
|
+
rspec-expectations (3.6.0)
|
85
87
|
diff-lcs (>= 1.2.0, < 2.0)
|
86
|
-
rspec-support (~> 3.
|
87
|
-
rspec-mocks (3.
|
88
|
+
rspec-support (~> 3.6.0)
|
89
|
+
rspec-mocks (3.6.0)
|
88
90
|
diff-lcs (>= 1.2.0, < 2.0)
|
89
|
-
rspec-support (~> 3.
|
90
|
-
rspec-support (3.
|
91
|
+
rspec-support (~> 3.6.0)
|
92
|
+
rspec-support (3.6.0)
|
91
93
|
ruby_dep (1.5.0)
|
92
94
|
safe_yaml (1.0.4)
|
93
95
|
shellany (0.0.1)
|
94
|
-
sidekiq (
|
96
|
+
sidekiq (5.0.4)
|
95
97
|
concurrent-ruby (~> 1.0)
|
96
98
|
connection_pool (~> 2.2, >= 2.2.0)
|
97
99
|
rack-protection (>= 1.5.0)
|
98
|
-
redis (~> 3.
|
100
|
+
redis (~> 3.3, >= 3.3.3)
|
99
101
|
simplecov (0.13.0)
|
100
102
|
docile (~> 1.1.0)
|
101
103
|
json (>= 1.8, < 3)
|
102
104
|
simplecov-html (~> 0.10.0)
|
103
|
-
simplecov-html (0.10.
|
105
|
+
simplecov-html (0.10.1)
|
104
106
|
slop (3.6.0)
|
105
107
|
thor (0.19.4)
|
106
108
|
typhoeus (1.1.2)
|
107
109
|
ethon (>= 0.9.0)
|
108
|
-
webmock (
|
110
|
+
webmock (3.0.1)
|
109
111
|
addressable (>= 2.3.6)
|
110
112
|
crack (>= 0.3.2)
|
111
113
|
hashdiff
|
@@ -128,4 +130,4 @@ DEPENDENCIES
|
|
128
130
|
webmock
|
129
131
|
|
130
132
|
BUNDLED WITH
|
131
|
-
1.
|
133
|
+
1.15.3
|
data/README.md
CHANGED
@@ -1,25 +1,20 @@
|
|
1
1
|
## routemaster-client [![Version](https://badge.fury.io/rb/routemaster-client.svg)](https://rubygems.org/gems/routemaster-client) [![Build](https://travis-ci.org/deliveroo/routemaster-client.svg?branch=master)](https://travis-ci.org/deliveroo/routemaster-client) [![Code Climate](https://codeclimate.com/github/deliveroo/routemaster-client/badges/gpa.svg)](https://codeclimate.com/github/deliveroo/routemaster-client) [![Test Coverage](https://codeclimate.com/github/deliveroo/routemaster-client/badges/coverage.svg)](https://codeclimate.com/github/deliveroo/routemaster-client/coverage) [![Docs](http://img.shields.io/badge/API%20docs-rubydoc.info-blue.svg)](http://rubydoc.info/github/deliveroo/routemaster-client/frames/file/README.md)
|
2
2
|
|
3
|
-
A Ruby API for the
|
4
|
-
bus.
|
3
|
+
A Ruby API and CLI for the
|
4
|
+
[Routemaster](https://github.com/deliveroo/routemaster) event bus.
|
5
5
|
|
6
|
+
[Installation](#installation) | [Library usage](#library-usage) | [CLI usage](#cli-usage)
|
6
7
|
|
7
8
|
|
8
9
|
## Installation
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
gem 'routemaster-client'
|
13
|
-
|
14
|
-
And then execute:
|
11
|
+
gem install routemaster-client
|
15
12
|
|
16
|
-
|
13
|
+
## Library usage
|
17
14
|
|
18
|
-
|
19
|
-
|
20
|
-
$ gem install routemaster-client
|
15
|
+
Add this line to your application's Gemfile:
|
21
16
|
|
22
|
-
|
17
|
+
gem 'routemaster-client'
|
23
18
|
|
24
19
|
**Configure** your client:
|
25
20
|
|
@@ -128,6 +123,102 @@ Routemaster::Client.monitor_subscriptions
|
|
128
123
|
# } ... ]
|
129
124
|
```
|
130
125
|
|
126
|
+
## CLI usage
|
127
|
+
|
128
|
+
This gem includes the `rtm` binary, which can be used to interact with a
|
129
|
+
Routemaster bus.
|
130
|
+
|
131
|
+
### Commands
|
132
|
+
|
133
|
+
```
|
134
|
+
rtm token add [options] SERVICE TOKEN
|
135
|
+
```
|
136
|
+
|
137
|
+
Adds `TOKEN` to the list of API tokens permitted to use the bus API. `SERVICE`
|
138
|
+
is a human-readable name for this token.
|
139
|
+
|
140
|
+
```
|
141
|
+
rtm token del [options] TOKEN
|
142
|
+
```
|
143
|
+
|
144
|
+
Removes `TOKEN` from permitted tokens if it exists.
|
145
|
+
|
146
|
+
```
|
147
|
+
rtm token list [options]
|
148
|
+
```
|
149
|
+
|
150
|
+
Lists currently permitted API tokens.
|
151
|
+
|
152
|
+
```
|
153
|
+
rtm sub add [options] URL TOPICS... [--latency MS] [--batch-size COUNT]
|
154
|
+
```
|
155
|
+
|
156
|
+
Adds (or updates) a subscription. Note that the `TOKEN` passed in `option` must be
|
157
|
+
that of the subscriber, not a root token.
|
158
|
+
|
159
|
+
- `URL` must be HTTPS and include an authentication username (used by the bus
|
160
|
+
when delivering events).
|
161
|
+
- `TOPICS` is a list of topic names.
|
162
|
+
- `MS`, if specified, is the target delivery latency for this subscriber (ie.
|
163
|
+
how long to buffer events).
|
164
|
+
- `COUNT`, if specified, is the maximum number of events in a delivered batch.
|
165
|
+
|
166
|
+
```
|
167
|
+
rtm sub del [options] [TOPICS]
|
168
|
+
```
|
169
|
+
|
170
|
+
Updates or removes a subscription. Note that the `TOKEN` passed in `option` must
|
171
|
+
be that of the subscriber, not a root token. If no `TOPICS` are specified, the
|
172
|
+
subscription is entirely removed.
|
173
|
+
|
174
|
+
```
|
175
|
+
rtm sub list [options]
|
176
|
+
```
|
177
|
+
|
178
|
+
List existing subscriptions.
|
179
|
+
|
180
|
+
```
|
181
|
+
rtm pub [options] EVENT TOPIC URL
|
182
|
+
```
|
183
|
+
|
184
|
+
Publishes an event to the bus. Note that the `TOKEN` passed in `option` must
|
185
|
+
be that of the subscriber, not a root token. `EVENT` must be one of `created`,
|
186
|
+
`updated`, `deleted`, or `noop`. `TOPIC` must be a valid topic name. `URL` must
|
187
|
+
be a valid HTTPS URL.
|
188
|
+
|
189
|
+
|
190
|
+
### Global options
|
191
|
+
|
192
|
+
```
|
193
|
+
-b|--bus DOMAIN|@NAME
|
194
|
+
```
|
195
|
+
|
196
|
+
The domain names of the bus to interact with, or a reference (`NAME`) to global
|
197
|
+
configuration.
|
198
|
+
|
199
|
+
Note that `DOMAIN` is _not_ a URL.
|
200
|
+
|
201
|
+
```
|
202
|
+
-t|--token TOKEN
|
203
|
+
```
|
204
|
+
|
205
|
+
An API token to use when querying the bus.
|
206
|
+
|
207
|
+
|
208
|
+
`rtm` will load a configuration file in Yaml format (`.rtmrc` or `~/.rtmrc`).
|
209
|
+
Example:
|
210
|
+
|
211
|
+
```
|
212
|
+
# .rtmrc
|
213
|
+
production:
|
214
|
+
bus: prod.bus.example.com
|
215
|
+
token: 2bf959d1-04fb-4912-8450-ab646888d476
|
216
|
+
```
|
217
|
+
|
218
|
+
With this configuration, `rtm token list -b @production` will list API tokens
|
219
|
+
for the bus at the domain specified in the config.
|
220
|
+
|
221
|
+
|
131
222
|
## Contributing
|
132
223
|
|
133
224
|
1. Fork it ( http://github.com/deliveroo/routemaster-client/fork )
|
data/exe/rtm
ADDED
data/routemaster-client.gemspec
CHANGED
@@ -16,8 +16,13 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.test_files = spec.files.grep(%r{^spec/})
|
17
17
|
spec.require_paths = %w(.)
|
18
18
|
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
|
19
22
|
spec.add_runtime_dependency 'typhoeus', '~> 1.1'
|
20
23
|
spec.add_runtime_dependency 'faraday', '>= 0.9.0'
|
21
24
|
spec.add_runtime_dependency 'wisper', '~> 1.6.1'
|
22
25
|
spec.add_runtime_dependency 'oj', '~> 2.17'
|
26
|
+
|
27
|
+
spec.add_runtime_dependency 'hashie'
|
23
28
|
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'routemaster/cli/helper'
|
2
|
+
require 'optparse'
|
3
|
+
require 'hashie'
|
4
|
+
|
5
|
+
module Routemaster
|
6
|
+
module CLI
|
7
|
+
class Base
|
8
|
+
def self.inherited(by)
|
9
|
+
by.extend(ClassMethods)
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def prefix(ary = nil)
|
14
|
+
@prefix ||= ary
|
15
|
+
end
|
16
|
+
|
17
|
+
def syntax(string = nil)
|
18
|
+
string ? (@syntax = string) : ['rtm', *@prefix, @syntax, '[options]'].compact.join(' ')
|
19
|
+
end
|
20
|
+
|
21
|
+
def descr(string = nil)
|
22
|
+
string ? (@descr = string) : @descr
|
23
|
+
end
|
24
|
+
|
25
|
+
def defaults(hash = nil)
|
26
|
+
hash ? (@defaults = hash) : (@defaults || {})
|
27
|
+
end
|
28
|
+
|
29
|
+
def options(&block)
|
30
|
+
block_given? ? (@options = block) : @options
|
31
|
+
end
|
32
|
+
|
33
|
+
def action(&block)
|
34
|
+
block_given? ? (@action = block) : @action || lambda { |*| }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize(stderr:, stdout:)
|
39
|
+
@stderr = stderr
|
40
|
+
@stdout = stdout
|
41
|
+
end
|
42
|
+
|
43
|
+
def run(argv)
|
44
|
+
@argv = argv
|
45
|
+
_parser.parse!(@argv)
|
46
|
+
instance_eval(&self.class.action)
|
47
|
+
rescue Exit
|
48
|
+
raise
|
49
|
+
rescue StandardError => e
|
50
|
+
log "#{e.class.name}: #{e.message}"
|
51
|
+
if config.verbose
|
52
|
+
e.backtrace.each { |l| log "\t#{l}" }
|
53
|
+
end
|
54
|
+
raise Exit, 2
|
55
|
+
end
|
56
|
+
|
57
|
+
protected
|
58
|
+
|
59
|
+
def argv
|
60
|
+
@argv || []
|
61
|
+
end
|
62
|
+
|
63
|
+
def config
|
64
|
+
@config ||= Hashie::Mash.new(_default_options).merge(self.class.defaults)
|
65
|
+
end
|
66
|
+
|
67
|
+
def helper
|
68
|
+
Helper.new(config)
|
69
|
+
end
|
70
|
+
|
71
|
+
def log(message)
|
72
|
+
@stderr.puts(message)
|
73
|
+
end
|
74
|
+
|
75
|
+
def puts(message)
|
76
|
+
@stdout.puts(message)
|
77
|
+
end
|
78
|
+
|
79
|
+
def usage!
|
80
|
+
log "Usage:"
|
81
|
+
log _parser
|
82
|
+
raise Exit, 1
|
83
|
+
end
|
84
|
+
|
85
|
+
def bad_argc!
|
86
|
+
log "Wrong number of arguments."
|
87
|
+
usage!
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def _default_options
|
93
|
+
{ verbose: false }
|
94
|
+
end
|
95
|
+
|
96
|
+
def _parser
|
97
|
+
@parser ||= OptionParser.new do |p|
|
98
|
+
p.banner = self.class.syntax
|
99
|
+
p.separator self.class.descr
|
100
|
+
|
101
|
+
if self.class.options
|
102
|
+
p.separator 'Options:'
|
103
|
+
self.class.options.call(p)
|
104
|
+
end
|
105
|
+
|
106
|
+
p.separator 'Common options:'
|
107
|
+
|
108
|
+
p.on('-b', '--bus DOMAIN|@NAME', %{
|
109
|
+
The domain name of the bus to interact with, or a reference (`NAME`)
|
110
|
+
to global configuration.
|
111
|
+
}) do |v|
|
112
|
+
config.bus = v
|
113
|
+
end
|
114
|
+
|
115
|
+
p.on('-t', '--token TOKEN', %{
|
116
|
+
An API token to use when querying the bus.
|
117
|
+
}) do |v|
|
118
|
+
config.token = v
|
119
|
+
end
|
120
|
+
|
121
|
+
p.on('-v', '--verbose', %{
|
122
|
+
Increase logging verbosity
|
123
|
+
}) do
|
124
|
+
config.verbose = true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def _description
|
130
|
+
self.class.descr.split(/\n/).map(&:strip).reject(&:empty?).join("\n")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|