diplomat 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -6
- data/features/configuration.feature +9 -0
- data/features/step_definitions/setup_diplomat.rb +22 -0
- data/features/step_definitions/test_key_value.rb +9 -0
- data/lib/diplomat.rb +14 -11
- data/lib/diplomat/configuration.rb +18 -0
- data/lib/diplomat/rest_client.rb +4 -2
- data/lib/diplomat/version.rb +1 -1
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b0b78c3defb59f640674929aa84736f259b301d
|
4
|
+
data.tar.gz: 57dc6f99df3cb29304ac35a3c0154cdc3476bb25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5622c913dcec5213b2fb595ab1e9f9fc4d869502f9b95d7e1794980203511c000a16966e98d6a32abe7e77852f8308b4bf52031e8b19651518a832dc785dae3a
|
7
|
+
data.tar.gz: 0f2e7d0534fa3fd79a497a01b126b3b1251c3fb4a949d447c949bb8968c5e626e8963df0a70c8afd0864491e463e370fa3dd51d72c3ac7728970994e95ae86f6
|
data/README.md
CHANGED
@@ -73,16 +73,25 @@ Looking up a service is easy as pie:
|
|
73
73
|
|
74
74
|
```ruby
|
75
75
|
foo_service = Diplomat::Service.get('foo')
|
76
|
-
# => #<OpenStruct Node="hotel", Address="1.2.3.4", ServiceID="
|
76
|
+
# => #<OpenStruct Node="hotel", Address="1.2.3.4", ServiceID="hotel_foo", ServiceName="foo", ServiceTags=["foo"], ServicePort=5432>
|
77
|
+
```
|
78
|
+
Or if you have multiple nodes per service:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
foo_service = Diplomat::Service.get('foo', :all)
|
82
|
+
# => [#<OpenStruct Node="hotel", Address="1.2.3.4", ServiceID="hotel_foo", ServiceName="foo", ServiceTags=["foo"], ServicePort=5432>,#<OpenStruct Node="indigo", Address="1.2.3.5", ServiceID="indigo_foo", ServiceName="foo", ServiceTags=["foo"], ServicePort=5432>]
|
77
83
|
```
|
78
84
|
|
79
85
|
### Todo
|
80
86
|
|
81
|
-
-
|
82
|
-
-
|
83
|
-
-
|
84
|
-
-
|
85
|
-
-
|
87
|
+
- Updating docs with latest changes
|
88
|
+
- PUTting and DELETEing services
|
89
|
+
- Allowing the custom configuration of the consul url to connect to
|
90
|
+
- - ~~Deleting Keys~~ **Needs a test**
|
91
|
+
- ~~Listing available Services~~ **Done**
|
92
|
+
- ~~Health~~ **Done**
|
93
|
+
- ~~Members~~ **Done**
|
94
|
+
- ~~Status~~ **Done**
|
86
95
|
|
87
96
|
## Enjoy!
|
88
97
|
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Feature: Configuration
|
2
|
+
|
3
|
+
Scenario: I'm Setting up Diplomat with a default config
|
4
|
+
Given I am setting up a default diplomat
|
5
|
+
Then I should be able to get and put keys
|
6
|
+
|
7
|
+
Scenario: I'm Setting up Diplomat with a custom config
|
8
|
+
Given I am setting up a custom diplomat
|
9
|
+
Then I should be able to get and put keys
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'diplomat'
|
2
|
+
Given /^I am setting up a default diplomat$/ do
|
3
|
+
end
|
4
|
+
|
5
|
+
Given /^I am setting up a custom diplomat$/ do
|
6
|
+
class StubMiddleware
|
7
|
+
def initialize(app, options = {})
|
8
|
+
@app = app
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
def call(env)
|
12
|
+
@app.call(env)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
expect {
|
17
|
+
Diplomat.configure do |config|
|
18
|
+
config.url = "http://localhost:8500"
|
19
|
+
config.middleware = StubMiddleware
|
20
|
+
end
|
21
|
+
}.to_not raise_error
|
22
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Then /^I should be able to get and put keys$/ do
|
2
|
+
# High-fructose Corn Syrup
|
3
|
+
Diplomat.put('drink', 'Irn Bru')
|
4
|
+
expect(Diplomat.get('drink')).to eq("Irn Bru")
|
5
|
+
|
6
|
+
# Sugar
|
7
|
+
Diplomat::Kv.put('cake', 'Sponge')
|
8
|
+
expect(Diplomat::Kv.get('cake')).to eq('Sponge')
|
9
|
+
end
|
data/lib/diplomat.rb
CHANGED
@@ -4,7 +4,7 @@ module Diplomat
|
|
4
4
|
|
5
5
|
attr_accessor :root_path
|
6
6
|
attr_accessor :lib_path
|
7
|
-
attr_accessor :
|
7
|
+
attr_accessor :configuration
|
8
8
|
|
9
9
|
# Internal: Requires internal Faraday libraries.
|
10
10
|
# @param *libs One or more relative String names to Faraday classes.
|
@@ -15,23 +15,26 @@ module Diplomat
|
|
15
15
|
end
|
16
16
|
|
17
17
|
alias require_lib require_libs
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def method_missing(name, *args, &block)
|
22
|
-
Diplomat::Kv.new.send(name, *args, &block)
|
23
|
-
end
|
24
|
-
|
25
18
|
end
|
26
19
|
|
27
20
|
self.root_path = File.expand_path "..", __FILE__
|
28
21
|
self.lib_path = File.expand_path "../diplomat", __FILE__
|
29
22
|
|
30
|
-
|
31
|
-
self.
|
23
|
+
require_libs "configuration", "rest_client", "kv", "service", "members", "check", "health"
|
24
|
+
self.configuration ||= Diplomat::Configuration.new
|
32
25
|
|
26
|
+
class << self
|
33
27
|
|
28
|
+
# Build optional configuration by yielding a block to configure
|
29
|
+
def configure
|
30
|
+
self.configuration ||= Diplomat::Configuration.new
|
31
|
+
yield(configuration)
|
32
|
+
end
|
34
33
|
|
35
|
-
|
34
|
+
private
|
36
35
|
|
36
|
+
def method_missing(name, *args, &block)
|
37
|
+
Diplomat::Kv.new.send(name, *args, &block)
|
38
|
+
end
|
39
|
+
end
|
37
40
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Diplomat
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :middleware
|
4
|
+
attr_accessor :url
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@middleware = []
|
8
|
+
@url = "http://localhost:8500"
|
9
|
+
end
|
10
|
+
|
11
|
+
def middleware=(middleware)
|
12
|
+
return @middleware = middleware if middleware.is_a? Array
|
13
|
+
@middleware = [middleware]
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
data/lib/diplomat/rest_client.rb
CHANGED
@@ -13,9 +13,11 @@ module Diplomat
|
|
13
13
|
# Build the API Client
|
14
14
|
# @param api_connection [Faraday::Connection,nil] supply mock API Connection
|
15
15
|
def start_connection api_connection=nil
|
16
|
-
@conn = api_connection ||= Faraday.new(:url => Diplomat
|
16
|
+
@conn = api_connection ||= Faraday.new(:url => Diplomat.configuration.url) do |faraday|
|
17
17
|
faraday.request :url_encoded
|
18
|
-
|
18
|
+
Diplomat.configuration.middleware.each do |middleware|
|
19
|
+
faraday.use middleware
|
20
|
+
end
|
19
21
|
faraday.adapter Faraday.default_adapter
|
20
22
|
faraday.use Faraday::Response::RaiseError
|
21
23
|
end
|
data/lib/diplomat/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hamelink
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0.7'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: cucumber
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.3'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.3'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: json
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -159,8 +173,12 @@ extra_rdoc_files: []
|
|
159
173
|
files:
|
160
174
|
- LICENSE
|
161
175
|
- README.md
|
176
|
+
- features/configuration.feature
|
177
|
+
- features/step_definitions/setup_diplomat.rb
|
178
|
+
- features/step_definitions/test_key_value.rb
|
162
179
|
- lib/diplomat.rb
|
163
180
|
- lib/diplomat/check.rb
|
181
|
+
- lib/diplomat/configuration.rb
|
164
182
|
- lib/diplomat/health.rb
|
165
183
|
- lib/diplomat/kv.rb
|
166
184
|
- lib/diplomat/members.rb
|
@@ -192,4 +210,3 @@ signing_key:
|
|
192
210
|
specification_version: 4
|
193
211
|
summary: Diplomat is a simple wrapper for Consul
|
194
212
|
test_files: []
|
195
|
-
has_rdoc:
|