instructure_registrar 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
+ SHA1:
3
+ metadata.gz: cc88e07ee4ce4cc7a4fbfc01474bdb2e91843bc1
4
+ data.tar.gz: 6549dee7f8367c8eee4551b07e38f120c05a75ef
5
+ SHA512:
6
+ metadata.gz: 817721f2a1393db6902b0d69fa29387bb6f4ae4d70d6cff3e2ca9f41942fcc513c0ad69627d1357ec6c3d71bbfd0648effbd4cc9e564edb9114f3a64c428ffb7
7
+ data.tar.gz: 2d7f4714c5a0288ab1e0a6e1595a0f0f18738abeabd7628396c3832d2f53406d3f48d63deb5b9d91777dab7085dfe0aac04bbb1ce450436447c6298894aff7e7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in instructure_service_registry_client.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # InstructureRegistrar
2
+
3
+ InstructureRegistrar is a Ruby library for registering and retrieving service
4
+ information from a central etcd service registry.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'instructure_registrar'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ ## Usage
19
+
20
+ Make sure that the following environment variables are set with the appropriate
21
+ information for your local etcd instance:
22
+
23
+ REGISTRY_HOST
24
+ REGISTRY_PORT
25
+
26
+ ### Integrating with a service
27
+
28
+ In your service's project folder, create a configuration file with the following contents:
29
+
30
+ #/config/instructure_registrar.rb
31
+ require 'dotenv'
32
+ Dotenv.load
33
+ require 'instructure_registrar'
34
+
35
+ InstructureRegistrar.configure do |config|
36
+ config.registry_host = ENV.fetch('REGISTRY_HOST') || "http://instructure-etcd.docker"
37
+ config.registry_port = ENV.fetch("REGISTRY_PORT") || 12379
38
+ config.service_name = "my.service.name"
39
+ config.service_host = ENV.fetch("SERVICE_HOST") || "http://localhost/"
40
+ config.service_port = ENV.fetch("SERVICE_PORT") || 3000
41
+ end
42
+
43
+ InstructureRegistrar.register
44
+ at_exit { InstructureRegistrar.unregister }
45
+
46
+ ### Looking up a service
47
+
48
+ Note that your client application will need a config file similar to that in the section above, but
49
+ unless you plan on registering your app as a service your config file will be simpler:
50
+
51
+ #/config/instructure_registrar.rb
52
+ require 'dotenv'
53
+ Dotenv.load
54
+ require 'instructure_registrar'
55
+
56
+ InstructureRegistrar.configure do |config|
57
+ config.registry_host = ENV.fetch('REGISTRY_HOST') || "http://instructure-etcd.docker"
58
+ config.registry_port = ENV.fetch("REGISTRY_PORT") || 12379
59
+ end
60
+
61
+ Then, to fetch connection information for a given service:
62
+
63
+ require 'instructure_registrar'
64
+ @some_service_url = InstructureRegistrar.get_service('some_service_name')
65
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "instructure_service_registry_client"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ require 'dotenv'
2
+ Dotenv.load
3
+ require 'concierge_service'
4
+
5
+ InstructureRegistrar.configure do |config|
6
+ config.registry_host = ENV.fetch('REGISTRY_HOST') || "http://instructure-etcd.docker"
7
+ config.registry_port = ENV.fetch("REGISTRY_PORT") || 12379
8
+ config.service_name = "my.service.name"
9
+ config.service_host = "localhost"
10
+ config.service_port = "3000"
11
+ end
12
+
13
+ InstructureRegistrar.register
14
+ at_exit { InstructureRegistrar.unregister }
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'instructure_registrar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "instructure_registrar"
8
+ spec.version = InstructureRegistrar::VERSION
9
+ spec.authors = ["CoralineAda"]
10
+ spec.email = ["coraline@idolhands.com"]
11
+
12
+ spec.summary = %q{Client for registering an Instructure service via etcd.}
13
+ spec.description = %q{Client for registering an Instructure service via etcd.}
14
+ spec.homepage = "https://github.com/CoralineAda/instructure_registrar"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "dotenv"
22
+ spec.add_dependency "etcd", "~> 0.3"
23
+ spec.add_dependency "require_all"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.9"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
@@ -0,0 +1,28 @@
1
+ module InstructureRegistrar
2
+ class Client
3
+
4
+ def lookup(service_name)
5
+ client.get(service_name).value || "unknown"
6
+ end
7
+
8
+ def register
9
+ client.set(
10
+ InstructureRegistrar.config.service_name,
11
+ "#{InstructureRegistrar.service_host}:#{InstructureRegistrar.config.service_port}"
12
+ )
13
+ end
14
+
15
+ def unregister
16
+ client.delete(InstructureRegistrar.config.service_name)
17
+ end
18
+
19
+ private
20
+
21
+ def client
22
+ @client ||= Etcd.client(
23
+ host: InstructureRegistrar.config.registry_host,
24
+ port: InstructureRegistrar.config.registry_port
25
+ )
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module InstructureRegistrar
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,37 @@
1
+ require 'require_all'
2
+ require_rel 'instructure_registrar'
3
+
4
+ module InstructureRegistrar
5
+
6
+ def self.get_service(service_name)
7
+ InstructureRegistrar::Client.new.lookup(service_name)
8
+ end
9
+
10
+ def self.register
11
+ InstructureRegistrar::Client.new.register
12
+ end
13
+
14
+ def self.unregister
15
+ InstructureRegistrar::Client.new.unregister
16
+ end
17
+
18
+ class << self
19
+ attr_accessor :config
20
+ end
21
+
22
+ def self.configure(&block)
23
+ @config = Configuration.new
24
+ yield(config)
25
+ end
26
+
27
+ def self.config
28
+ @config || Configuration.new
29
+ end
30
+
31
+ class Configuration
32
+ attr_accessor :registry_host, :registry_port
33
+ attr_accessor :service_name, :service_host, :service_port
34
+ end
35
+
36
+ end
37
+
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: instructure_registrar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - CoralineAda
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dotenv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: etcd
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: require_all
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: Client for registering an Instructure service via etcd.
84
+ email:
85
+ - coraline@idolhands.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/setup
97
+ - config/instructure_registrar.rb
98
+ - instructure_registrar.gemspec
99
+ - lib/instructure_registrar.rb
100
+ - lib/instructure_registrar/client.rb
101
+ - lib/instructure_registrar/version.rb
102
+ homepage: https://github.com/CoralineAda/instructure_registrar
103
+ licenses: []
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.4.6
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Client for registering an Instructure service via etcd.
125
+ test_files: []
126
+ has_rdoc: