New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Allow loading of arbitrary files in InSpec resources. #1396

Closed
chris-rock opened this Issue Jan 4, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@chris-rock
Copy link
Member

chris-rock commented Jan 4, 2017

Description

InSpec Resources do not allow users to load files via IO.read(File.dirname(__FILE__)). Sometimes InSpec resources store meta information in json or xml files to separate data from code. InSpec resources should support loading data from files.

I propose we add an optional files directory to our profiles.

tree examples/profile
examples/profile
├── README.md
├── controls
│   ├── gordon.rb
│   └── meta.rb
├── inspec.yml
├── files
│   ├── file1.xml
│   └── 2016.09.json
└── libraries
    └── gordon_config.rb

Once the directory is available, InSpec resources are allowed to load files via

inspec.profile.file('2016.09.json')
# in subdirectories
inspec.profile.file('platforms/amazon/2016.09.json')

Alternative options, not preferred by me are:

# everything within the profile root can be loaded
inspec.profile.file('files/platforms/amazon/2016.09.json')

A simple resource would look like:

class GordonConfig < Inspec.resource(1)
  name 'gordon_config'

  def initialize
    content = inspec.profile.file('2016.09.json')
    @params = JSON.parse(content, :symbolize_names => true)
  end

  def [](name)
    @params[name]
  end
end

@chris-rock chris-rock added the Type: RFC label Jan 4, 2017

@arlimus

This comment has been minimized.

Copy link
Contributor

arlimus commented Apr 25, 2017

Love the idea, also love that files are gated, i.e. that we don't just expose everything in the profile and provide a nice guideline on the location of these files.

  • Would love to expose this in regular control files as well; for that to happen, we'd need to expose the inspec keyword in the core DSL. This might be a good place to do this and stop the constant workarounds a la os.inspec 😁
  • I really like your first option of accessing files, i.e. inspec.profile.file('platforms/amazon/...') (instead of files/...)

What do you think @adamleff ?

arlimus added a commit that referenced this issue Apr 26, 2017

provide the `inspec` keyword
Instead of my favorite shortcut of `os.inspec` just finally add it as a global keyword.

Preparation for #1396

arlimus added a commit that referenced this issue Apr 26, 2017

provide the `inspec` keyword
Instead of my favorite shortcut of `os.inspec` just finally add it as a global keyword.

Preparation for #1396

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>

arlimus added a commit that referenced this issue Apr 26, 2017

arlimus added a commit that referenced this issue Apr 26, 2017

add `inspec.profile.file(...)` for profile files
Fixes #1396

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>

@arlimus arlimus self-assigned this Apr 26, 2017

@arlimus arlimus added the in progress label Apr 26, 2017

arlimus added a commit that referenced this issue Apr 26, 2017

add `inspec.profile.file(...)` for profile files
Fixes #1396

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>

arlimus added a commit that referenced this issue Apr 26, 2017

add `inspec.profile.file(...)` for profile files
Fixes #1396

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
@adamleff

This comment has been minimized.

Copy link
Contributor

adamleff commented Apr 26, 2017

Seems like this would be a handy feature for sure. Agreed with limiting it to the files directory only.

arlimus added a commit that referenced this issue Apr 26, 2017

add `inspec.profile.file(...)` for profile files
Fixes #1396

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>

arlimus added a commit that referenced this issue Apr 26, 2017

add `inspec.profile.file(...)` for profile files
Fixes #1396

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>

arlimus added a commit that referenced this issue Apr 26, 2017

add `inspec.profile.file(...)` for profile files
Fixes #1396

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>

arlimus added a commit that referenced this issue Apr 27, 2017

add `inspec.profile.file(...)` for profile files
Fixes #1396

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>

arlimus added a commit that referenced this issue Apr 28, 2017

add `inspec.profile.file(...)` for profile files
Fixes #1396

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>

arlimus added a commit that referenced this issue May 1, 2017

add `inspec.profile.file(...)` for profile files
Fixes #1396

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>

arlimus added a commit that referenced this issue May 2, 2017

add `inspec.profile.file(...)` for profile files
Fixes #1396

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>

arlimus added a commit that referenced this issue May 3, 2017

add `inspec.profile.file(...)` for profile files
Fixes #1396

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>

@chris-rock chris-rock removed the in progress label May 3, 2017

nsdavidson added a commit to nsdavidson/inspec that referenced this issue May 5, 2017

provide the `inspec` keyword
Instead of my favorite shortcut of `os.inspec` just finally add it as a global keyword.

Preparation for inspec#1396

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>

nsdavidson added a commit to nsdavidson/inspec that referenced this issue May 5, 2017

add `inspec.profile.file(...)` for profile files
Fixes inspec#1396

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment