dryad-consul 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 18ba39b82bec489a26cf303fe475a8af6b813e1e40ea3a97a1f510274c60a6ed
4
+ data.tar.gz: 2f1d1c5c4d49e6ea8ddcd538f3e4fa98200544ac1255b05d021ad9021b19d4d1
5
+ SHA512:
6
+ metadata.gz: bee95523f20a4e59de3f131ef9aa91ddaf8b9ceaae2124c887f6ef245f6e0e419a8b4487652c341dfcded726c799a6cb295653c2612f6e81874fe9536d9b5d0c
7
+ data.tar.gz: 154eec07bc0eebc8b4e38d4e474c0f3174c7673846d54c280e7c4be1db3f4fda02e1b02eb2db2012db0cbdd9d17b687c63fb7427df8a6cdd5f594253877fcfa0
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dryad-consul.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dryad-consul (0.1.0.alpha)
5
+ diplomat
6
+ dryad-core (= 0.1.0.alpha)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ deep_merge (1.2.1)
12
+ diff-lcs (1.3)
13
+ diplomat (2.2.4)
14
+ deep_merge (~> 1.0, >= 1.0.1)
15
+ faraday (~> 0.9)
16
+ dryad-core (0.1.0.alpha)
17
+ faraday (0.15.4)
18
+ multipart-post (>= 1.2, < 3)
19
+ multipart-post (2.1.0)
20
+ rake (10.5.0)
21
+ rspec (3.8.0)
22
+ rspec-core (~> 3.8.0)
23
+ rspec-expectations (~> 3.8.0)
24
+ rspec-mocks (~> 3.8.0)
25
+ rspec-core (3.8.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-expectations (3.8.3)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-mocks (3.8.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.8.0)
33
+ rspec-support (3.8.0)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bundler (~> 2.0)
40
+ dryad-consul!
41
+ rake (~> 10.0)
42
+ rspec (~> 3.0)
43
+
44
+ BUNDLED WITH
45
+ 2.0.1
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ The MIT License (MIT)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Dryad::Consul
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dryad/consul`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dryad-consul'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dryad-consul
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dryad-consul.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dryad/consul"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "dryad/consul/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dryad-consul"
8
+ spec.version = Dryad::Consul::VERSION
9
+ spec.authors = ["Pan Jie"]
10
+ spec.email = ["panjie@growingio.com"]
11
+
12
+ spec.summary = %q{Dryad consul library.}
13
+ spec.description = %q{Dryad consul is the adapter for consul.}
14
+ spec.homepage = "https://github.com/jack0pan/dryad.rb"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "dryad-core", Dryad::Consul::VERSION
25
+ spec.add_dependency "diplomat"
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ end
@@ -0,0 +1,33 @@
1
+ module Dryad
2
+ module Consul
3
+ class Service < Dryad::Core::Service
4
+ def to_registers
5
+ portals.map do |portal|
6
+ {
7
+ ID: portal.id,
8
+ Name: Service.full_name(portal.schema, name),
9
+ Address: address,
10
+ Port: portal.port,
11
+ EnableTagOverride: true,
12
+ Tags: tags(portal)
13
+ }
14
+ end
15
+ end
16
+
17
+ private
18
+ def tags(portal)
19
+ tags = [
20
+ "type = \"#{type_name}\"",
21
+ "priority = \"#{priority}\"",
22
+ "group = \"#{group}\"",
23
+ "schema = \"#{portal.schema}\"",
24
+ "pattern = \"#{portal.pattern}\""
25
+ ]
26
+ if portal.non_certifications.count > 0
27
+ tags << "non_certifications = \"#{portal.non_certifications.join(",")}\""
28
+ end
29
+ tags.concat(load_balancing.map{|lb| "load_balancing = \"#{lb}\"" })
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ module Dryad
2
+ module Consul
3
+ class ServiceClient
4
+ class << self
5
+ def method_missing(name, *args, &block)
6
+ Diplomat::Service.send(name, *args, &block) || super
7
+ end
8
+
9
+ def respond_to_missing?(meth_id, with_private = false)
10
+ access_method?(meth_id) || super
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,37 @@
1
+ module Dryad
2
+ module Consul
3
+ class ServiceRegistry
4
+ class << self
5
+ def register(service)
6
+ service.to_registers.each do |register|
7
+ ServiceClient.register(register)
8
+ end
9
+ end
10
+
11
+ def deregister(service)
12
+ service.portals.each do |portal|
13
+ ServiceClient.deregister(portal.id)
14
+ end
15
+ end
16
+
17
+ def service_instances(name, schema, groups)
18
+ all_services = ServiceClient.get(Dryad::Core::Service.full_name(schema, name), :all)
19
+ services = []
20
+ all_services.each do |service|
21
+ groups.each do |group|
22
+ services << service if service.ServiceTags.include?("group = \"#{group}\"")
23
+ end
24
+ end
25
+ services.map do |service|
26
+ Dryad::Core::ServiceInstance.new(
27
+ name: name,
28
+ schema: schema,
29
+ address: service.ServiceAddress,
30
+ port: service.ServicePort
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ module Dryad
2
+ module Consul
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+ PRE = nil
7
+
8
+ VERSION = [MAJOR, MINOR, TINY, PRE].compact.join(".")
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ require "diplomat"
2
+ require "dryad"
3
+ require "dryad/consul/version"
4
+ require "dryad/consul/service_client"
5
+ require "dryad/consul/service_registry"
6
+ require "dryad/consul/service"
7
+
8
+ module Dryad
9
+ module Consul
10
+ class Error < StandardError; end
11
+
12
+ ::Diplomat.configure do |config|
13
+ config.url = "http://#{Dryad.configuration.consul[:host]}:#{Dryad.configuration.consul[:port]}"
14
+ end
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dryad-consul
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pan Jie
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dryad-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: diplomat
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Dryad consul is the adapter for consul.
84
+ email:
85
+ - panjie@growingio.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - dryad-consul.gemspec
100
+ - lib/dryad/consul.rb
101
+ - lib/dryad/consul/service.rb
102
+ - lib/dryad/consul/service_client.rb
103
+ - lib/dryad/consul/service_registry.rb
104
+ - lib/dryad/consul/version.rb
105
+ homepage: https://github.com/jack0pan/dryad.rb
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubygems_version: 3.0.3
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Dryad consul library.
128
+ test_files: []