inspec-plugin-example 0.4.0 → 0.5.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 +5 -5
- data/Gemfile +1 -1
- data/README.md +38 -32
- data/inspec-plugin-example.gemspec +12 -12
- data/lib/inspec-plugin-example.rb +11 -3
- data/lib/inspec-plugin-example/cli.rb +35 -24
- data/lib/inspec-plugin-example/control.rb +4 -28
- data/lib/inspec-plugin-example/plugin.rb +42 -0
- data/lib/inspec-plugin-example/second.rb +1 -3
- data/lib/inspec-plugin-example/version.rb +1 -8
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: eda4dfd762de64ea1e42623e37a878cb3888e01ee3352331b4f86d3ce6b26ba5
|
4
|
+
data.tar.gz: 16448cf8748eea56bc5844b79717f8011635e0871ac864cf95d25e4d0f61afea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cf5a756fdffba033d245e3139d5b788771d552a29fe3fbd5954d5ed9ebed6d98288a2dcaabe24758ca4387d48ccbfd246130a04b819e8aa38526e2ae8e7f465
|
7
|
+
data.tar.gz: d16e349b87bfa53cfbc148bb3391bf602190f6c1201b254781f85c58d3153cb4e3ade1833900f837a9dbe1aa346307e53cbf6ea9af886513b7f4c6407ab8261f
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,62 +1,68 @@
|
|
1
1
|
# InSpec Plugin Example
|
2
2
|
|
3
|
-
This repository provides an example of building a plugin for use with [InSpec](https://inspec.io).
|
3
|
+
This repository provides an example of building a version 2 plugin for use with [InSpec](https://inspec.io). It was built following the instructions from the [Developing InSpec Plugins for the v2 plugin API](https://github.com/inspec/inspec/blob/master/docs/dev/plugins.md) instructions.
|
4
4
|
|
5
5
|
# Requirements #
|
6
6
|
|
7
|
-
This has been built with Ruby 2.
|
7
|
+
This has been built with Ruby 2.5.1 and InSpec 3.0. It most likely works with InSpec 2.3 and later its versions of Ruby.
|
8
8
|
|
9
9
|
# Installation #
|
10
10
|
|
11
|
-
`inspec-plugin-example` is a plugin for InSpec and may be installed
|
11
|
+
`inspec-plugin-example` is a plugin for InSpec and may be installed by following the [Developing InSpec Plugins for the v2 plugin API](https://github.com/inspec/inspec/blob/master/docs/dev/plugins.md#how-plugins-are-located-and-loaded) instructions.
|
12
12
|
|
13
|
-
|
14
|
-
# install InSpec
|
15
|
-
gem install inspec
|
16
|
-
```
|
17
|
-
|
18
|
-
Then install the `inspec-plugin-example` plugin via `~/.inspec/plugins` or a gem build:
|
19
|
-
|
20
|
-
## * for development: ##
|
21
|
-
|
22
|
-
```bash
|
23
|
-
# Install `inspec-plugin-example` via a symlink:
|
24
|
-
git clone git@github.com:mattray/inspec-plugin-example ~/inspec-plugin-example
|
25
|
-
mkdir -p ~/.inspec/plugins
|
26
|
-
ln -s ~/inspec-plugin-example/ ~/.inspec/plugins/inspec-plugin-example
|
27
|
-
inspec example help
|
28
|
-
```
|
13
|
+
## ~/.inspec/plugins.json
|
29
14
|
|
30
|
-
|
15
|
+
When developing this plugin, this was the contents of my `~/.inspec/plugins.json`
|
31
16
|
|
32
|
-
```
|
33
|
-
|
34
|
-
|
35
|
-
|
17
|
+
```json
|
18
|
+
{
|
19
|
+
"plugins_config_version" : "1.0.0",
|
20
|
+
"plugins": [
|
21
|
+
{
|
22
|
+
"name": "inspec-plugin-example",
|
23
|
+
"installation_type": "path",
|
24
|
+
"installation_path": "/Users/mattray/ws/inspec-plugin-example/lib/inspec-plugin-example.rb"
|
25
|
+
}
|
26
|
+
]
|
27
|
+
}
|
36
28
|
```
|
37
29
|
|
38
30
|
# Usage #
|
39
31
|
|
40
|
-
inspec example help
|
41
|
-
|
42
32
|
inspec example control
|
43
33
|
|
34
|
+
inspec example help
|
35
|
+
|
44
36
|
inspec example version
|
45
37
|
|
38
|
+
inspec example2 second
|
39
|
+
|
46
40
|
# Code Examples #
|
47
41
|
|
42
|
+
## lib/inspec-plugin-example.rb ##
|
43
|
+
|
44
|
+
Entry point for the plugin code.
|
45
|
+
|
46
|
+
## lib/inspec-plugin-example/plugin.rb ##
|
47
|
+
|
48
|
+
Declares `example` and `example2` as InSpec subcommands within the `inspec-plugin-example` namespace.
|
49
|
+
|
48
50
|
## lib/inspec-plugin-example/cli.rb ##
|
49
51
|
|
50
|
-
|
52
|
+
Defines the `example` and `example2` CliCommands for use with InSpec.
|
53
|
+
|
54
|
+
## lib/inspec-plugin-example/control.rb ##
|
55
|
+
|
56
|
+
Example of calling another module from a CliCommand used by `inspec example control`
|
51
57
|
|
52
|
-
## lib/example/
|
58
|
+
## lib/inspec-plugin-example/second.rb ##
|
53
59
|
|
54
|
-
|
60
|
+
Example of a second CliCommand used by `inspec example2 control`
|
55
61
|
|
56
|
-
## lib/example/version.rb ##
|
62
|
+
## lib/inspec-plugin-example/version.rb ##
|
57
63
|
|
58
|
-
The version of the plugin may be defined and exposed with
|
64
|
+
The version of the plugin may be defined and exposed with `inspec example version`
|
59
65
|
|
60
66
|
# Code #
|
61
67
|
|
62
|
-
|
68
|
+
Uses the `.rubocop.yml` from InSpec for code formatting.
|
@@ -1,26 +1,26 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
|
5
|
-
require
|
5
|
+
require 'inspec-plugin-example/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
8
|
+
spec.name = 'inspec-plugin-example'
|
9
9
|
spec.version = Example::VERSION
|
10
|
-
spec.authors = [
|
11
|
-
spec.email = [
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
10
|
+
spec.authors = ['Matt Ray']
|
11
|
+
spec.email = ['matt@chef.io']
|
12
|
+
spec.summary = 'InSpec Plugin Example'
|
13
|
+
spec.description = 'Example for implementing an InSpec plugin.'
|
14
|
+
spec.homepage = 'https://github.com/mattray/inspec-plugin-example'
|
15
|
+
spec.license = 'Apache-2.0'
|
16
16
|
|
17
17
|
spec.files = %w{
|
18
18
|
README.md inspec-plugin-example.gemspec Gemfile
|
19
19
|
} + Dir.glob(
|
20
|
-
|
20
|
+
'{bin,docs,examples,lib,tasks,test}/**/*', File::FNM_DOTMATCH
|
21
21
|
).reject { |f| File.directory?(f) }
|
22
22
|
|
23
|
-
spec.require_paths = [
|
23
|
+
spec.require_paths = ['lib']
|
24
24
|
|
25
|
-
spec.add_dependency
|
25
|
+
spec.add_dependency 'inspec', '>=2.3', '<4.0.0'
|
26
26
|
end
|
@@ -1,7 +1,15 @@
|
|
1
|
-
#
|
1
|
+
# This file is known as the "entry point."
|
2
|
+
# This is the file InSpec will try to load if it
|
3
|
+
# thinks your plugin is installed.
|
4
|
+
|
5
|
+
# The *only* thing this file should do is setup the
|
6
|
+
# load path, then load the plugin definition file.
|
7
|
+
|
8
|
+
# Next two lines simply add the path of the gem to the load path.
|
9
|
+
# This is not needed when being loaded as a gem; but when doing
|
10
|
+
# plugin development, you may need it. Either way, it's harmless.
|
2
11
|
|
3
12
|
libdir = File.dirname(__FILE__)
|
4
13
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
5
14
|
|
6
|
-
|
7
|
-
require "inspec-plugin-example/version"
|
15
|
+
require_relative 'inspec-plugin-example/plugin'
|
@@ -1,44 +1,55 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require "inspec-plugin-example/control"
|
5
|
-
require "inspec-plugin-example/second"
|
1
|
+
require_relative 'control'
|
2
|
+
require_relative 'second'
|
3
|
+
require_relative 'version'
|
6
4
|
|
7
|
-
module Example
|
8
|
-
class
|
9
|
-
|
5
|
+
module InspecPlugins::Example
|
6
|
+
class CliCommand < Inspec.plugin(2, :cli_command) # Note two-arg form
|
7
|
+
subcommand_desc 'example SUBCOMMAND', 'InSpec Example Plugin commands'
|
10
8
|
|
11
|
-
|
9
|
+
class_option :debug,
|
10
|
+
desc: 'Verbose debugging messages',
|
11
|
+
type: :boolean,
|
12
|
+
default: false
|
13
|
+
|
14
|
+
desc 'version', 'Display version information' # , hide: true
|
15
|
+
long_desc <<-LONGDESC
|
16
|
+
'version' shows you an example of how to see the version of your plugin
|
17
|
+
|
18
|
+
That's what this is!
|
19
|
+
LONGDESC
|
12
20
|
|
13
|
-
desc "version", "Display version information", hide: true
|
14
21
|
def version
|
22
|
+
Inspec::Log.level = :debug if options[:debug]
|
23
|
+
Inspec::Log.debug 'Example::Version debugging message'
|
15
24
|
say("InSpec Example Plugin v#{Example::VERSION}")
|
16
25
|
end
|
17
26
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
27
|
+
desc 'control', 'Display an example InSpec Control'
|
28
|
+
long_desc <<-LONGDESC
|
29
|
+
'control' Provides an example of working with InSpec Controls
|
30
|
+
LONGDESC
|
31
|
+
|
32
|
+
option :example,
|
33
|
+
aliases: '-e',
|
34
|
+
desc: 'Example option',
|
35
|
+
type: :boolean,
|
36
|
+
default: false
|
22
37
|
|
23
|
-
desc "control", "Display an example InSpec Control"
|
24
38
|
def control
|
25
39
|
Inspec::Log.level = :debug if options[:debug]
|
26
|
-
Example::Control.print
|
40
|
+
Example::Control.print(options)
|
27
41
|
end
|
28
42
|
end
|
29
|
-
|
30
|
-
Inspec::Plugins::CLI.add_subcommand(CLI, "example", "example SUBCOMMAND ...", "Example commands", {})
|
31
43
|
end
|
32
44
|
|
33
|
-
module SecondExample
|
34
|
-
class
|
35
|
-
|
45
|
+
module InspecPlugins::SecondExample
|
46
|
+
class CliCommand < Inspec.plugin(2, :cli_command) # Note two-arg form
|
47
|
+
subcommand_desc 'example2 SUBCOMMAND', 'Second InSpec Example Plugin commands'
|
48
|
+
|
49
|
+
desc 'second', 'Second InSpec subcommand example'
|
36
50
|
|
37
|
-
desc "second", "Second InSpec subcommand example"
|
38
51
|
def second
|
39
52
|
SecondExample::Second.print
|
40
53
|
end
|
41
54
|
end
|
42
|
-
|
43
|
-
Inspec::Plugins::CLI.add_subcommand(CLI, "example2", "example2 SUBCOMMAND ...", "Additional Example commands", {})
|
44
55
|
end
|
@@ -4,36 +4,12 @@
|
|
4
4
|
# Copyright:: 2018, Chef Software, Inc <legal@chef.io>
|
5
5
|
#
|
6
6
|
|
7
|
-
require "inspec/objects/control"
|
8
|
-
require "inspec/objects/ruby_helper"
|
9
|
-
require "inspec/objects/describe"
|
10
|
-
|
11
7
|
module Example
|
12
8
|
class Control
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
ctrl = ::Inspec::Control.new
|
18
|
-
ctrl.id = "InSpecPluginExample"
|
19
|
-
ctrl.title = "Example of an InSpec Control"
|
20
|
-
ctrl.desc = "Description of an Example InSpec Control"
|
21
|
-
ctrl.impact = "1.0"
|
22
|
-
# Example of adding a Resource
|
23
|
-
describe = ::Inspec::Describe.new
|
24
|
-
# describes the Resource with the id as argument
|
25
|
-
describe.qualifier.push(["file", "/tmp/test.txt"])
|
26
|
-
# ensure the Resource exists
|
27
|
-
describe.add_test(nil, "exist", nil)
|
28
|
-
# example of testing a Resource
|
29
|
-
describe.add_test("mode", "cmp", "0644")
|
30
|
-
|
31
|
-
ctrl.add_test(describe)
|
32
|
-
|
33
|
-
# print out the Control
|
34
|
-
puts "title 'Example File Title'\n\n"
|
35
|
-
puts ctrl.to_ruby
|
9
|
+
def self.print(options)
|
10
|
+
Inspec::Log.debug 'Example::Control debugging message'
|
11
|
+
puts "This used to be an example of creating a control, now it's just a subcommand example."
|
12
|
+
puts 'I see your example option!' if options[:example]
|
36
13
|
end
|
37
|
-
|
38
14
|
end
|
39
15
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Plugin Definition file
|
2
|
+
# The purpose of this file is to declare to InSpec what plugin_types (capabilities)
|
3
|
+
# are included in this plugin, and provide hooks that will load them as needed.
|
4
|
+
|
5
|
+
# It is important that this file load successfully and *quickly*.
|
6
|
+
# Your plugin's functionality may never be used on this InSpec run; so we keep things
|
7
|
+
# fast and light by only loading heavy things when they are needed.
|
8
|
+
|
9
|
+
require 'inspec/plugin/v2'
|
10
|
+
|
11
|
+
# The InspecPlugins namespace is where all plugins should declare themselves.
|
12
|
+
# The 'Inspec' capitalization is used throughout the InSpec source code; yes, it's
|
13
|
+
# strange.
|
14
|
+
|
15
|
+
module InspecPlugins
|
16
|
+
# Pick a reasonable namespace here for your plugin. A reasonable choice
|
17
|
+
# would be the CamelCase version of your plugin gem name.
|
18
|
+
module Example
|
19
|
+
class Plugin < ::Inspec.plugin(2)
|
20
|
+
# Internal machine name of the plugin. InSpec will use this in errors, etc.
|
21
|
+
plugin_name :'inspec-plugin-example'
|
22
|
+
|
23
|
+
cli_command :example do
|
24
|
+
# Calling this hook doesn't mean example is being executed - just
|
25
|
+
# that we should be ready to do so. So, load the file that defines the
|
26
|
+
# functionality.
|
27
|
+
# For example, InSpec will activate this hook when `inspec help` is
|
28
|
+
# executed, so that this plugin's usage message will be included in the help.
|
29
|
+
require_relative 'cli'
|
30
|
+
|
31
|
+
# Having loaded our functionality, return a class that will let the
|
32
|
+
# CLI engine tap into it.
|
33
|
+
InspecPlugins::Example::CliCommand
|
34
|
+
end
|
35
|
+
|
36
|
+
cli_command :example2 do
|
37
|
+
require_relative 'cli'
|
38
|
+
InspecPlugins::SecondExample::CliCommand
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inspec-plugin-example
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Ray
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inspec
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '2.3'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 4.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: '2.3'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 4.0.0
|
33
33
|
description: Example for implementing an InSpec plugin.
|
34
34
|
email:
|
35
35
|
- matt@chef.io
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- lib/inspec-plugin-example.rb
|
44
44
|
- lib/inspec-plugin-example/cli.rb
|
45
45
|
- lib/inspec-plugin-example/control.rb
|
46
|
+
- lib/inspec-plugin-example/plugin.rb
|
46
47
|
- lib/inspec-plugin-example/second.rb
|
47
48
|
- lib/inspec-plugin-example/version.rb
|
48
49
|
homepage: https://github.com/mattray/inspec-plugin-example
|
@@ -65,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
66
|
version: '0'
|
66
67
|
requirements: []
|
67
68
|
rubyforge_project:
|
68
|
-
rubygems_version: 2.6
|
69
|
+
rubygems_version: 2.7.6
|
69
70
|
signing_key:
|
70
71
|
specification_version: 4
|
71
72
|
summary: InSpec Plugin Example
|