train-habitat 0.1.1 → 0.2.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b8186bbf0eb9865517415f2f9270625140b5881b
4
- data.tar.gz: f9680ef5db5b308a52c27efb2c4baa054de253db
2
+ SHA256:
3
+ metadata.gz: 7b3bd86a77252c25b4cd62467713a3b2565c06c473e9d2ff1561f20c9f6f3fa9
4
+ data.tar.gz: b39c257fa768518b4df7db0f4f071da46889664aa1807c2bf57ae03ab4b3b25f
5
5
  SHA512:
6
- metadata.gz: 49a883505104ab0e9c69356e9bbea5ab46663a11c4fb9be12ba599172e506c7c5ea7c8708639a0f58cb46fc3079e17c71abe6843cb5a257a721b3410fc9b265d
7
- data.tar.gz: ac1de8ee00ae2ba8c5bdd087784f699b084d6c87f31047ae822e9fe683a3a76ef16ec70f29f9d539773e0903ea11fd845fe8ef745832e4b146a1a59dff7f1055
6
+ metadata.gz: 24654c94a9b4fcf75b0a55c58918d941fed7853eab8f45fd8388b484d2835e0f0476a2d0135202ccbd48bbe8c5c4c12b1debeb51bd1110b49e25cd3856997aff
7
+ data.tar.gz: 2a39149145e5bebb7d7899f2d3e1e69ac03bf4cda7a28f0d772ec046665b63d75a6793fed30896883d9fe9f1b6d1d3b9be541e072d3c030e9114fec7ccae9b00
data/Gemfile CHANGED
@@ -1,15 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
7
  group :development do
8
- gem 'byebug', '~> 11.0'
9
- gem 'm', '~> 1.5'
10
- gem 'minitest', '~> 5.11'
11
- gem 'mocha', '~> 1.8'
12
- gem 'pry', '~> 0.11'
13
- gem 'rake', '~> 12.3'
14
- gem 'rubocop', '~> 0.59'
8
+ gem "byebug", "~> 11.0"
9
+ gem "m", "~> 1.5"
10
+ gem "minitest", "~> 5.11"
11
+ gem "mocha", "~> 1.8"
12
+ gem "pry", "~> 0.11"
13
+ gem "rake", "~> 12.3"
14
+ gem "rubocop", "~> 0.59"
15
+ gem "chefstyle", "0.13.2"
15
16
  end
data/README.md CHANGED
@@ -1,16 +1,16 @@
1
1
  # Train-Habitat
2
2
 
3
- `train-habitat` is a Train plugin and is used as a Train Transport to connect to Habitat installations.
3
+ * **Project State: Active**
4
+ * **Issues Response SLA: 3 business days**
5
+ * **Pull Request Response SLA: 3 business days**
4
6
 
5
- ## To Install this as a User
7
+ For more information on project states and SLAs, see [this documentation](https://github.com/chef/chef-oss-practices/blob/master/repo-management/repo-states.md).
6
8
 
7
- You will need InSpec v2.3 or later.
9
+ `train-habitat` is a Train plugin and is used as a Train Transport to connect to Habitat installations.
8
10
 
9
- Simply run:
11
+ ## To Install this as a User
10
12
 
11
- ```
12
- $ inspec plugin install train-habitat
13
- ```
13
+ `train-habitat` is included with InSpec 4.7.3 and later. There is no need to separately install this plugin.
14
14
 
15
15
  ## Using train-habitat from InSpec
16
16
 
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'net/http'
4
- require 'json'
5
- require 'train-habitat/httpgateway'
6
- require 'train-habitat/platform'
7
- require 'train-habitat/transport'
3
+ require "net/http"
4
+ require "json"
5
+ require "train-habitat/httpgateway"
6
+ require "train-habitat/platform"
7
+ require "train-habitat/transport"
8
8
 
9
9
  module TrainPlugins
10
10
  module Habitat
@@ -27,7 +27,7 @@ module TrainPlugins
27
27
  end
28
28
 
29
29
  def api_options_provided?
30
- have_transport_options_with_prefix?('api')
30
+ have_transport_options_with_prefix?("api")
31
31
  end
32
32
 
33
33
  def cli_options_provided?
@@ -41,11 +41,18 @@ module TrainPlugins
41
41
  raise CliNotAvailableError(cli_tranport_names) unless cli_options_provided?
42
42
 
43
43
  # TODO: - leverage exec_options to add things like JSON parsing, ENV setting, etc.
44
- cli_connection.run_command(hab_path + ' ' + command)
44
+ cli_connection.run_command(hab_path + " " + command)
45
+ end
46
+
47
+ # See #run_command in BaseConnection.
48
+ def run_command_via_connection(*args)
49
+ raise CliNotAvailableError(cli_tranport_names) unless cli_options_provided?
50
+
51
+ cli_connection.run_command(*args)
45
52
  end
46
53
 
47
54
  def hab_path
48
- '/bin/hab'
55
+ "/bin/hab"
49
56
  end
50
57
 
51
58
  def habitat_api_client
@@ -53,9 +60,9 @@ module TrainPlugins
53
60
  # Send all options beginning with api_ to the HTTPGateway, stripping the prefix
54
61
  api_options = {}
55
62
  transport_options.each do |option_name, option_value|
56
- next unless option_name.to_s.start_with? 'api_'
63
+ next unless option_name.to_s.start_with? "api_"
57
64
 
58
- api_options[option_name.to_s.sub(/^api_/, '').to_sym] = option_value
65
+ api_options[option_name.to_s.sub(/^api_/, "").to_sym] = option_value
59
66
  end
60
67
  HTTPGateway.new(api_options)
61
68
  end
@@ -69,14 +76,14 @@ module TrainPlugins
69
76
  end
70
77
 
71
78
  valid_cli_prefixes = TrainPlugins::Habitat::Transport.cli_transport_prefixes.keys.map(&:to_s)
72
- seen_cli_options = transport_options.keys.map(&:to_s).select { |n| n.start_with?('cli_') }
79
+ seen_cli_options = transport_options.keys.map(&:to_s).select { |n| n.start_with?("cli_") }
73
80
 
74
81
  # All seen CLI options must start with a recognized prefix
75
82
  options_by_prefix = {}
76
83
  seen_cli_options.each do |option|
77
84
  prefix = valid_cli_prefixes.detect { |p| option.start_with?(p) }
78
85
  unless prefix
79
- raise Train::TransportError, "All Habitat CLI connection options must begin with a recognized prefix (#{valid_cli_prefixes.join(', ')}) - saw #{option}"
86
+ raise Train::TransportError, "All Habitat CLI connection options must begin with a recognized prefix (#{valid_cli_prefixes.join(", ")}) - saw #{option}"
80
87
  end
81
88
 
82
89
  options_by_prefix[prefix] ||= []
@@ -85,7 +92,7 @@ module TrainPlugins
85
92
 
86
93
  # Only one prefix may be used (don't mix and match)
87
94
  if options_by_prefix.count > 1
88
- raise Train::TransportError, "Only one set of Habitat CLI connection options may be used - saw #{options_by_prefix.keys.join(', ')}"
95
+ raise Train::TransportError, "Only one set of Habitat CLI connection options may be used - saw #{options_by_prefix.keys.join(", ")}"
89
96
  end
90
97
  end
91
98
 
@@ -110,7 +117,7 @@ module TrainPlugins
110
117
  seen_cli_transports = {}
111
118
  non_specific_options = {} # Things like :logger, :sudo, etc
112
119
  transport_options.each do |xport_option_name, xport_option_value|
113
- unless xport_option_name.to_s.start_with?('cli_')
120
+ unless xport_option_name.to_s.start_with?("cli_")
114
121
  non_specific_options[xport_option_name] = xport_option_value
115
122
  next
116
123
  end
@@ -121,7 +128,7 @@ module TrainPlugins
121
128
 
122
129
  seen_cli_transports[xport_name] ||= {}
123
130
  # Remove the prefix from the option and store under transport name
124
- seen_cli_transports[xport_name][xport_option_name.to_s.sub(/^#{prefix}_/, '').to_sym] = xport_option_value
131
+ seen_cli_transports[xport_name][xport_option_name.to_s.sub(/^#{prefix}_/, "").to_sym] = xport_option_value
125
132
  end
126
133
  end
127
134
 
@@ -1,5 +1,5 @@
1
- require 'uri'
2
- require 'net/http'
1
+ require "uri"
2
+ require "net/http"
3
3
 
4
4
  module TrainPlugins
5
5
  module Habitat
@@ -23,7 +23,7 @@ module TrainPlugins
23
23
  uri.path = path
24
24
  headers = {}
25
25
  unless auth_token.nil?
26
- headers['Authorization'] = 'Bearer ' + auth_token # Set bearer token, see https://www.habitat.sh/docs/using-habitat/#authentication
26
+ headers["Authorization"] = "Bearer " + auth_token # Set bearer token, see https://www.habitat.sh/docs/using-habitat/#authentication
27
27
  end
28
28
 
29
29
  conn = Net::HTTP.start(uri.host, uri.port)
@@ -20,12 +20,12 @@ end
20
20
 
21
21
  class CliNotAvailableError < IllegalStateError
22
22
  def initialize(_cli_tranport_names)
23
- super("No CLI-capable connection options passed - use one of #{cli_transport_names.join(', ')} option sets")
23
+ super("No CLI-capable connection options passed - use one of #{cli_transport_names.join(", ")} option sets")
24
24
  end
25
25
  end
26
26
 
27
27
  class MultipleCliTransportsError < IllegalStateError
28
28
  def initialize(_cli_tranport_names)
29
- super("Too many CLI-capable transports specified - only one may be used at a time. Saw: #{cli_transport_names.join(', ')}.")
29
+ super("Too many CLI-capable transports specified - only one may be used at a time. Saw: #{cli_transport_names.join(", ")}.")
30
30
  end
31
31
  end
@@ -4,8 +4,8 @@ module TrainPlugins
4
4
  module Habitat
5
5
  module Platform
6
6
  def platform
7
- Train::Platforms.name('habitat').in_family('api')
8
- force_platform!('habitat', release: TrainPlugins::Habitat::VERSION)
7
+ Train::Platforms.name("habitat").in_family("api")
8
+ force_platform!("habitat", release: TrainPlugins::Habitat::VERSION)
9
9
  end
10
10
  end
11
11
  end
@@ -1,11 +1,11 @@
1
- require 'train'
2
- require 'train/plugins'
3
- require 'train-habitat/connection'
1
+ require "train"
2
+ require "train/plugins"
3
+ require "train-habitat/connection"
4
4
 
5
5
  module TrainPlugins
6
6
  module Habitat
7
7
  class Transport < Train.plugin(1)
8
- name 'habitat'
8
+ name "habitat"
9
9
 
10
10
  # The train-habitat plugins is a chimeric plugin, meaning it uses
11
11
  # multiple ways of connecting to its target. A user must specifiy
@@ -14,8 +14,8 @@ module TrainPlugins
14
14
 
15
15
  # For service listings and health, specify supervisor api options.
16
16
  # https://www.habitat.sh/docs/using-habitat/#monitor-services-through-the-http-api
17
- option :api_url, required: false, desc: 'The url at which a Habitat Supervisor exposes its HTTP Gateway API'
18
- option :api_auth_token, required: false, desc: 'A bearer token which may be used to authenticate to the Supervisor HTTP Gateway'
17
+ option :api_url, required: false, desc: "The url at which a Habitat Supervisor exposes its HTTP Gateway API"
18
+ option :api_auth_token, required: false, desc: "A bearer token which may be used to authenticate to the Supervisor HTTP Gateway"
19
19
 
20
20
  def self.cli_transport_prefixes
21
21
  {
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TrainPlugins
4
4
  module Habitat
5
- VERSION = '0.1.1'
5
+ VERSION = "0.2.7"
6
6
  end
7
7
  end
data/lib/train-habitat.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  libdir = File.dirname(__FILE__)
4
4
  $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
5
5
 
6
- require 'train-habitat/version'
7
- require 'train-habitat/transport'
8
- require 'train-habitat/platform'
9
- require 'train-habitat/connection'
6
+ require "train-habitat/version"
7
+ require "train-habitat/transport"
8
+ require "train-habitat/platform"
9
+ require "train-habitat/connection"
@@ -1,29 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('lib', __dir__)
3
+ lib = File.expand_path("lib", __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'train-habitat/version'
5
+ require "train-habitat/version"
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = 'train-habitat'
8
+ spec.name = "train-habitat"
9
9
  spec.version = TrainPlugins::Habitat::VERSION
10
- spec.authors = ['Chef InSpec Team']
11
- spec.email = ['inspec@chef.io']
12
- spec.summary = 'Habitat API Transport for Train'
13
- spec.description = 'Allows applications using Train to speak to Habitat.'
14
- spec.homepage = 'https://github.com/inspec/train-habitat'
15
- spec.license = 'Apache-2.0'
10
+ spec.authors = ["Chef InSpec Team"]
11
+ spec.email = ["inspec@chef.io"]
12
+ spec.summary = "Habitat API Transport for Train"
13
+ spec.description = "Allows applications using Train to speak to Habitat."
14
+ spec.homepage = "https://github.com/inspec/train-habitat"
15
+ spec.license = "Apache-2.0"
16
16
 
17
17
  spec.files = %w{
18
18
  README.md train-habitat.gemspec Gemfile
19
19
  } + Dir.glob(
20
- 'lib/**/*', File::FNM_DOTMATCH
20
+ "lib/**/*", File::FNM_DOTMATCH
21
21
  ).reject { |f| File.directory?(f) }
22
- spec.require_paths = ['lib']
22
+ spec.require_paths = ["lib"]
23
23
 
24
24
  # All plugins should mention train, > 1.4
25
- spec.add_dependency 'train', '>= 1.7.5', '< 3.0'
25
+ spec.add_dependency "train", ">= 1.7.5", "< 3.0"
26
26
 
27
- spec.add_development_dependency 'minitest', '~> 5.0'
28
- spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: train-habitat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef InSpec Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-28 00:00:00.000000000 Z
11
+ date: 2019-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: train
@@ -94,8 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  requirements: []
97
- rubyforge_project:
98
- rubygems_version: 2.6.14.3
97
+ rubygems_version: 3.0.3
99
98
  signing_key:
100
99
  specification_version: 4
101
100
  summary: Habitat API Transport for Train