habitat_supervisor 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: facc7748fbaaf075004a9aae98213c708f1bd3f8efb42bab6f049e52b2ec8ef1
4
+ data.tar.gz: 8d8fd5d0d003844fddfe4295b012642934948e37d0a963c8f50b5c6d426cc9e9
5
+ SHA512:
6
+ metadata.gz: 54e2a78290ba1b0703deaf416ab2c17aa23252ab1b6ed83347fca2734f52974f1ee41c28dc9ce734fa65a295c9d84dcf934cc6a6de3c33c39a5df727ac70cec8
7
+ data.tar.gz: 7e863d878fc484d5f971560b494a5bdde995b96e7328c68806ca2e278a594c1a23fe4b45e475cb47205fe30278fd63338fdf2bd0695e5457fab8f684f2164ca4
@@ -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
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.3
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ group :test do
6
+ gem "webmock"
7
+ end
8
+
9
+ # Specify your gem's dependencies in habitat_supervisor.gemspec
10
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Keith Walters
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # HabitatSupervisor
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/habitat_supervisor`. 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 'habitat_supervisor'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install habitat_supervisor
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]/habitat_supervisor.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "habitat_supervisor"
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__)
@@ -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,36 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "habitat_supervisor/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "habitat_supervisor"
8
+ spec.version = HabitatSupervisor::VERSION
9
+ spec.authors = ["Keith Walters"]
10
+ spec.email = ["keith.walters@cattywamp.us"]
11
+
12
+ spec.summary = %q{Rubygem wrapper for the Habitat Supervisor API}
13
+ spec.description = %q{Rubygem wrapper for the Habitat Supervisor API}
14
+ spec.homepage = "https://github.com/cattywampus/habitat_supervisor"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ end
@@ -0,0 +1,32 @@
1
+ require "habitat_supervisor/client"
2
+ require "habitat_supervisor/default"
3
+
4
+ module HabitatSupervisor
5
+ class << self
6
+ include HabitatSupervisor::Configurable
7
+
8
+ # API client based on configured options {Configurable}
9
+ #
10
+ # @return [HabitatSupervisor::Client] API wrapper
11
+ def client
12
+ return @client if defined?(@client) && @client.same_options?(options)
13
+ @client = HabitatSupervisor::Client.new(options)
14
+ end
15
+
16
+ private
17
+
18
+ def respond_to_missing?(method_name, include_private=false)
19
+ client.respond_to?(method_name, include_private)
20
+ end
21
+
22
+ def method_missing(method_name, *args, &block)
23
+ if client.respond_to?(method_name)
24
+ return client.send(method_name, *args, &block)
25
+ end
26
+
27
+ super
28
+ end
29
+ end
30
+ end
31
+
32
+ HabitatSupervisor.setup
@@ -0,0 +1,22 @@
1
+ require 'habitat_supervisor/configurable'
2
+ require 'habitat_supervisor/connection'
3
+ require 'habitat_supervisor/client/butterfly'
4
+ require 'habitat_supervisor/client/census'
5
+ require 'habitat_supervisor/client/services'
6
+
7
+ module HabitatSupervisor
8
+ class Client
9
+ include HabitatSupervisor::Configurable
10
+ include HabitatSupervisor::Connection
11
+ include HabitatSupervisor::Client::Butterfly
12
+ include HabitatSupervisor::Client::Census
13
+ include HabitatSupervisor::Client::Services
14
+
15
+ def initialize(options = {})
16
+ # Use options passed in, but fall back to module defaults
17
+ HabitatSupervisor::Configurable.keys.each do |key|
18
+ instance_variable_set(:"@#{key}", options[key] || HabitatSupervisor.instance_variable_get(:"@#{key}"))
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ module HabitatSupervisor
2
+ class Client
3
+ module Butterfly
4
+ def butterfly(options = {})
5
+ get "/butterfly", options
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module HabitatSupervisor
2
+ class Client
3
+ module Census
4
+ def census(options = {})
5
+ get "/census", options
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,30 @@
1
+ module HabitatSupervisor
2
+ class Client
3
+ module Services
4
+ def services(options = {})
5
+ get "/services", options
6
+ end
7
+
8
+ def service(name, options = {})
9
+ service_name, service_group = parse_service_name(name)
10
+ get "/services/#{service_name}/#{service_group}", options
11
+ end
12
+
13
+ def service_config(name, options = {})
14
+ service_name, service_group = parse_service_name(name)
15
+ get "/services/#{service_name}/#{service_group}/config", options
16
+ end
17
+
18
+ def service_health(name, option = {})
19
+ service_name, service_group = parse_service_name(name)
20
+ get "/services/#{service_name}/#{service_group}/health", options
21
+ end
22
+
23
+ private
24
+
25
+ def parse_service_name(name)
26
+ name.split(".")
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,39 @@
1
+ module HabitatSupervisor
2
+ module Configurable
3
+ attr_writer :api_endpoint
4
+
5
+ class << self
6
+
7
+ def keys
8
+ @keys ||= [
9
+ :api_endpoint
10
+ ]
11
+ end
12
+
13
+ end
14
+
15
+ def configure
16
+ yield(self)
17
+ end
18
+
19
+ # Reset configuration options to default values
20
+ def reset!
21
+ HabitatSupervisor::Configurable.keys.each do |key|
22
+ instance_variable_set(:"@#{key}", HabitatSupervisor::Default.options[key])
23
+ end
24
+ self
25
+ end
26
+ alias setup reset!
27
+
28
+ def api_endpoint
29
+ File.join(@api_endpoint, "")
30
+ end
31
+
32
+ private
33
+
34
+
35
+ def options
36
+ Hash[HabitatSupervisor::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,20 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ module HabitatSupervisor
5
+ module Connection
6
+ def get(path, options = {})
7
+ req = Net::HTTP::Get.new(path, options)
8
+ response = http.request(req)
9
+ JSON.parse(response.body)
10
+ end
11
+
12
+ def url
13
+ @url ||= URI.parse(api_endpoint)
14
+ end
15
+
16
+ def http
17
+ @http ||= Net::HTTP.new(url.host, url.port)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ require "habitat_supervisor/version"
2
+
3
+ module HabitatSupervisor
4
+ module Default
5
+
6
+ # Default API endpoint
7
+ API_ENDPOINT = "http://localhost:9631".freeze
8
+
9
+ # Default User Agent header string
10
+ USER_AGENT = "Habitat Supervisor Ruby Gem #{HabitatSupervisor::VERSION}".freeze
11
+
12
+ class << self
13
+
14
+ # Configuration options
15
+ # @return [Hash]
16
+ def options
17
+ Hash[HabitatSupervisor::Configurable.keys.map{|key| [key, send(key)]}]
18
+ end
19
+
20
+ # Default API endpoint from ENV or {API_ENDPOINT}
21
+ # @return [String]
22
+ def api_endpoint
23
+ ENV['HAB_SUP_API_ENDPOINT'] || API_ENDPOINT
24
+ end
25
+
26
+ # Default User-Agent header string from ENV or {USER_AGENT}
27
+ # @return [String]
28
+ def user_agent
29
+ ENV['HAB_SUP_USER_AGENT'] || USER_AGENT
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module HabitatSupervisor
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: habitat_supervisor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Keith Walters
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-03 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Rubygem wrapper for the Habitat Supervisor API
56
+ email:
57
+ - keith.walters@cattywamp.us
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - habitat_supervisor.gemspec
72
+ - lib/habitat_supervisor.rb
73
+ - lib/habitat_supervisor/client.rb
74
+ - lib/habitat_supervisor/client/butterfly.rb
75
+ - lib/habitat_supervisor/client/census.rb
76
+ - lib/habitat_supervisor/client/services.rb
77
+ - lib/habitat_supervisor/configurable.rb
78
+ - lib/habitat_supervisor/connection.rb
79
+ - lib/habitat_supervisor/default.rb
80
+ - lib/habitat_supervisor/version.rb
81
+ homepage: https://github.com/cattywampus/habitat_supervisor
82
+ licenses:
83
+ - MIT
84
+ metadata:
85
+ allowed_push_host: https://rubygems.org/
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.7.5
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Rubygem wrapper for the Habitat Supervisor API
106
+ test_files: []