train-habitat 0.1.1 → 0.2.22

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: d517d6acec8b0d954a94a128af818ce58f1e5c7795bc4b00d1cde1d2d13b8bee
4
+ data.tar.gz: f2c33469c6461d34b50b0f1b484c89148b939604c1343a92e798ff6f98d9950a
5
5
  SHA512:
6
- metadata.gz: 49a883505104ab0e9c69356e9bbea5ab46663a11c4fb9be12ba599172e506c7c5ea7c8708639a0f58cb46fc3079e17c71abe6843cb5a257a721b3410fc9b265d
7
- data.tar.gz: ac1de8ee00ae2ba8c5bdd087784f699b084d6c87f31047ae822e9fe683a3a76ef16ec70f29f9d539773e0903ea11fd845fe8ef745832e4b146a1a59dff7f1055
6
+ metadata.gz: 867c09352706b078b177328ac37483e55042e0b59babf46718b856313b63556a0d5c6722f39a92bd2a800b34c5c444cac40c7604b13d598e689ca1f57115d97c
7
+ data.tar.gz: c20278d657b5c68ad2f3d4bb7f07d67f6038cd4055fe7e4d45d03ec1ac89637b59820416fecabbf220543d3932eefe478c9f821ffb106c8e9a5c3ff5585f67f2
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2018 Chef Software Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -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_relative "train-habitat/version"
7
+ require_relative "train-habitat/transport"
8
+ require_relative "train-habitat/platform"
9
+ require_relative "train-habitat/connection"
@@ -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" unless defined?(Net::HTTP)
4
+ require "json" unless defined?(JSON)
5
+ require_relative "httpgateway"
6
+ require_relative "platform"
7
+ require_relative "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" unless defined?(URI)
2
+ require "net/http" unless defined?(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_relative "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.22"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,35 +1,15 @@
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.22
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: 2021-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: train
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 1.7.5
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '3.0'
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: 1.7.5
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '3.0'
33
13
  - !ruby/object:Gem::Dependency
34
14
  name: minitest
35
15
  requirement: !ruby/object:Gem::Requirement
@@ -50,14 +30,14 @@ dependencies:
50
30
  requirements:
51
31
  - - "~>"
52
32
  - !ruby/object:Gem::Version
53
- version: '10.0'
33
+ version: '13.0'
54
34
  type: :development
55
35
  prerelease: false
56
36
  version_requirements: !ruby/object:Gem::Requirement
57
37
  requirements:
58
38
  - - "~>"
59
39
  - !ruby/object:Gem::Version
60
- version: '10.0'
40
+ version: '13.0'
61
41
  description: Allows applications using Train to speak to Habitat.
62
42
  email:
63
43
  - inspec@chef.io
@@ -65,8 +45,7 @@ executables: []
65
45
  extensions: []
66
46
  extra_rdoc_files: []
67
47
  files:
68
- - Gemfile
69
- - README.md
48
+ - LICENSE
70
49
  - lib/train-habitat.rb
71
50
  - lib/train-habitat/connection.rb
72
51
  - lib/train-habitat/httpgateway.rb
@@ -74,7 +53,6 @@ files:
74
53
  - lib/train-habitat/platform.rb
75
54
  - lib/train-habitat/transport.rb
76
55
  - lib/train-habitat/version.rb
77
- - train-habitat.gemspec
78
56
  homepage: https://github.com/inspec/train-habitat
79
57
  licenses:
80
58
  - Apache-2.0
@@ -94,8 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
72
  - !ruby/object:Gem::Version
95
73
  version: '0'
96
74
  requirements: []
97
- rubyforge_project:
98
- rubygems_version: 2.6.14.3
75
+ rubygems_version: 3.1.4
99
76
  signing_key:
100
77
  specification_version: 4
101
78
  summary: Habitat API Transport for Train
data/Gemfile DELETED
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- gemspec
6
-
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'
15
- end
data/README.md DELETED
@@ -1,163 +0,0 @@
1
- # Train-Habitat
2
-
3
- `train-habitat` is a Train plugin and is used as a Train Transport to connect to Habitat installations.
4
-
5
- ## To Install this as a User
6
-
7
- You will need InSpec v2.3 or later.
8
-
9
- Simply run:
10
-
11
- ```
12
- $ inspec plugin install train-habitat
13
- ```
14
-
15
- ## Using train-habitat from InSpec
16
-
17
- As `train-habitat` takes potentially many options, it is simplest to list the options in your `~/.inspec/config.json` file, then used the named set of options with `-t`.
18
-
19
- For example, if your config file contains:
20
-
21
- ```
22
- {
23
- "file_version": "1.1",
24
- "credentials": {
25
- "habitat": {
26
- "dev-hab": {
27
- "api_url": "http://dev-hab.my-corp.io",
28
- "cli_ssh_host": "dev-hab.my-corp.io"
29
- },
30
- "prod-hab": {
31
- "api_url": "https://prod-hab.my-corp.io",
32
- "api_auth_token": "opensesame"
33
- },
34
- }
35
- }
36
- }
37
- ```
38
-
39
- Using this configuration, you could execute:
40
-
41
- ```
42
- $ inspec exec some-profile -t habitat://dev-hab
43
- # Or
44
- $ inspec exec some-profile -t habitat://prod-hab
45
- ```
46
-
47
- You may also pass `--config some-file.json` to use a config file at a different location.
48
-
49
- See the next section for the full list of options you may use with a `habitat` credential set in your configuration.
50
-
51
- ## Using train-habitat from Ruby
52
-
53
- The options that may be passed to `Train.create` are listed below.
54
-
55
- ### Dual-mode transport
56
-
57
- Because Habitat exposes some facts by its HTTP Gateway API, and some facts by its CLI tool `hab`, this Train Transport has three modes of operation:
58
-
59
- * Using only the HTTP API (no ability to query packages, but rich ability to query rings)
60
- * Using only the `hab` CLI command (limitations TBD)
61
- * Using both (full capabilities)
62
-
63
- When creating a `train-habitat` Connection, there are thus two sets of options, prefixed with `api_` and `cli_` respectively. You must provide at least one set.
64
-
65
- ### API-Mode options
66
-
67
- API-mode options are used to connect to a Habitat Supervisor running with an exposed HTTP Gateway. They are prefixed with `api_`.
68
-
69
- ```ruby
70
- Train.create(:habitat, api_url: 'http://my-hab.my-company.io:9631')
71
- ```
72
-
73
- #### api_url
74
-
75
- Required for API-mode use. This is an HTTP or HTTPS URL that identifies a Supervisor HTTP Gateway. If the port is omitted from the URL, the API standard port of 9631 is assumed; to use port 80, specify it explicitly.
76
-
77
- #### api_auth_token
78
-
79
- The supervisor may be configured to require a [Bearer Token Authorization](https://www.habitat.sh/docs/using-habitat/#monitor-services-through-the-http-api), in which the client and the gateway use a pre-shared secret. Use this option to specify the secret.
80
-
81
- ### CLI Mode options
82
-
83
- CLI options are more varied, and are entirely dependent on the underlying transport chosen to reach the CLI. For example, if there were a supported transport named 'radio' that took options 'channel' and 'band', specify them to train-habitat like this:
84
-
85
- ```ruby
86
- Train.create(:habitat, {cli_radio_band: 'VHF', cli_radio_channel: 23})
87
- ```
88
-
89
- `train-habitat` identifies the underlying "sub-transport" using the prefixes of the provided options. For example, if you pass an option named `cli_ssh_host`, `train-habitat` will recognize that you intend to use the SSH transport to connect to a location that has access to the `hab` CLI tool.
90
-
91
- You may specify many options referring to the same sub-transport (such as credentials), but it is an error to specify more than one CLI sub-transport.
92
-
93
- Currently supported CLI transports include:
94
- * SSH
95
-
96
- Plans for future support include (in approximate order):
97
- * WinRM
98
- * Local
99
- * Docker
100
-
101
- #### General Options
102
-
103
- Any options not prefixed with `cli_` or `api_` are also passed to the CLI transport. This means you can use generic Train connection options such as the `sudo` and `shell` sets of options (see [train source code](https://github.com/inspec/train/blob/71679307903fc8853e09abd93f3901c83800e019/lib/train/extras/command_wrapper.rb#L31)), as well as `logger`.
104
-
105
- #### SSH Options
106
-
107
- `train-habitat` can accept any option that the Train SSH Transport accepts if the prefix `cli_ssh_` is added. This includes:
108
-
109
- * `cli_ssh_host` - String hostname or IP address
110
- * `cli_ssh_user` - String user to connect as
111
- * `cli_ssh_key_files` - Array of paths to private key files to use
112
-
113
- Other options are available; see [train source code](https://github.com/inspec/train/blob/71679307903fc8853e09abd93f3901c83800e019/lib/train/transports/ssh.rb#L45) for details.
114
-
115
- ## Development
116
-
117
- ### Testing
118
- ```
119
- # Install development tools
120
- $ gem install bundler
121
- $ bundle install
122
-
123
- # Running style checker
124
- bundle exec rake lint
125
-
126
- # Running unit tests
127
- bundle exec rake test:unit
128
-
129
- # Running integration tests (requires Vagrant and VirtualBox)
130
- bundle exec rake test:integration
131
- ```
132
-
133
- ## Contributing
134
-
135
- 1. Fork it
136
- 1. Create your feature branch (git checkout -b my-new-feature)
137
- 1. Commit your changes (git commit -sam 'Add some feature')
138
- 1. Push to the branch (git push origin my-new-feature)
139
- 1. Create new Pull Request
140
-
141
- ## License
142
-
143
- | **Author:** | Paul Welch
144
-
145
- | **Author:** | David McCown
146
-
147
- | **Author:** | Clinton Wolfe
148
-
149
- | **Copyright:** | Copyright (c) 2018-2019 Chef Software Inc.
150
-
151
- | **License:** | Apache License, Version 2.0
152
-
153
- Licensed under the Apache License, Version 2.0 (the "License");
154
- you may not use this file except in compliance with the License.
155
- You may obtain a copy of the License at
156
-
157
- http://www.apache.org/licenses/LICENSE-2.0
158
-
159
- Unless required by applicable law or agreed to in writing, software
160
- distributed under the License is distributed on an "AS IS" BASIS,
161
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
162
- See the License for the specific language governing permissions and
163
- limitations under the License.
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- lib = File.expand_path('lib', __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'train-habitat/version'
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = 'train-habitat'
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'
16
-
17
- spec.files = %w{
18
- README.md train-habitat.gemspec Gemfile
19
- } + Dir.glob(
20
- 'lib/**/*', File::FNM_DOTMATCH
21
- ).reject { |f| File.directory?(f) }
22
- spec.require_paths = ['lib']
23
-
24
- # All plugins should mention train, > 1.4
25
- spec.add_dependency 'train', '>= 1.7.5', '< 3.0'
26
-
27
- spec.add_development_dependency 'minitest', '~> 5.0'
28
- spec.add_development_dependency 'rake', '~> 10.0'
29
- end