mirror of
https://github.com/inspec/inspec
synced 2024-11-10 15:14:23 +00:00
Support erb rendering (#3338)
* Support erb rendering Fixes: https://github.com/inspec/inspec/issues/3337 * Add UT's and docs Signed-off-by: Noel Georgi <git@frezbo.com>
This commit is contained in:
parent
006b4c7e6f
commit
9b5aaa4f87
3 changed files with 47 additions and 1 deletions
|
@ -71,6 +71,24 @@ depends:
|
|||
inspec_version: "~> 2.1"
|
||||
```
|
||||
|
||||
The `inspec.yml` also supports embedded ERB in the file. For example:
|
||||
|
||||
```YAML
|
||||
name: dummy
|
||||
title: InSpec Profile
|
||||
maintainer: The Authors
|
||||
copyright: The Authors
|
||||
copyright_email: you@example.com
|
||||
license: Apache-2.0
|
||||
summary: An InSpec Compliance Profile
|
||||
version: 0.1.0
|
||||
depends:
|
||||
- name: inherit
|
||||
url: "https://artifactory.com/artifactory/example-repo-local/inspec/0.4.1.tar.gz"
|
||||
username: <%= ENV['USERNAME'] %>
|
||||
password: <%= ENV['API_KEY'] %>
|
||||
```
|
||||
|
||||
## Verify Profiles
|
||||
|
||||
Use the `inspec check` command to verify the implementation of a profile:
|
||||
|
|
|
@ -204,7 +204,8 @@ module Inspec
|
|||
|
||||
def self.from_yaml(ref, content, profile_id, logger = nil)
|
||||
res = Metadata.new(ref, logger)
|
||||
res.params = YAML.load(content)
|
||||
require 'erb'
|
||||
res.params = YAML.load(ERB.new(content).result)
|
||||
res.content = content
|
||||
finalize(res, profile_id, {}, logger)
|
||||
end
|
||||
|
|
|
@ -27,6 +27,33 @@ describe 'metadata with supported operating systems' do
|
|||
res.content.must_equal(s)
|
||||
end
|
||||
|
||||
it 'renders a YAML containing ERB' do
|
||||
data = <<EOF
|
||||
name: dummy
|
||||
title: InSpec Profile
|
||||
maintainer: The Authors
|
||||
copyright: The Authors
|
||||
copyright_email: you@example.com
|
||||
license: Apache-2.0
|
||||
summary: An InSpec Compliance Profile
|
||||
version: 0.1.0
|
||||
depends:
|
||||
- name: inherit
|
||||
url: "https://artifactory.com/artifactory/example-repo-local/inspec/0.4.1.tar.gz"
|
||||
username: <%= ENV['USERNAME'] %>
|
||||
password: <%= ENV['API_KEY'] %>
|
||||
EOF
|
||||
ENV['USERNAME'] = 'dummy_user'
|
||||
ENV['API_KEY'] = 'dummy_pass'
|
||||
res = Inspec::Metadata.from_yaml('mock', data, nil)
|
||||
Inspec::Metadata.finalize(res, 'mock', empty_options)
|
||||
res.params[:name].must_equal 'mock'
|
||||
res.params[:depends][0][:name].must_equal 'inherit'
|
||||
res.params[:depends][0][:url].must_equal 'https://artifactory.com/artifactory/example-repo-local/inspec/0.4.1.tar.gz'
|
||||
res.params[:depends][0][:username].must_equal 'dummy_user'
|
||||
res.params[:depends][0][:password].must_equal 'dummy_pass'
|
||||
end
|
||||
|
||||
it 'finalizes a loaded metadata via Profile ID' do
|
||||
res = Inspec::Metadata.from_yaml('mock', '---', nil)
|
||||
Inspec::Metadata.finalize(res, 'mock', empty_options)
|
||||
|
|
Loading…
Reference in a new issue