inspec-tkinfo 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8ef0db5c35e4ea1f8cc82ac1bdf4f128d09b82572aeffde44411967cd174dc64
4
+ data.tar.gz: 6f82d1cfa0dd1dfeb04c9accca20a20199a7468e5a6e6ac0a843be126d0de500
5
+ SHA512:
6
+ metadata.gz: 13eace66037c8080c6e31b697677fdcdbc31decfe89abcb79791ee2d808d36054dcc5f4f30cf68d6c6687b56d3f895af99671515543c8c0e5f548c15c8afc8bf
7
+ data.tar.gz: 17a94644d484461014c40ab583332e6258df65b2fc430f476cdb7fcd85ad65296f7824a83e4ab12c798d91c635b287b301bb284d3774fe1ca63c0a42eaf82de5
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ source "https://rubygems.org"
3
+
4
+ gemspec
5
+
6
+ gem "inspec-bin"
7
+
8
+ group :development do
9
+ gem "chefstyle", "0.13.0"
10
+ gem "m"
11
+ gem "bundler"
12
+ gem "minitest"
13
+ gem "rake"
14
+ gem "rubocop"
15
+ end
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # inspec-tkinfo
2
+
3
+ InSpec plugin to retrieve Test Kitchen data as inputs.
4
+
5
+ ## Use Case
6
+
7
+ In some cases you want to get info about the Test Kitchen environment that
8
+ your InSpec verifier is running in. This plugin offers some insight into
9
+ instance name, platform name and suite name.
10
+
11
+ ## Installation
12
+
13
+ Simply execute `inspec plugin install inspec-tkinfo`, which will get
14
+ the plugin from RubyGems and install/register it with InSpec.
15
+
16
+ You can verify successful installation via `inspec plugin list`
17
+
18
+ ## Usage
19
+
20
+ You have three input names available:
21
+ - KITCHEN_INSTANCE_NAME ('default-amazon2')
22
+ - KITCHEN_SUITE_NAME ('default')
23
+ - KITCHEN_PLATFORM_NAME ('amazon2')
24
+
25
+ Use them in your InSpec tests like this:
26
+
27
+ ```ruby
28
+ instance_name = input('KITCHEN_INSTANCE_NAME')
29
+
30
+ describe file("/etc/#{instance_name}") do
31
+ it { should exist }
32
+ end
33
+ ```
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+
3
+ # As plugins are usually packaged and distributed as a RubyGem,
4
+ # we have to provide a .gemspec file, which controls the gembuild
5
+ # and publish process. This is a fairly generic gemspec.
6
+
7
+ # It is traditional in a gemspec to dynamically load the current version
8
+ # from a file in the source tree. The next three lines make that happen.
9
+ lib = File.expand_path("../lib", __FILE__)
10
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
11
+ require "inspec-tkinfo/version"
12
+
13
+ Gem::Specification.new do |spec|
14
+ # Importantly, all InSpec plugins must be prefixed with `inspec-` (most
15
+ # plugins) or `train-` (plugins which add new connectivity features).
16
+ spec.name = "inspec-tkinfo"
17
+
18
+ # It is polite to namespace your plugin under InspecPlugins::YourPluginInCamelCase
19
+ spec.version = InspecPlugins::TKInfo::VERSION
20
+ spec.authors = ["Thomas Heinen"]
21
+ spec.email = ["theinen@tecracer.de"]
22
+ spec.summary = "InSpec plugin to retrieve Test Kitchen data as inputs."
23
+ spec.description = "Allows reading instance name, suite name and platform name in tests."
24
+ spec.homepage = "https://github.com/tecracer-theinen/inspec-tkinfo"
25
+ spec.license = "Apache-2.0"
26
+
27
+ # Though complicated-looking, this is pretty standard for a gemspec.
28
+ # It just filters what will actually be packaged in the gem (leaving
29
+ # out tests, etc)
30
+ spec.files = %w{
31
+ README.md inspec-tkinfo.gemspec Gemfile
32
+ } + Dir.glob(
33
+ "lib/**/*", File::FNM_DOTMATCH
34
+ ).reject { |f| File.directory?(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_development_dependency "bump", "~> 0.8"
38
+ spec.add_development_dependency "minitest", "~> 5.11"
39
+ end
@@ -0,0 +1,4 @@
1
+ libdir = File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
3
+
4
+ require "inspec-tkinfo/plugin"
@@ -0,0 +1,55 @@
1
+ module InspecPlugins
2
+ module TKInfo
3
+ class Input < Inspec.plugin(2, :input)
4
+
5
+ # ========================================================================
6
+ # Dependency Injection
7
+
8
+ attr_writer :kitchen_instance
9
+
10
+ def kitchen_instance
11
+ require "binding_of_caller"
12
+
13
+ @kitchen_instance ||= binding.callers.find { |b| b.frame_description == "verify_action" }.receiver
14
+ end
15
+
16
+ # ========================================================================
17
+ # Input Plugin API
18
+
19
+ # Fetch method used for Input plugins
20
+ def fetch(_profile_name, input)
21
+ return nil unless valid_plugin_input?(input)
22
+
23
+ raise "Plugin can only be run via TestKitchen" unless inside_testkitchen?
24
+
25
+ case input
26
+ when "KITCHEN_INSTANCE_NAME"
27
+ kitchen_instance.name
28
+ when "KITCHEN_SUITE_NAME"
29
+ kitchen_instance.suite.name
30
+ when "KITCHEN_PLATFORM_NAME"
31
+ kitchen_instance.platform.name
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ # ========================================================================
38
+ # Helper Methods
39
+
40
+ # Verify if input is valid for this plugin
41
+ def valid_plugin_input?(input)
42
+ %w{
43
+ KITCHEN_INSTANCE_NAME
44
+ KITCHEN_SUITE_NAME
45
+ KITCHEN_PLATFORM_NAME
46
+ }.include? input
47
+ end
48
+
49
+ # Check if this is called from within TestKitchen
50
+ def inside_testkitchen?
51
+ !! defined?(::Kitchen)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+
3
+ # Plugin Definition file
4
+ # The purpose of this file is to declare to InSpec what plugin_types (capabilities)
5
+ # are included in this plugin, and provide hooks that will load them as needed.
6
+
7
+ # It is important that this file load successfully and *quickly*.
8
+ # Your plugin's functionality may never be used on this InSpec run; so we keep things
9
+ # fast and light by only loading heavy things when they are needed.
10
+
11
+ require "inspec-tkinfo/version"
12
+ module InspecPlugins
13
+ module TKInfo
14
+ class Plugin < ::Inspec.plugin(2)
15
+ # Internal machine name of the plugin. InSpec will use this in errors, etc.
16
+ plugin_name :'inspec-tkinfo'
17
+
18
+ # Define an Input plugin type.
19
+ input :tkinfo do
20
+ require_relative "input.rb"
21
+ InspecPlugins::TKInfo::Input
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: UTF-8
2
+
3
+ # This file simply makes it easier for CI engines to update
4
+ # the version stamp, and provide a clean way for the gemspec
5
+ # to learn the current version.
6
+ module InspecPlugins
7
+ module TKInfo
8
+ VERSION = "0.1.0".freeze
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inspec-tkinfo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Heinen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bump
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.11'
41
+ description: Allows reading instance name, suite name and platform name in tests.
42
+ email:
43
+ - theinen@tecracer.de
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Gemfile
49
+ - README.md
50
+ - inspec-tkinfo.gemspec
51
+ - lib/inspec-tkinfo.rb
52
+ - lib/inspec-tkinfo/input.rb
53
+ - lib/inspec-tkinfo/plugin.rb
54
+ - lib/inspec-tkinfo/version.rb
55
+ homepage: https://github.com/tecracer-theinen/inspec-tkinfo
56
+ licenses:
57
+ - Apache-2.0
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.0.3
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: InSpec plugin to retrieve Test Kitchen data as inputs.
78
+ test_files: []