inspec-reporter-flex 0.1.0 → 0.1.1

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
2
  SHA256:
3
- metadata.gz: 462241a08906f9500cc8ac2eff3d66cf9419d933b4166502dd35b5bc4445834c
4
- data.tar.gz: c6aefa556b71a5ef91ce07f3d406c4f4dddedf16c89cd577919813aa4ce3fc26
3
+ metadata.gz: 4a3a407e8d18f6b3322ae80be9966b218b3e7c74afe5ba7cebf50b2888f2121a
4
+ data.tar.gz: 272924c807526f524a99805f2d6ffc2999d1fd8f6cfe138ee63baa56efaf4a20
5
5
  SHA512:
6
- metadata.gz: ffc434833148c5c32706ebc64c479a94b05a673d1fb526ec6d4514c2ac549b542018ed7e0412f0304af4aeeb2205253ef68392a3f429679d6e7f66da9b26bb2c
7
- data.tar.gz: a737d31db943e3755e73a695bf58030851d5191e0015b9dd84a2dbe993049f98f30669ba73c4ea700e49aa896a436883853854a069670d26d749e6d5aee8b835
6
+ metadata.gz: b59accab7656b4a910ad433b862d822d0bd7cb518f965c808ed93fed7288f54c8d8b7716cebca723afe9c7bb49df4a4eb30634b5dcc6c7f4f7691bb9c9a37cff
7
+ data.tar.gz: 77667735300b220f165cc89aa14835d3f2ace950c6801d8674e3f25e2cc96413a28634a3c643f7c998e5825aafdf88670e123fb190807ffa6d80b25a624fa6dc
@@ -1,6 +1,10 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## v0.1.1
4
+
5
+ - Add configurability via environment variable
6
+ - Fix documentation and reporter to use `template_file`
7
+ - Refactor to allow better testing
4
8
 
5
9
  ## v0.1.0
6
10
 
data/README.md CHANGED
@@ -35,7 +35,7 @@ For example:
35
35
  "version": "1.2",
36
36
  "plugins": {
37
37
  "inspec-reporter-flex": {
38
- "template_file":"template/markdown.rb"
38
+ "template_file": "template/markdown.erb"
39
39
  }
40
40
  }
41
41
  }
@@ -43,9 +43,9 @@ For example:
43
43
 
44
44
  See below all customization options available:
45
45
 
46
- | Option | Default | Description |
47
- |------------------|:--------------------:|:--------------:|
48
- | `template_file` | `templates/flex.erb` | Name of the file for templating. Will look up in order "absolute path", "relative to current directory", "relative to gem directory" |
46
+ | Option | Env Variable | Default | Description |
47
+ |------------------|:------------------------------------:|:--------------------:|---------------|
48
+ | `template_file` | `INSPEC_REPORTER_FLEX_TEMPLATE_FILE` | `templates/flex.erb` | Name of the file for templating. Will look up in order "absolute path", "relative to current directory", "relative to gem directory" |
49
49
 
50
50
  ## Writing Templates
51
51
 
@@ -4,7 +4,7 @@ module InspecPlugins::FlexReporter
4
4
  #
5
5
  # @param [String] name Name or path of a file to resolve
6
6
  # @return [String] Absolute path to the file, if any
7
- # @raise [RuntimeError] if file not found
7
+ # @raise [IOError] if file not found
8
8
  def resolve_path(name)
9
9
  if absolute_path?(name)
10
10
  name
@@ -13,7 +13,7 @@ module InspecPlugins::FlexReporter
13
13
  elsif gem_path?(name)
14
14
  gem_path(name)
15
15
  else
16
- raise "Template file #{name} not found"
16
+ raise IOError, "Template file #{name} not found"
17
17
  end
18
18
  end
19
19
 
@@ -8,9 +8,13 @@ module InspecPlugins::FlexReporter
8
8
  include InspecPlugins::FlexReporter::ErbHelpers
9
9
  include InspecPlugins::FlexReporter::FileResolver
10
10
 
11
+ ENV_PREFIX = "INSPEC_REPORTER_FLEX_".freeze
12
+
13
+ attr_writer :config, :env, :inspec_config, :logger
14
+
11
15
  # Render report
12
16
  def render
13
- template_file = resolve_path(config["template"])
17
+ template_file = resolve_path(config["template_file"])
14
18
  template = ERB.new(File.read(template_file))
15
19
 
16
20
  # Use JSON Reporter base's `report` to have pre-processed data
@@ -58,10 +62,44 @@ module InspecPlugins::FlexReporter
58
62
 
59
63
  # Defaults
60
64
  @config = {
61
- "template" => "templates/flex.erb",
65
+ "template_file" => "templates/flex.erb",
62
66
  }
63
67
 
64
- @config.merge! Inspec::Config.cached.fetch_plugin_config("inspec-reporter-flex")
68
+ @config.merge! inspec_config.fetch_plugin_config("inspec-reporter-flex")
69
+ @config.merge! config_environment
70
+
71
+ logger.debug format("Configuration: %<config>s", config: @config)
72
+
73
+ @config
74
+ end
75
+
76
+ # Allow (top-level) setting overrides from environment.
77
+ #
78
+ # @return [Hash] Configuration data from environment
79
+ def config_environment
80
+ env_reporter = env.select { |var, _| var.start_with?(ENV_PREFIX) }
81
+ env_reporter.transform_keys { |key| key.delete_prefix(ENV_PREFIX).downcase }
82
+ end
83
+
84
+ # Return environment variables.
85
+ #
86
+ # @return [Hash] Mapping of environment variables
87
+ def env
88
+ @env ||= ENV
89
+ end
90
+
91
+ # Return InSpec Config object.
92
+ #
93
+ # @return [Inspec::Config] The InSpec config object
94
+ def inspec_config
95
+ @inspec_config ||= Inspec::Config.cached
96
+ end
97
+
98
+ # Return InSpec logger.
99
+ #
100
+ # @return [Inspec:Log] The Logger object
101
+ def logger
102
+ @logger ||= Inspec::Log
65
103
  end
66
104
 
67
105
  # Return InSpec Runner for further inspection.
@@ -1,5 +1,5 @@
1
1
  module InspecPlugins
2
2
  module FlexReporter
3
- VERSION = "0.1.0".freeze
3
+ VERSION = "0.1.1".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inspec-reporter-flex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Heinen