inspec 0.9.7 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -2
- data/Gemfile +1 -0
- data/README.md +21 -2
- data/Rakefile +1 -1
- data/bin/inspec +25 -3
- data/bin/os +23 -0
- data/docs/dsl_resource.rst +90 -0
- data/docs/profiles.rst +167 -0
- data/docs/resources.rst +79 -0
- data/examples/README.md +1 -0
- data/examples/kitchen-ansible/.kitchen/logs/default-centos-71.log +0 -0
- data/examples/kitchen-ansible/.kitchen/logs/default-ubuntu-1204.log +0 -0
- data/examples/kitchen-ansible/.kitchen/logs/default-ubuntu-1404.log +432 -0
- data/examples/kitchen-ansible/.kitchen/logs/kitchen.log +10 -0
- data/examples/kitchen-ansible/Gemfile.lock +154 -0
- data/examples/kitchen-chef/.kitchen/default-centos-71.yml +6 -0
- data/examples/kitchen-chef/.kitchen/default-ubuntu-1204.yml +6 -0
- data/examples/kitchen-chef/.kitchen/default-ubuntu-1404.yml +6 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/id +1 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-centos-71/Vagrantfile +9 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/id +1 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1204/Vagrantfile +9 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/id +1 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/examples/kitchen-chef/.kitchen/kitchen-vagrant/kitchen-kitchen-chef-default-ubuntu-1404/Vagrantfile +9 -0
- data/examples/kitchen-chef/.kitchen/logs/default-centos-71.log +4 -0
- data/examples/kitchen-chef/.kitchen/logs/default-ubuntu-1204.log +4 -0
- data/examples/kitchen-chef/.kitchen/logs/default-ubuntu-1404.log +4 -0
- data/examples/kitchen-chef/.kitchen/logs/kitchen.log +8 -0
- data/examples/kitchen-chef/Berksfile.lock +11 -0
- data/examples/kitchen-chef/Gemfile.lock +223 -0
- data/examples/kitchen-puppet/.bundle/config +2 -0
- data/examples/kitchen-puppet/.kitchen/logs/default-centos-71.log +0 -0
- data/examples/kitchen-puppet/.kitchen/logs/default-ubuntu-1204.log +0 -0
- data/examples/kitchen-puppet/.kitchen/logs/default-ubuntu-1404.log +306 -0
- data/examples/kitchen-puppet/.kitchen/logs/kitchen.log +10 -0
- data/examples/kitchen-puppet/.librarian/puppet/config +2 -0
- data/examples/kitchen-puppet/Gemfile.lock +174 -0
- data/examples/kitchen-puppet/Puppetfile.lock +2 -0
- data/examples/profile/README.md +30 -0
- data/examples/profile/controls/example.rb +14 -0
- data/examples/profile/controls/gordon.rb +20 -0
- data/examples/profile/inspec.yml +10 -0
- data/examples/profile/libraries/.DS_Store +0 -0
- data/examples/profile/libraries/gordon_config.rb +17 -0
- data/examples/test-kitchen/.kitchen/logs/default-centos-71.log +5 -0
- data/examples/test-kitchen/.kitchen/logs/default-ubuntu-1204.log +5 -0
- data/examples/test-kitchen/.kitchen/logs/default-ubuntu-1404.log +5 -0
- data/examples/test-kitchen/.kitchen/logs/kitchen.log +5 -0
- data/examples/test-kitchen/Berksfile.lock +11 -0
- data/examples/test-kitchen/Gemfile.lock +233 -0
- data/inspec.gemspec +1 -1
- data/lib/.DS_Store +0 -0
- data/lib/inspec/archive/tar.rb +29 -0
- data/lib/inspec/archive/zip.rb +19 -0
- data/lib/inspec/metadata.rb +110 -15
- data/lib/inspec/profile.rb +88 -19
- data/lib/inspec/profile_context.rb +10 -4
- data/lib/inspec/resource.rb +1 -0
- data/lib/inspec/runner.rb +21 -4
- data/lib/inspec/targets.rb +2 -1
- data/lib/inspec/targets/archive.rb +39 -0
- data/lib/inspec/targets/core.rb +2 -2
- data/lib/inspec/targets/dir.rb +18 -2
- data/lib/inspec/targets/file.rb +4 -0
- data/lib/inspec/targets/folder.rb +21 -11
- data/lib/inspec/targets/tar.rb +36 -5
- data/lib/inspec/targets/url.rb +45 -13
- data/lib/inspec/targets/zip.rb +22 -15
- data/lib/inspec/version.rb +1 -1
- data/lib/matchers/matchers.rb +30 -0
- data/lib/resources/certificate.rb +0 -0
- data/lib/resources/etc_group.rb +1 -1
- data/lib/resources/file.rb +28 -3
- data/lib/resources/mount.rb +57 -0
- data/lib/resources/passwd.rb +1 -1
- data/lib/resources/private_key.rb +0 -0
- data/lib/resources/user.rb +3 -2
- data/lib/utils/hash.rb +29 -1
- data/lib/utils/parser.rb +34 -1
- data/lib/utils/simpleconfig.rb +1 -1
- data/test/chefdk/.gitignore +16 -0
- data/test/chefdk/.kitchen.yml +27 -0
- data/test/chefdk/Policyfile.rb +16 -0
- data/test/chefdk/README.md +4 -0
- data/test/chefdk/chefignore +100 -0
- data/test/chefdk/metadata.rb +7 -0
- data/test/chefdk/recipes/default.rb +5 -0
- data/test/chefdk/spec/spec_helper.rb +2 -0
- data/test/chefdk/spec/unit/recipes/default_spec.rb +20 -0
- data/test/chefdk/test/integration/default/serverspec/default_spec.rb +9 -0
- data/test/chefdk/test/integration/helpers/serverspec/spec_helper.rb +8 -0
- data/test/helper.rb +3 -1
- data/test/integration/.DS_Store +0 -0
- data/test/integration/.kitchen.ec2.yml +67 -0
- data/test/integration/.kitchen.local.yml +68 -0
- data/test/integration/.kitchen/default-aws-linux.yml +4 -0
- data/test/integration/.kitchen/default-centos-511.yml +6 -0
- data/test/integration/.kitchen/default-centos-67.yml +6 -0
- data/test/integration/.kitchen/default-centos-7.yml +4 -0
- data/test/integration/.kitchen/default-centos-71.yml +6 -0
- data/test/integration/.kitchen/default-debian-6010.yml +6 -0
- data/test/integration/.kitchen/default-debian-78.yml +6 -0
- data/test/integration/.kitchen/default-debian-8.yml +4 -0
- data/test/integration/.kitchen/default-debian-81.yml +6 -0
- data/test/integration/.kitchen/default-fedora-21.yml +6 -0
- data/test/integration/.kitchen/default-fedora-22.yml +4 -0
- data/test/integration/.kitchen/default-freebsd-102.yml +6 -0
- data/test/integration/.kitchen/default-freebsd-93.yml +6 -0
- data/test/integration/.kitchen/default-opensuse-132-x86-64.yml +6 -0
- data/test/integration/.kitchen/default-redhat-65.yml +4 -0
- data/test/integration/.kitchen/default-redhat-71.yml +4 -0
- data/test/integration/.kitchen/default-suse-11sp3.yml +4 -0
- data/test/integration/.kitchen/default-suse-12.yml +4 -0
- data/test/integration/.kitchen/default-ubuntu-1004.yml +6 -0
- data/test/integration/.kitchen/default-ubuntu-1204.yml +4 -0
- data/test/integration/.kitchen/default-ubuntu-1404.yml +4 -0
- data/test/integration/.kitchen/default-ubuntu-1510.yml +4 -0
- data/test/integration/.kitchen/default-windows-2012.yml +5 -0
- data/test/integration/.kitchen/default-windows-2012r2.yml +6 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/id +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-511/Vagrantfile +9 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67-i386/Vagrantfile +9 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/id +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-67/Vagrantfile +9 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/id +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-centos-71/Vagrantfile +9 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/id +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-6010/Vagrantfile +9 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/id +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-78/Vagrantfile +9 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/id +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-debian-81/Vagrantfile +9 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/id +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-21/Vagrantfile +9 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/id +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-fedora-22/Vagrantfile +9 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/id +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-102/Vagrantfile +9 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/id +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-freebsd-93/Vagrantfile +9 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/id +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-opensuse-132-x86-64/Vagrantfile +9 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/id +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1004/Vagrantfile +9 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/id +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1204/Vagrantfile +9 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/id +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-default-ubuntu-1404/Vagrantfile +9 -0
- data/test/integration/.kitchen/kitchen-vagrant/kitchen-integration-new-ubuntu-1404/Vagrantfile +9 -0
- data/test/integration/.kitchen/logs/default-aws-linux.log +0 -0
- data/test/integration/.kitchen/logs/default-centos-511-i386.log +0 -0
- data/test/integration/.kitchen/logs/default-centos-511.log +0 -0
- data/test/integration/.kitchen/logs/default-centos-67-i386.log +0 -0
- data/test/integration/.kitchen/logs/default-centos-67.log +0 -0
- data/test/integration/.kitchen/logs/default-centos-7.log +0 -0
- data/test/integration/.kitchen/logs/default-centos-71.log +0 -0
- data/test/integration/.kitchen/logs/default-debian-6010-i386.log +0 -0
- data/test/integration/.kitchen/logs/default-debian-6010.log +0 -0
- data/test/integration/.kitchen/logs/default-debian-78-i386.log +0 -0
- data/test/integration/.kitchen/logs/default-debian-78.log +0 -0
- data/test/integration/.kitchen/logs/default-debian-8.log +0 -0
- data/test/integration/.kitchen/logs/default-debian-81-i386.log +0 -0
- data/test/integration/.kitchen/logs/default-debian-81.log +0 -0
- data/test/integration/.kitchen/logs/default-fedora-21-i386.log +0 -0
- data/test/integration/.kitchen/logs/default-fedora-21.log +0 -0
- data/test/integration/.kitchen/logs/default-fedora-22.log +0 -0
- data/test/integration/.kitchen/logs/default-freebsd-102.log +0 -0
- data/test/integration/.kitchen/logs/default-freebsd-93.log +0 -0
- data/test/integration/.kitchen/logs/default-mint-172-cinnamon.log +0 -0
- data/test/integration/.kitchen/logs/default-opensuse-132-i386.log +0 -0
- data/test/integration/.kitchen/logs/default-opensuse-132-x86-64.log +0 -0
- data/test/integration/.kitchen/logs/default-redhat-65.log +0 -0
- data/test/integration/.kitchen/logs/default-redhat-71.log +0 -0
- data/test/integration/.kitchen/logs/default-suse-11sp3.log +0 -0
- data/test/integration/.kitchen/logs/default-suse-12.log +0 -0
- data/test/integration/.kitchen/logs/default-ubuntu-1004-i386.log +0 -0
- data/test/integration/.kitchen/logs/default-ubuntu-1004.log +0 -0
- data/test/integration/.kitchen/logs/default-ubuntu-1204-i386.log +0 -0
- data/test/integration/.kitchen/logs/default-ubuntu-1204.log +23 -0
- data/test/integration/.kitchen/logs/default-ubuntu-1404-i386.log +0 -0
- data/test/integration/.kitchen/logs/default-ubuntu-1404.log +0 -0
- data/test/integration/.kitchen/logs/default-ubuntu-1510.log +0 -0
- data/test/integration/.kitchen/logs/default-windows-2012.log +0 -0
- data/test/integration/.kitchen/logs/default-windows-2012r2.log +0 -0
- data/test/integration/.kitchen/logs/kitchen.log +3 -0
- data/test/integration/.kitchen/logs/new-centos-511-i386.log +0 -0
- data/test/integration/.kitchen/logs/new-centos-511.log +0 -0
- data/test/integration/.kitchen/logs/new-centos-67-i386.log +0 -0
- data/test/integration/.kitchen/logs/new-centos-67.log +0 -0
- data/test/integration/.kitchen/logs/new-centos-71.log +0 -0
- data/test/integration/.kitchen/logs/new-debian-6010-i386.log +0 -0
- data/test/integration/.kitchen/logs/new-debian-6010.log +0 -0
- data/test/integration/.kitchen/logs/new-debian-78-i386.log +0 -0
- data/test/integration/.kitchen/logs/new-debian-78.log +0 -0
- data/test/integration/.kitchen/logs/new-debian-81-i386.log +0 -0
- data/test/integration/.kitchen/logs/new-debian-81.log +0 -0
- data/test/integration/.kitchen/logs/new-fedora-21-i386.log +0 -0
- data/test/integration/.kitchen/logs/new-fedora-21.log +0 -0
- data/test/integration/.kitchen/logs/new-fedora-22.log +0 -0
- data/test/integration/.kitchen/logs/new-freebsd-102.log +0 -0
- data/test/integration/.kitchen/logs/new-freebsd-93.log +0 -0
- data/test/integration/.kitchen/logs/new-opensuse-132-i386.log +0 -0
- data/test/integration/.kitchen/logs/new-opensuse-132-x86-64.log +0 -0
- data/test/integration/.kitchen/logs/new-ubuntu-1004-i386.log +0 -0
- data/test/integration/.kitchen/logs/new-ubuntu-1004.log +0 -0
- data/test/integration/.kitchen/logs/new-ubuntu-1204-i386.log +0 -0
- data/test/integration/.kitchen/logs/new-ubuntu-1204.log +0 -0
- data/test/integration/.kitchen/logs/new-ubuntu-1404-i386.log +0 -0
- data/test/integration/.kitchen/logs/new-ubuntu-1404.log +3 -0
- data/test/integration/.kitchen/logs/test-centos-511-i386.log +0 -0
- data/test/integration/.kitchen/logs/test-centos-511.log +0 -0
- data/test/integration/.kitchen/logs/test-centos-67-i386.log +0 -0
- data/test/integration/.kitchen/logs/test-centos-67.log +0 -0
- data/test/integration/.kitchen/logs/test-centos-71.log +0 -0
- data/test/integration/.kitchen/logs/test-debian-6010-i386.log +0 -0
- data/test/integration/.kitchen/logs/test-debian-6010.log +0 -0
- data/test/integration/.kitchen/logs/test-debian-78-i386.log +0 -0
- data/test/integration/.kitchen/logs/test-debian-78.log +0 -0
- data/test/integration/.kitchen/logs/test-debian-81-i386.log +0 -0
- data/test/integration/.kitchen/logs/test-debian-81.log +0 -0
- data/test/integration/.kitchen/logs/test-fedora-21-i386.log +0 -0
- data/test/integration/.kitchen/logs/test-fedora-21.log +0 -0
- data/test/integration/.kitchen/logs/test-fedora-22.log +0 -0
- data/test/integration/.kitchen/logs/test-freebsd-102.log +0 -0
- data/test/integration/.kitchen/logs/test-freebsd-93.log +0 -0
- data/test/integration/.kitchen/logs/test-opensuse-132-i386.log +0 -0
- data/test/integration/.kitchen/logs/test-opensuse-132-x86-64.log +0 -0
- data/test/integration/.kitchen/logs/test-ubuntu-1004-i386.log +0 -0
- data/test/integration/.kitchen/logs/test-ubuntu-1004.log +0 -0
- data/test/integration/.kitchen/logs/test-ubuntu-1204-i386.log +0 -0
- data/test/integration/.kitchen/logs/test-ubuntu-1204.log +0 -0
- data/test/integration/.kitchen/logs/test-ubuntu-1404-i386.log +0 -0
- data/test/integration/.kitchen/logs/test-ubuntu-1404.log +0 -0
- data/test/integration/.kitchen/new-ubuntu-1404.yml +1 -0
- data/test/integration/Berksfile.lock +11 -0
- data/test/integration/TODO.md +15 -0
- data/test/integration/cookbooks/os_prepare/recipes/default.rb +1 -0
- data/test/integration/cookbooks/os_prepare/recipes/json_yaml_csv_ini.rb +13 -6
- data/test/integration/cookbooks/os_prepare/recipes/mount.rb +29 -0
- data/test/integration/test/.DS_Store +0 -0
- data/test/integration/test/integration/.DS_Store +0 -0
- data/test/integration/test/integration/default/.DS_Store +0 -0
- data/test/integration/test/integration/default/certificate_spec.rb +7 -0
- data/test/integration/test/integration/default/csv_spec.rb +7 -1
- data/test/integration/test/integration/default/file_spec.rb +29 -0
- data/test/integration/test/integration/default/ini_spec.rb +7 -1
- data/test/integration/test/integration/default/json_spec.rb +7 -1
- data/test/integration/test/integration/default/mount_spec.rb +10 -0
- data/test/integration/test/integration/default/yaml_spec.rb +7 -1
- data/test/serverspec/.kitchen.yml +18 -0
- data/test/serverspec/.kitchen/default-ubuntu-1404.yml +6 -0
- data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/action_set_name +1 -0
- data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/creator_uid +1 -0
- data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/id +1 -0
- data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/index_uuid +1 -0
- data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/private_key +27 -0
- data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/.vagrant/machines/default/virtualbox/synced_folders +1 -0
- data/test/serverspec/.kitchen/kitchen-vagrant/kitchen-serverspec-default-ubuntu-1404/Vagrantfile +9 -0
- data/test/serverspec/.kitchen/logs/default-ubuntu-1404.log +2 -0
- data/test/serverspec/.kitchen/logs/kitchen.log +3 -0
- data/test/serverspec/Berksfile +3 -0
- data/test/serverspec/Berksfile.lock +5 -0
- data/test/serverspec/TODO.md +2 -0
- data/test/serverspec/test/integration/default/serverspec/os_spec.rb +25 -0
- data/test/serverspec/test/integration/default/serverspec/spec_helper.rb +48 -0
- data/test/serverspec/test/integration/default/serverspec/sysctl_spec.rb +37 -0
- data/test/unit/metadata_test.rb +69 -0
- data/test/unit/mock/cmd/mount +1 -0
- data/test/unit/mock/cmd/mount-multiple +2 -0
- data/test/unit/mock/profiles/complete-meta/metadata.rb +7 -0
- data/test/unit/mock/profiles/complete-meta/test/.gitkeep +0 -0
- data/test/unit/mock/profiles/complete-profile/controls/filesystem_spec.rb +16 -0
- data/test/unit/mock/profiles/complete-profile/inspec.yml +10 -0
- data/test/unit/profile_context_test.rb +2 -2
- data/test/unit/profile_test.rb +63 -6
- data/test/unit/resources/file_test.rb +4 -0
- data/test/unit/resources/mount_test.rb +26 -0
- data/test/unit/utils/{content_parser_test.rb → passwd_parser_test.rb} +2 -2
- metadata +588 -5
data/inspec.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
25
25
|
spec.require_paths = ['lib']
|
26
26
|
|
27
|
-
spec.add_dependency 'r-train', '~> 0.9'
|
27
|
+
spec.add_dependency 'r-train', '~> 0.9', '>= 0.9.3'
|
28
28
|
spec.add_dependency 'thor', '~> 0.19'
|
29
29
|
spec.add_dependency 'json', '~> 1.8'
|
30
30
|
spec.add_dependency 'rainbow', '~> 2'
|
data/lib/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Christoph Hartmann
|
3
|
+
# author: Dominik Richter
|
4
|
+
|
5
|
+
require 'rubygems/package'
|
6
|
+
|
7
|
+
module Inspec::Archive
|
8
|
+
class TarArchiveGenerator
|
9
|
+
def archive(base_dir, files, archive)
|
10
|
+
File.open(archive, 'wb') do |file|
|
11
|
+
Zlib::GzipWriter.wrap(file) do |gz|
|
12
|
+
Gem::Package::TarWriter.new(gz) do |tar|
|
13
|
+
files.each do |input_filename|
|
14
|
+
path = Pathname.new(base_dir).join(input_filename)
|
15
|
+
stat = File.stat(path)
|
16
|
+
if path.directory?
|
17
|
+
tar.mkdir(input_filename, stat.mode)
|
18
|
+
else
|
19
|
+
tar.add_file_simple(input_filename, stat.mode, stat.size) do |io|
|
20
|
+
io.write(File.read(path))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Christoph Hartmann
|
3
|
+
# author: Dominik Richter
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'zip'
|
7
|
+
require 'pathname'
|
8
|
+
|
9
|
+
module Inspec::Archive
|
10
|
+
class ZipArchiveGenerator
|
11
|
+
def archive(base_dir, files, archive)
|
12
|
+
Zip::File.open(archive, Zip::File::CREATE) do |zipfile|
|
13
|
+
files.each do |input_filename|
|
14
|
+
zipfile.add(input_filename, Pathname.new(base_dir).join(input_filename))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/inspec/metadata.rb
CHANGED
@@ -7,9 +7,11 @@ require 'logger'
|
|
7
7
|
|
8
8
|
module Inspec
|
9
9
|
# Extract metadata.rb information
|
10
|
-
class Metadata
|
11
|
-
attr_reader :
|
12
|
-
|
10
|
+
class Metadata # rubocop:disable Metrics/ClassLength
|
11
|
+
attr_reader :ref
|
12
|
+
attr_accessor :params
|
13
|
+
def initialize(ref, logger = nil)
|
14
|
+
@ref = ref
|
13
15
|
@logger = logger || Logger.new(nil)
|
14
16
|
@params = {}
|
15
17
|
@missing_methods = []
|
@@ -35,45 +37,138 @@ module Inspec
|
|
35
37
|
def supports(sth, version = nil)
|
36
38
|
params[:supports] ||= []
|
37
39
|
params[:supports].push(
|
40
|
+
# do not use hash syntax for `-` to work properly with ruby 1.9.3 parser
|
38
41
|
{
|
39
|
-
os
|
42
|
+
:'os-name' => sth, # rubocop:disable Style/HashSyntax, Lint/UnneededDisable
|
40
43
|
version: version,
|
41
44
|
},
|
42
45
|
)
|
43
46
|
end
|
44
47
|
|
48
|
+
def is_supported(os, entry)
|
49
|
+
name, family, release = support_fields(entry)
|
50
|
+
|
51
|
+
# return true if the backend matches the supported OS's
|
52
|
+
# fields act as masks, i.e. any value configured for os-name, os-family,
|
53
|
+
# or release must be met by the backend; any field that is nil acts as
|
54
|
+
# a glob expression i.e. is true
|
55
|
+
|
56
|
+
# os name is both saved in :family and :name, so check both
|
57
|
+
name_ok = name.nil? ||
|
58
|
+
os[:name] == name || os[:family] == name
|
59
|
+
|
60
|
+
family_check = family.to_s + '?'
|
61
|
+
family_ok = family.nil? || os[:family] == family ||
|
62
|
+
(
|
63
|
+
os.respond_to?(family_check) &&
|
64
|
+
# this call will return true if the family matches
|
65
|
+
os.method(family_check).call
|
66
|
+
)
|
67
|
+
|
68
|
+
release_ok = release.nil? || os[:release] == release
|
69
|
+
|
70
|
+
# we want to make sure that all matchers are true
|
71
|
+
name_ok && family_ok && release_ok
|
72
|
+
end
|
73
|
+
|
74
|
+
def support_fields(entry)
|
75
|
+
if entry.is_a?(Hash)
|
76
|
+
try_support = self.class.symbolize_keys(entry)
|
77
|
+
name = try_support[:'os-name'] || try_support[:os]
|
78
|
+
family = try_support[:'os-family']
|
79
|
+
release = try_support[:release]
|
80
|
+
elsif entry.is_a?(String)
|
81
|
+
@logger.warn("Using deprecated `supports` syntax: using `#{entry}` as OS family")
|
82
|
+
family = entry
|
83
|
+
end
|
84
|
+
|
85
|
+
[name, family, release]
|
86
|
+
end
|
87
|
+
|
88
|
+
def supports_transport?(backend)
|
89
|
+
# make sure the supports field is always an array
|
90
|
+
supp = params[:supports]
|
91
|
+
supp = supp.is_a?(Hash) ? [supp] : Array(supp)
|
92
|
+
|
93
|
+
# with no supports specified, always return true, as there are no
|
94
|
+
# constraints on the supported backend; it is equivalent to putting
|
95
|
+
# all fields into accept-all mode
|
96
|
+
return true if supp.empty?
|
97
|
+
|
98
|
+
found = supp.find do |entry|
|
99
|
+
is_supported(backend.os, entry)
|
100
|
+
end
|
101
|
+
|
102
|
+
# finally, if we found a supported entry, we are good to go
|
103
|
+
!found.nil?
|
104
|
+
end
|
105
|
+
|
45
106
|
def valid?
|
46
107
|
is_valid = true
|
47
|
-
%w{ name
|
108
|
+
%w{ name version }.each do |field|
|
48
109
|
next unless params[field.to_sym].nil?
|
49
|
-
@logger.error("Missing profile #{field} in
|
110
|
+
@logger.error("Missing profile #{field} in #{ref}")
|
50
111
|
is_valid = false
|
51
112
|
end
|
52
|
-
%w{ maintainer copyright }.each do |field|
|
113
|
+
%w{ title summary maintainer copyright }.each do |field|
|
53
114
|
next unless params[field.to_sym].nil?
|
54
|
-
@logger.warn("Missing profile #{field} in
|
115
|
+
@logger.warn("Missing profile #{field} in #{ref}")
|
55
116
|
is_valid = false
|
56
117
|
end
|
57
118
|
is_valid && @missing_methods.empty?
|
58
119
|
end
|
59
120
|
|
60
121
|
def method_missing(sth, *args)
|
61
|
-
@logger.warn "
|
122
|
+
@logger.warn "#{ref} doesn't support: #{sth} #{args}"
|
62
123
|
@missing_methods.push(sth)
|
63
124
|
end
|
64
125
|
|
65
|
-
def self.
|
66
|
-
|
126
|
+
def self.symbolize_keys(hash)
|
127
|
+
hash.each_with_object({}) {|(k, v), h|
|
128
|
+
v = symbolize_keys(v) if v.is_a?(Hash)
|
129
|
+
h[k.to_sym] = v
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
def self.finalize(metadata, profile_id)
|
134
|
+
metadata.params['name'] = profile_id.to_s unless profile_id.to_s.empty?
|
135
|
+
metadata.params = symbolize_keys(metadata.params || {})
|
136
|
+
metadata
|
137
|
+
end
|
138
|
+
|
139
|
+
def self.from_yaml(ref, contents, profile_id, logger = nil)
|
140
|
+
res = Metadata.new(ref, logger)
|
141
|
+
res.params = YAML.load(contents)
|
142
|
+
finalize(res, profile_id)
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.from_ruby(ref, contents, profile_id, logger = nil)
|
146
|
+
res = Metadata.new(ref, logger)
|
147
|
+
res.instance_eval(contents, ref, 1)
|
148
|
+
finalize(res, profile_id)
|
149
|
+
end
|
67
150
|
|
151
|
+
def self.from_ref(ref, contents, profile_id, logger = nil)
|
152
|
+
case File.basename(ref)
|
153
|
+
when 'inspec.yml'
|
154
|
+
from_yaml(ref, contents, profile_id, logger)
|
155
|
+
when 'metadata.rb'
|
156
|
+
from_ruby(ref, contents, profile_id, logger)
|
157
|
+
else
|
158
|
+
logger ||= Logger.new(nil)
|
159
|
+
logger.error "Don't know how to handle metadata in #{ref}"
|
160
|
+
nil
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def self.from_file(path, profile_id, logger = nil)
|
68
165
|
unless File.file?(path)
|
166
|
+
logger ||= Logger.new(nil)
|
69
167
|
logger.error "Can't find metadata file #{path}"
|
70
168
|
return nil
|
71
169
|
end
|
72
170
|
|
73
|
-
|
74
|
-
res.instance_eval(File.read(path), path, 1)
|
75
|
-
res.params[:name] = profile_id.to_s unless profile_id.to_s.empty?
|
76
|
-
res
|
171
|
+
from_ref(File.basename(path), File.read(path), profile_id, logger)
|
77
172
|
end
|
78
173
|
end
|
79
174
|
end
|
data/lib/inspec/profile.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
# author: Christoph Hartmann
|
5
5
|
|
6
6
|
require 'inspec/metadata'
|
7
|
+
require 'pathname'
|
7
8
|
|
8
9
|
module Inspec
|
9
10
|
class Profile # rubocop:disable Metrics/ClassLength
|
@@ -15,11 +16,11 @@ module Inspec
|
|
15
16
|
end
|
16
17
|
|
17
18
|
attr_reader :params
|
18
|
-
attr_reader :
|
19
|
+
attr_reader :path
|
19
20
|
|
20
21
|
def initialize(options = nil)
|
21
22
|
@options = options || {}
|
22
|
-
|
23
|
+
|
23
24
|
@params = {}
|
24
25
|
@logger = options[:logger] || Logger.new(nil)
|
25
26
|
|
@@ -28,14 +29,16 @@ module Inspec
|
|
28
29
|
fail "Cannot find directory #{@path}" unless File.directory?(@path)
|
29
30
|
|
30
31
|
@metadata = read_metadata
|
31
|
-
@params = @metadata.params
|
32
|
+
@params = @metadata.params
|
33
|
+
# use the id from parameter, name or fallback to nil
|
34
|
+
@profile_id = options[:id] || params[:name] || nil
|
32
35
|
|
33
36
|
@params[:rules] = rules = {}
|
34
37
|
@runner = Runner.new(
|
35
38
|
id: @profile_id,
|
36
39
|
backend: :mock,
|
37
40
|
)
|
38
|
-
@runner.add_tests([@path])
|
41
|
+
@runner.add_tests([@path], @options)
|
39
42
|
@runner.rules.each do |id, rule|
|
40
43
|
file = rule.instance_variable_get(:@__file)
|
41
44
|
rules[file] ||= {}
|
@@ -92,23 +95,23 @@ module Inspec
|
|
92
95
|
|
93
96
|
@logger.info "Checking profile in #{@path}"
|
94
97
|
|
95
|
-
if
|
96
|
-
|
97
|
-
elsif !(@params[:name].to_s =~ %r{^\S+\/\S+$})
|
98
|
-
error.call('Profile name must be defined as: OWNER/ID')
|
98
|
+
if Pathname.new(path).join('metadata.rb').exist?
|
99
|
+
warn.call('The use of `metadata.rb` is deprecated. Use `inspec.yml`.')
|
99
100
|
end
|
100
101
|
|
101
|
-
|
102
|
-
warn.call('No title defined') if @params[:name].to_s.empty?
|
103
|
-
warn.call('No maintainer defined') if @params[:name].to_s.empty?
|
104
|
-
warn.call('No supports defined') if @params[:name].empty?
|
105
|
-
@logger.info 'Metadata OK.' if no_warnings
|
102
|
+
@logger.info 'Metadata OK.' if @metadata.valid?
|
106
103
|
|
107
|
-
|
108
|
-
|
109
|
-
|
104
|
+
# check if the profile is using the old test directory instead of the
|
105
|
+
# new controls directory
|
106
|
+
if Pathname.new(path).join('test').exist? && !Pathname.new(path).join('controls').exist?
|
107
|
+
warn.call('Profile uses deprecated `test` directory, rename it to `controls`')
|
108
|
+
end
|
109
|
+
|
110
|
+
count = rules_count
|
111
|
+
if count == 0
|
112
|
+
warn.call('No controls or tests were defined.')
|
110
113
|
else
|
111
|
-
@logger.
|
114
|
+
@logger.info("Found #{count} rules.")
|
112
115
|
end
|
113
116
|
|
114
117
|
# iterate over hash of groups
|
@@ -116,6 +119,7 @@ module Inspec
|
|
116
119
|
@logger.debug "Verify all rules in #{group}"
|
117
120
|
rules_array.each do |id, rule|
|
118
121
|
error.call('Avoid rules with empty IDs') if id.nil? or id.empty?
|
122
|
+
next if id.start_with? '(generated '
|
119
123
|
warn.call("Rule #{id} has no title") if rule[:title].to_s.empty?
|
120
124
|
warn.call("Rule #{id} has no description") if rule[:desc].to_s.empty?
|
121
125
|
warn.call("Rule #{id} has impact > 1.0") if rule[:impact].to_f > 1.0
|
@@ -128,11 +132,76 @@ module Inspec
|
|
128
132
|
no_errors
|
129
133
|
end
|
130
134
|
|
135
|
+
def rules_count
|
136
|
+
@params[:rules].values.map { |hm| hm.values.length }.inject(:+) || 0
|
137
|
+
end
|
138
|
+
|
139
|
+
# generates a archive of a folder profile
|
140
|
+
def archive(opts) # rubocop:disable Metrics/AbcSize
|
141
|
+
check_result = check
|
142
|
+
|
143
|
+
if check_result && !opts.ignore_errors == false
|
144
|
+
@logger.info 'Profile check failed. Please fix the profile before generating an archive.'
|
145
|
+
return false
|
146
|
+
end
|
147
|
+
|
148
|
+
profile_name = @params[:name]
|
149
|
+
|
150
|
+
opts[:zip] ? ext='zip' : ext='tar.gz'
|
151
|
+
slug = profile_name.downcase.strip.tr(' ', '-').gsub(/[^\w-]/, '_')
|
152
|
+
archive = Pathname.new(File.dirname(__FILE__)).join('../..', "#{slug}.#{ext}")
|
153
|
+
|
154
|
+
# check if file exists otherwise overwrite the archive
|
155
|
+
if archive.exist? && !opts[:overwrite]
|
156
|
+
@logger.info "Archive #{archive} exists already. Use --overwrite."
|
157
|
+
return false
|
158
|
+
end
|
159
|
+
|
160
|
+
# remove existing archive
|
161
|
+
File.delete(archive) if archive.exist?
|
162
|
+
|
163
|
+
@logger.info "Profile check finished. Generate archive #{archive}."
|
164
|
+
|
165
|
+
# find all files
|
166
|
+
files = Dir.glob("#{path}/**/*")
|
167
|
+
|
168
|
+
# filter files that should not be part of the profile
|
169
|
+
# TODO ignore all .files, but add the files to debug output
|
170
|
+
|
171
|
+
# map absolute paths to relative paths
|
172
|
+
files = files.collect { |f| Pathname.new(f).relative_path_from(Pathname.new(path)).to_s }
|
173
|
+
|
174
|
+
# display all files that will be part of the archive
|
175
|
+
@logger.debug 'Add the following files to archive:'
|
176
|
+
files.each { |f|
|
177
|
+
@logger.debug ' ' + f
|
178
|
+
}
|
179
|
+
|
180
|
+
if opts[:zip]
|
181
|
+
# generate zip archive
|
182
|
+
require 'inspec/archive/zip'
|
183
|
+
zag = Inspec::Archive::ZipArchiveGenerator.new
|
184
|
+
zag.archive(path, files, archive)
|
185
|
+
else
|
186
|
+
# generate tar archive
|
187
|
+
require 'inspec/archive/tar'
|
188
|
+
tag = Inspec::Archive::TarArchiveGenerator.new
|
189
|
+
tag.archive(path, files, archive)
|
190
|
+
end
|
191
|
+
|
192
|
+
@logger.info 'Finished archive generation.'
|
193
|
+
true
|
194
|
+
end
|
195
|
+
|
131
196
|
private
|
132
197
|
|
133
198
|
def read_metadata
|
134
|
-
mpath =
|
135
|
-
|
199
|
+
mpath = Pathname.new(path).join('inspec.yml')
|
200
|
+
|
201
|
+
# fallback to metadata.rb if inspec.yml does not exist
|
202
|
+
# TODO deprecated, will be removed in InSpec 1.0
|
203
|
+
mpath = File.join(@path, 'metadata.rb') if !mpath.exist?
|
204
|
+
Metadata.from_file(mpath, @profile_id, @logger)
|
136
205
|
end
|
137
206
|
end
|
138
207
|
end
|
@@ -19,11 +19,15 @@ module Inspec
|
|
19
19
|
@profile_id = profile_id
|
20
20
|
@rules = profile_registry
|
21
21
|
@only_ifs = only_ifs
|
22
|
+
@backend = backend
|
22
23
|
|
23
|
-
|
24
|
+
reload_dsl
|
25
|
+
end
|
26
|
+
|
27
|
+
def reload_dsl
|
28
|
+
dsl = create_inner_dsl(@backend)
|
24
29
|
outer_dsl = create_outer_dsl(dsl)
|
25
30
|
ctx = create_context(outer_dsl)
|
26
|
-
|
27
31
|
@profile_context = ctx.new
|
28
32
|
end
|
29
33
|
|
@@ -111,7 +115,7 @@ module Inspec
|
|
111
115
|
define_method :describe do |*args, &block|
|
112
116
|
path = block.source_location[0]
|
113
117
|
line = block.source_location[1]
|
114
|
-
id = "#{File.basename(path)}:#{line} #{SecureRandom.hex}"
|
118
|
+
id = "(generated from #{File.basename(path)}:#{line} #{SecureRandom.hex})"
|
115
119
|
rule = rule_class.new(id, {}) do
|
116
120
|
describe(*args, &block)
|
117
121
|
end
|
@@ -123,10 +127,12 @@ module Inspec
|
|
123
127
|
nil
|
124
128
|
end
|
125
129
|
|
126
|
-
def
|
130
|
+
def skip_control(id)
|
127
131
|
__unregister_rule id
|
128
132
|
end
|
129
133
|
|
134
|
+
alias_method :skip_rule, :skip_control
|
135
|
+
|
130
136
|
def only_if(&block)
|
131
137
|
return unless block_given?
|
132
138
|
@skip_profile = !block.call
|
data/lib/inspec/resource.rb
CHANGED
@@ -44,6 +44,7 @@ require 'resources/kernel_module'
|
|
44
44
|
require 'resources/kernel_parameter'
|
45
45
|
require 'resources/limits_conf'
|
46
46
|
require 'resources/login_def'
|
47
|
+
require 'resources/mount'
|
47
48
|
require 'resources/mysql'
|
48
49
|
require 'resources/mysql_conf'
|
49
50
|
require 'resources/mysql_session'
|
data/lib/inspec/runner.rb
CHANGED
@@ -8,6 +8,7 @@ require 'uri'
|
|
8
8
|
require 'inspec/backend'
|
9
9
|
require 'inspec/profile_context'
|
10
10
|
require 'inspec/targets'
|
11
|
+
require 'inspec/metadata'
|
11
12
|
# spec requirements
|
12
13
|
require 'rspec'
|
13
14
|
require 'rspec/its'
|
@@ -46,10 +47,22 @@ module Inspec
|
|
46
47
|
@backend = Inspec::Backend.create(@conf)
|
47
48
|
end
|
48
49
|
|
49
|
-
def
|
50
|
+
def add_test_profile(test, ignore_supports = false)
|
51
|
+
assets = Inspec::Targets.resolve(test, @conf)
|
52
|
+
meta_assets = assets.find_all { |a| a[:type] == :metadata }
|
53
|
+
metas = meta_assets.map do |x|
|
54
|
+
Inspec::Metadata.from_ref(x[:ref], x[:content], @profile_id, @conf[:logger])
|
55
|
+
end
|
56
|
+
metas.each do |meta|
|
57
|
+
return [] unless ignore_supports || meta.supports_transport?(@backend)
|
58
|
+
end
|
59
|
+
assets
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_tests(tests, options = {})
|
50
63
|
# retrieve the raw ruby code of all tests
|
51
64
|
items = tests.map do |test|
|
52
|
-
|
65
|
+
add_test_profile(test, options[:ignore_supports])
|
53
66
|
end.flatten
|
54
67
|
|
55
68
|
tests = items.find_all { |i| i[:type] == :test }
|
@@ -59,8 +72,11 @@ module Inspec
|
|
59
72
|
# will ensure traditional RSpec-isms like `require 'spec_helper'`
|
60
73
|
# continue to work.
|
61
74
|
tests.flatten.each do |test|
|
62
|
-
|
63
|
-
|
75
|
+
# do not load path for virtual files, eg. from zip
|
76
|
+
if !test[:ref].nil?
|
77
|
+
test_directory = File.dirname(test[:ref])
|
78
|
+
$LOAD_PATH.unshift test_directory unless $LOAD_PATH.include?(test_directory)
|
79
|
+
end
|
64
80
|
end
|
65
81
|
|
66
82
|
# add all tests (raw) to the runtime
|
@@ -81,6 +97,7 @@ module Inspec
|
|
81
97
|
ctx = create_context
|
82
98
|
libs.each do |lib|
|
83
99
|
ctx.load(lib[:content].to_s, lib[:ref], lib[:line] || 1)
|
100
|
+
ctx.reload_dsl
|
84
101
|
end
|
85
102
|
|
86
103
|
# evaluate the test content
|