consul-ruby-client 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ require_relative 'base'
2
+
3
+ module Consul
4
+ module Client
5
+ class Status
6
+ include Consul::Client::Base
7
+
8
+ # Public: This endpoint is used to get the Raft leader for the
9
+ # datacenter in which the agent is running
10
+ #
11
+ # Reference: https://www.consul.io/docs/agent/http/status.html
12
+ #
13
+ # Returns: Address, host:port.
14
+ def leader
15
+ RestClient.get leader_url
16
+ end
17
+
18
+ # Public: This endpoint retrieves the Raft peers for the
19
+ # datacenter in which the the agent is running
20
+ #
21
+ # Reference: https://www.consul.io/docs/agent/http/status.html
22
+ #
23
+ # Returns: List of addresses.
24
+ def peers
25
+ RestClient.get peers_url
26
+ end
27
+
28
+ def build_url(suffix)
29
+ "#{base_versioned_url}/status/#{suffix}"
30
+ end
31
+
32
+ private
33
+
34
+ def peers_url
35
+ build_url('peers')
36
+ end
37
+
38
+ def leader_url
39
+ build_url('leader')
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ module Consul
2
+ module Client
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+ require 'representable/json'
2
+ require 'ostruct'
3
+
4
+ module Consul
5
+ module Model
6
+
7
+ # Consul Health Check
8
+ #
9
+ # Reference: https://www.consul.io/docs/agent/checks.html
10
+ #
11
+ class HealthCheck < OpenStruct
12
+ module Representer
13
+ include Representable::JSON
14
+ include Representable::Hash
15
+ include Representable::Hash::AllowSymbols
16
+
17
+ # Property Common for registering and reading
18
+ property :name, as: :Name
19
+ property :notes, as: :Notes
20
+
21
+ # Properties used for registration
22
+ property :id, as: :ID
23
+ property :script, as: :Script
24
+ property :http, as: :HTTP
25
+ property :interval, as: :Interval
26
+ property :ttl, as: :TTL
27
+
28
+ # Properties used for reading.
29
+ property :node, as: :Node
30
+ property :check_id, as: :CheckID
31
+ property :status, as: :Status
32
+ property :output, as: :Output
33
+ property :service_id, as: :ServiceID
34
+ property :service_name, as: :ServiceName
35
+ end
36
+ extend Representer
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,28 @@
1
+ require 'representable/json'
2
+ require 'ostruct'
3
+
4
+ module Consul
5
+ module Model
6
+
7
+ # Consul Key Value representation
8
+ #
9
+ # Reference: https://www.consul.io/intro/getting-started/kv.html
10
+ #
11
+ class KeyValue < OpenStruct
12
+ module Representer
13
+ include Representable::JSON
14
+ include Representable::Hash
15
+ include Representable::Hash::AllowSymbols
16
+
17
+ property :create_index, as: :CreateIndex
18
+ property :modify_index, as: :ModifyIndex
19
+ property :lock_index, as: :LockIndex
20
+ property :key, as: :Key
21
+ property :flags, as: :Flags
22
+ property :value, as: :Value
23
+ property :session, as: :Session
24
+ end
25
+ extend Representer
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ require 'representable/json'
2
+ require 'ostruct'
3
+
4
+ module Consul
5
+ module Model
6
+
7
+ # Consul Node Representation.
8
+ class Node < OpenStruct
9
+ module Representer
10
+ include Representable::JSON
11
+ include Representable::Hash
12
+ include Representable::Hash::AllowSymbols
13
+
14
+ property :node, as: :Node
15
+ property :address, as: :Address
16
+ property :service_id, as: :ServiceID
17
+ property :service_name, as: :ServiceName
18
+ property :service_tags, as: :ServiceTags
19
+ property :service_address, as: :ServiceAddress
20
+ property :service_port, as: :ServicePort
21
+ end
22
+ extend Representer
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ require 'representable/json'
2
+ require 'ostruct'
3
+ require_relative 'health_check'
4
+
5
+ module Consul
6
+ module Model
7
+
8
+ # Consul Service Representation.
9
+ class Service < OpenStruct
10
+ module Representer
11
+ include Representable::JSON
12
+ include Representable::Hash
13
+ include Representable::Hash::AllowSymbols
14
+
15
+ # Attributes that can be both configured as well read.
16
+ property :id, as: :ID
17
+ property :service, as: :Service
18
+ property :tags, as: :Tags
19
+ property :address, as: :Address
20
+ property :port, as: :Port
21
+
22
+ # Attributes only defined at initialization time
23
+ property :name, as: :Name
24
+ property :check, as: :Check, extend: Consul::Model::HealthCheck::Representer, class: Consul::Model::HealthCheck
25
+ end
26
+ extend Representer
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'representable/json'
2
+ require 'ostruct'
3
+
4
+ module Consul
5
+ module Model
6
+
7
+ # Consul Session representation.
8
+ class Session < OpenStruct
9
+ module Representer
10
+ include Representable::JSON
11
+ include Representable::Hash
12
+ include Representable::Hash::AllowSymbols
13
+
14
+ # Properties that are intended to be written by clients.
15
+ property :lock_delay, as: :LockDelay
16
+ property :name, as: :Name
17
+ property :node, as: :Node
18
+ collection :checks, as: :Checks
19
+ property :behaviour, as: :Behavior
20
+ property :ttl, as: :TTL
21
+
22
+ # Properties that exclusively read access.
23
+ property :id, as: :ID
24
+ property :create_index, as: :CreateIndex
25
+ end
26
+ extend Representer
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+
3
+ module Consul
4
+ class Utils
5
+
6
+ # Public verify this is valid json
7
+ def self.valid_json?(json)
8
+ begin
9
+ JSON.parse(json)
10
+ return true
11
+ rescue Exception => e
12
+ return false
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Consul::Client::Base do
4
+
5
+ before :all do
6
+ # Create a temporary directory that will be cleaned up
7
+ # dir = Dir.mktmpdir('consul-client4r-test', Dir.tmpdir)
8
+ # @pid = Process.spawn("consul agent --server -data-dir=#{dir}")
9
+ end
10
+
11
+ after :all do
12
+ # Detach process and then kill it.
13
+ # Process.detach(@pid)
14
+ # Process.kill(:SIGINT, @pid)
15
+ end
16
+
17
+ class BaseApiImpl
18
+ include Consul::Client::Base
19
+ end
20
+
21
+ it 'should be reachable' do
22
+ expect(BaseApiImpl.new.is_reachable).to eq(true)
23
+ end
24
+
25
+ end
@@ -0,0 +1,13 @@
1
+ require 'tmpdir'
2
+ require 'simplecov'
3
+
4
+ SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter]
5
+
6
+ SimpleCov.start do
7
+ add_filter '/spec/'
8
+ # minimum_coverage(99.61)
9
+ end
10
+
11
+ require 'consul/client'
12
+
13
+
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: consul-ruby-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Michael Hotan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.21'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.21'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rest-client
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.6'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: representable
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.1'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: json
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.8'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.8'
125
+ description: Consul agents expose a HTTP REST API and this library is used to communicate
126
+ directly with it.
127
+ email:
128
+ - michael.hotan@socrata.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - Gemfile
135
+ - LICENSE
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - consul-ruby-client.gemspec
140
+ - lib/consul/client.rb
141
+ - lib/consul/client/agent.rb
142
+ - lib/consul/client/base.rb
143
+ - lib/consul/client/catalog.rb
144
+ - lib/consul/client/key_value.rb
145
+ - lib/consul/client/session.rb
146
+ - lib/consul/client/status.rb
147
+ - lib/consul/client/version.rb
148
+ - lib/consul/model/health_check.rb
149
+ - lib/consul/model/key_value.rb
150
+ - lib/consul/model/node.rb
151
+ - lib/consul/model/service.rb
152
+ - lib/consul/model/session.rb
153
+ - lib/consul/util/utils.rb
154
+ - spec/base_client_spec.rb
155
+ - spec/spec_helper.rb
156
+ homepage: https://github.com/mhotan-s/consul-ruby-client
157
+ licenses:
158
+ - MIT
159
+ metadata: {}
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubyforge_project:
176
+ rubygems_version: 2.4.5
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: Ruby Client library for communicating with Consul Agents.
180
+ test_files:
181
+ - spec/base_client_spec.rb
182
+ - spec/spec_helper.rb