inspec-plugin-example 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2d4a170b96fee2fbd49a4d4dd495d18ede831062
4
+ data.tar.gz: c7124ddcbd2329caeb070af15f117803c08fe7cb
5
+ SHA512:
6
+ metadata.gz: 595c7a2fee421bf162ba9362fdda451f44096d3274a6de13c5bcfd2b599cc1b7b940eab8177af43bbad19e4b5d4a98d3aebdd2cf1439e15d0d20265bdb1c21aa
7
+ data.tar.gz: 8aa5a80245dd857644d0ccc70b0e003ffd9f9c4ae3f48d7d9d9c2662979dd62108c36ee18ffccc25ad7eb545e7d113c5991e8e48bf7e0d29979384fa8772eda5
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ source "https://rubygems.org"
3
+
4
+ gemspec
5
+
6
+ group :test do
7
+ gem "bundler"
8
+ gem "rake"
9
+ gem "chefstyle"
10
+ end
11
+
12
+ group :tools do
13
+ gem "github_changelog_generator"
14
+ gem "rb-readline"
15
+ end
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # InSpec Plugin Example
2
+
3
+ This repository provides an example of building a plugin for use with [InSpec](https://inspec.io).
4
+
5
+ # Requirements #
6
+
7
+ This has been built with Ruby 2.4.4 and InSpec 2.0. It most likely works with InSpec 1.5.x and its versions of Ruby.
8
+
9
+ # Installation #
10
+
11
+ `inspec-plugin-example` is a plugin for InSpec and may be installed as follows
12
+
13
+ ```bash
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
+ ```
29
+
30
+ ## * or build a gem: ##
31
+
32
+ ```bash
33
+ # Build the `inspec-plugin-example` then install:
34
+ git clone https://github.com/mattray/inspec-plugin-example && cd inspec-plugin-example && gem build *gemspec && gem install *gem
35
+ inspec example help
36
+ ```
37
+
38
+ # Usage #
39
+
40
+ inspec example help
41
+
42
+ inspec example control
43
+
44
+ inspec example version
45
+
46
+ # Code Examples #
47
+
48
+ ## lib/inspec-plugin-example/cli.rb ##
49
+
50
+ InSpec uses [Thor](http://whatisthor.com/) for adding command-line options. This shows how to add Thor subcommands for use with InSpec.
51
+
52
+ ## lib/example/control.rb ##
53
+
54
+ This shows how to use InSpec objects for building and printing Controls.
55
+
56
+ ## lib/example/version.rb ##
57
+
58
+ The version of the plugin may be defined and exposed with ```inspec example version```
59
+
60
+ # Code #
61
+
62
+ InSpec uses ```chefstyle``` for code formatting.
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require "inspec-plugin-example/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "inspec-plugin-example"
9
+ spec.version = Example::VERSION
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
+
17
+ spec.files = %w{
18
+ README.md inspec-plugin-example.gemspec Gemfile
19
+ } + Dir.glob(
20
+ "{bin,docs,examples,lib,tasks,test}/**/*", File::FNM_DOTMATCH
21
+ ).reject { |f| File.directory?(f) }
22
+
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "inspec", ">=1.51.6", "<3.0.0"
26
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ libdir = File.dirname(__FILE__)
4
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
5
+
6
+ require "inspec-plugin-example/cli"
7
+ require "inspec-plugin-example/version"
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ require "inspec/plugins"
3
+ require "thor"
4
+ require "inspec-plugin-example/control"
5
+ require "inspec-plugin-example/second"
6
+
7
+ module Example
8
+ class CLI < Thor
9
+ namespace "example"
10
+
11
+ map %w{-v --version} => "version"
12
+
13
+ desc "version", "Display version information", hide: true
14
+ def version
15
+ say("InSpec Example Plugin v#{Example::VERSION}")
16
+ end
17
+
18
+ class_option :debug,
19
+ :desc => "Verbose debugging messages",
20
+ :type => :boolean,
21
+ :default => false
22
+
23
+ desc "control", "Display an example InSpec Control"
24
+ def control
25
+ Inspec::Log.level = :debug if options[:debug]
26
+ Example::Control.print
27
+ end
28
+ end
29
+
30
+ Inspec::Plugins::CLI.add_subcommand(CLI, "example", "example SUBCOMMAND ...", "Example commands", {})
31
+ end
32
+
33
+ module SecondExample
34
+ class CLI < Thor
35
+ namespace "example2"
36
+
37
+ desc "second", "Second InSpec subcommand example"
38
+ def second
39
+ SecondExample::Second.print
40
+ end
41
+ end
42
+
43
+ Inspec::Plugins::CLI.add_subcommand(CLI, "example2", "example2 SUBCOMMAND ...", "Additional Example commands", {})
44
+ end
@@ -0,0 +1,39 @@
1
+ #
2
+ # Author:: Matt Ray (<matt@chef.io>)
3
+ #
4
+ # Copyright:: 2018, Chef Software, Inc <legal@chef.io>
5
+ #
6
+
7
+ require "inspec/objects/control"
8
+ require "inspec/objects/ruby_helper"
9
+ require "inspec/objects/describe"
10
+
11
+ module Example
12
+ class Control
13
+
14
+ def self.print
15
+ Inspec::Log.debug "Example::Control debugging message"
16
+ # Example of adding a Control
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
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ #
2
+ # Author:: Matt Ray (<matt@chef.io>)
3
+ #
4
+ # Copyright:: 2018, Chef Software, Inc <legal@chef.io>
5
+ #
6
+
7
+ module SecondExample
8
+ class Second
9
+
10
+ def self.print
11
+ puts "another example print out"
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Author:: Matt Ray (<matt@chef.io>)
4
+ #
5
+ # Copyright:: 2018, Chef Software, Inc <legal@chef.io>
6
+ #
7
+
8
+ module Example
9
+ VERSION = "0.4.0".freeze
10
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inspec-plugin-example
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Ray
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: inspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.51.6
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.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.51.6
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ description: Example for implementing an InSpec plugin.
34
+ email:
35
+ - matt@chef.io
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - Gemfile
41
+ - README.md
42
+ - inspec-plugin-example.gemspec
43
+ - lib/inspec-plugin-example.rb
44
+ - lib/inspec-plugin-example/cli.rb
45
+ - lib/inspec-plugin-example/control.rb
46
+ - lib/inspec-plugin-example/second.rb
47
+ - lib/inspec-plugin-example/version.rb
48
+ homepage: https://github.com/mattray/inspec-plugin-example
49
+ licenses:
50
+ - Apache-2.0
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.6.14.1
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: InSpec Plugin Example
72
+ test_files: []