inspec 4.18.51 → 4.18.85
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/inspec.gemspec +15 -37
- data/lib/resource_support/aws/aws_resource_mixin.rb +1 -1
- metadata +22 -709
- data/Gemfile +0 -61
- data/LICENSE +0 -14
- data/README.md +0 -474
- data/etc/deprecations.json +0 -125
- data/etc/plugin_filters.json +0 -45
- data/lib/bundles/README.md +0 -3
- data/lib/bundles/inspec-compliance/api.rb +0 -7
- data/lib/bundles/inspec-compliance/configuration.rb +0 -7
- data/lib/bundles/inspec-compliance/http.rb +0 -7
- data/lib/bundles/inspec-compliance/support.rb +0 -7
- data/lib/bundles/inspec-compliance/target.rb +0 -7
- data/lib/bundles/inspec-supermarket.rb +0 -9
- data/lib/bundles/inspec-supermarket/README.md +0 -45
- data/lib/bundles/inspec-supermarket/api.rb +0 -87
- data/lib/bundles/inspec-supermarket/cli.rb +0 -71
- data/lib/bundles/inspec-supermarket/target.rb +0 -31
- data/lib/inspec.rb +0 -30
- data/lib/inspec/archive/tar.rb +0 -25
- data/lib/inspec/archive/zip.rb +0 -15
- data/lib/inspec/backend.rb +0 -101
- data/lib/inspec/base_cli.rb +0 -318
- data/lib/inspec/cached_fetcher.rb +0 -65
- data/lib/inspec/cli.rb +0 -469
- data/lib/inspec/completions/bash.sh.erb +0 -45
- data/lib/inspec/completions/fish.sh.erb +0 -34
- data/lib/inspec/completions/zsh.sh.erb +0 -61
- data/lib/inspec/config.rb +0 -511
- data/lib/inspec/control_eval_context.rb +0 -248
- data/lib/inspec/dependencies/cache.rb +0 -74
- data/lib/inspec/dependencies/dependency_set.rb +0 -93
- data/lib/inspec/dependencies/lockfile.rb +0 -115
- data/lib/inspec/dependencies/requirement.rb +0 -135
- data/lib/inspec/dependencies/resolver.rb +0 -86
- data/lib/inspec/describe_base.rb +0 -53
- data/lib/inspec/dist.rb +0 -20
- data/lib/inspec/dsl.rb +0 -115
- data/lib/inspec/dsl_shared.rb +0 -32
- data/lib/inspec/env_printer.rb +0 -156
- data/lib/inspec/errors.rb +0 -18
- data/lib/inspec/exceptions.rb +0 -11
- data/lib/inspec/expect.rb +0 -42
- data/lib/inspec/fetcher.rb +0 -48
- data/lib/inspec/fetcher/git.rb +0 -211
- data/lib/inspec/fetcher/local.rb +0 -116
- data/lib/inspec/fetcher/mock.rb +0 -34
- data/lib/inspec/fetcher/url.rb +0 -281
- data/lib/inspec/file_provider.rb +0 -318
- data/lib/inspec/formatters.rb +0 -3
- data/lib/inspec/formatters/base.rb +0 -269
- data/lib/inspec/formatters/json_rspec.rb +0 -20
- data/lib/inspec/formatters/show_progress.rb +0 -12
- data/lib/inspec/globals.rb +0 -9
- data/lib/inspec/impact.rb +0 -36
- data/lib/inspec/input.rb +0 -421
- data/lib/inspec/input_dsl_helpers.rb +0 -26
- data/lib/inspec/input_registry.rb +0 -315
- data/lib/inspec/library_eval_context.rb +0 -55
- data/lib/inspec/log.rb +0 -7
- data/lib/inspec/metadata.rb +0 -253
- data/lib/inspec/method_source.rb +0 -20
- data/lib/inspec/objects.rb +0 -14
- data/lib/inspec/objects/control.rb +0 -85
- data/lib/inspec/objects/describe.rb +0 -106
- data/lib/inspec/objects/each_loop.rb +0 -41
- data/lib/inspec/objects/input.rb +0 -49
- data/lib/inspec/objects/list.rb +0 -15
- data/lib/inspec/objects/or_test.rb +0 -45
- data/lib/inspec/objects/ruby_helper.rb +0 -13
- data/lib/inspec/objects/tag.rb +0 -32
- data/lib/inspec/objects/test.rb +0 -94
- data/lib/inspec/objects/value.rb +0 -32
- data/lib/inspec/plugin/v1.rb +0 -2
- data/lib/inspec/plugin/v1/plugin_types/cli.rb +0 -22
- data/lib/inspec/plugin/v1/plugin_types/fetcher.rb +0 -83
- data/lib/inspec/plugin/v1/plugin_types/resource.rb +0 -176
- data/lib/inspec/plugin/v1/plugin_types/secret.rb +0 -11
- data/lib/inspec/plugin/v1/plugin_types/source_reader.rb +0 -36
- data/lib/inspec/plugin/v1/plugins.rb +0 -59
- data/lib/inspec/plugin/v1/registry.rb +0 -90
- data/lib/inspec/plugin/v2.rb +0 -46
- data/lib/inspec/plugin/v2/activator.rb +0 -40
- data/lib/inspec/plugin/v2/config_file.rb +0 -151
- data/lib/inspec/plugin/v2/filter.rb +0 -96
- data/lib/inspec/plugin/v2/installer.rb +0 -512
- data/lib/inspec/plugin/v2/loader.rb +0 -321
- data/lib/inspec/plugin/v2/plugin_base.rb +0 -112
- data/lib/inspec/plugin/v2/plugin_types/cli.rb +0 -49
- data/lib/inspec/plugin/v2/plugin_types/dsl.rb +0 -11
- data/lib/inspec/plugin/v2/plugin_types/input.rb +0 -34
- data/lib/inspec/plugin/v2/plugin_types/mock.rb +0 -12
- data/lib/inspec/plugin/v2/registry.rb +0 -98
- data/lib/inspec/plugin/v2/status.rb +0 -29
- data/lib/inspec/profile.rb +0 -658
- data/lib/inspec/profile_context.rb +0 -203
- data/lib/inspec/profile_vendor.rb +0 -84
- data/lib/inspec/reporters.rb +0 -73
- data/lib/inspec/reporters/automate.rb +0 -78
- data/lib/inspec/reporters/base.rb +0 -25
- data/lib/inspec/reporters/cli.rb +0 -370
- data/lib/inspec/reporters/json.rb +0 -113
- data/lib/inspec/reporters/json_automate.rb +0 -80
- data/lib/inspec/reporters/json_min.rb +0 -48
- data/lib/inspec/reporters/junit.rb +0 -77
- data/lib/inspec/reporters/yaml.rb +0 -20
- data/lib/inspec/require_loader.rb +0 -29
- data/lib/inspec/resource.rb +0 -114
- data/lib/inspec/resources.rb +0 -130
- data/lib/inspec/resources/aide_conf.rb +0 -153
- data/lib/inspec/resources/apache.rb +0 -47
- data/lib/inspec/resources/apache_conf.rb +0 -156
- data/lib/inspec/resources/apt.rb +0 -151
- data/lib/inspec/resources/audit_policy.rb +0 -64
- data/lib/inspec/resources/auditd.rb +0 -251
- data/lib/inspec/resources/auditd_conf.rb +0 -45
- data/lib/inspec/resources/bash.rb +0 -33
- data/lib/inspec/resources/bond.rb +0 -70
- data/lib/inspec/resources/bridge.rb +0 -125
- data/lib/inspec/resources/bsd_service.rb +0 -2
- data/lib/inspec/resources/chocolatey_package.rb +0 -82
- data/lib/inspec/resources/command.rb +0 -91
- data/lib/inspec/resources/cpan.rb +0 -58
- data/lib/inspec/resources/cran.rb +0 -64
- data/lib/inspec/resources/crontab.rb +0 -173
- data/lib/inspec/resources/csv.rb +0 -56
- data/lib/inspec/resources/dh_params.rb +0 -83
- data/lib/inspec/resources/directory.rb +0 -23
- data/lib/inspec/resources/docker.rb +0 -274
- data/lib/inspec/resources/docker_container.rb +0 -91
- data/lib/inspec/resources/docker_image.rb +0 -84
- data/lib/inspec/resources/docker_object.rb +0 -52
- data/lib/inspec/resources/docker_plugin.rb +0 -64
- data/lib/inspec/resources/docker_service.rb +0 -91
- data/lib/inspec/resources/elasticsearch.rb +0 -165
- data/lib/inspec/resources/etc_fstab.rb +0 -96
- data/lib/inspec/resources/etc_group.rb +0 -157
- data/lib/inspec/resources/etc_hosts.rb +0 -68
- data/lib/inspec/resources/etc_hosts_allow.rb +0 -2
- data/lib/inspec/resources/etc_hosts_allow_deny.rb +0 -114
- data/lib/inspec/resources/etc_hosts_deny.rb +0 -2
- data/lib/inspec/resources/file.rb +0 -339
- data/lib/inspec/resources/filesystem.rb +0 -139
- data/lib/inspec/resources/firewalld.rb +0 -148
- data/lib/inspec/resources/gem.rb +0 -80
- data/lib/inspec/resources/group.rb +0 -2
- data/lib/inspec/resources/groups.rb +0 -241
- data/lib/inspec/resources/grub_conf.rb +0 -230
- data/lib/inspec/resources/host.rb +0 -310
- data/lib/inspec/resources/http.rb +0 -275
- data/lib/inspec/resources/iis_app.rb +0 -101
- data/lib/inspec/resources/iis_app_pool.rb +0 -127
- data/lib/inspec/resources/iis_site.rb +0 -148
- data/lib/inspec/resources/iis_website.rb +0 -2
- data/lib/inspec/resources/inetd_conf.rb +0 -53
- data/lib/inspec/resources/ini.rb +0 -28
- data/lib/inspec/resources/interface.rb +0 -204
- data/lib/inspec/resources/ip6tables.rb +0 -79
- data/lib/inspec/resources/iptables.rb +0 -80
- data/lib/inspec/resources/json.rb +0 -116
- data/lib/inspec/resources/kernel_module.rb +0 -106
- data/lib/inspec/resources/kernel_parameter.rb +0 -54
- data/lib/inspec/resources/key_rsa.rb +0 -66
- data/lib/inspec/resources/ksh.rb +0 -33
- data/lib/inspec/resources/launchd_service.rb +0 -2
- data/lib/inspec/resources/limits_conf.rb +0 -45
- data/lib/inspec/resources/linux_kernel_parameter.rb +0 -2
- data/lib/inspec/resources/login_defs.rb +0 -56
- data/lib/inspec/resources/mount.rb +0 -88
- data/lib/inspec/resources/mssql_session.rb +0 -117
- data/lib/inspec/resources/mysql.rb +0 -81
- data/lib/inspec/resources/mysql_conf.rb +0 -128
- data/lib/inspec/resources/mysql_session.rb +0 -88
- data/lib/inspec/resources/nginx.rb +0 -96
- data/lib/inspec/resources/nginx_conf.rb +0 -232
- data/lib/inspec/resources/noop.rb +0 -9
- data/lib/inspec/resources/npm.rb +0 -68
- data/lib/inspec/resources/ntp_conf.rb +0 -51
- data/lib/inspec/resources/oneget.rb +0 -71
- data/lib/inspec/resources/oracledb_session.rb +0 -149
- data/lib/inspec/resources/os.rb +0 -34
- data/lib/inspec/resources/os_env.rb +0 -86
- data/lib/inspec/resources/package.rb +0 -391
- data/lib/inspec/resources/packages.rb +0 -111
- data/lib/inspec/resources/parse_config.rb +0 -112
- data/lib/inspec/resources/parse_config_file.rb +0 -2
- data/lib/inspec/resources/passwd.rb +0 -73
- data/lib/inspec/resources/pip.rb +0 -132
- data/lib/inspec/resources/platform.rb +0 -112
- data/lib/inspec/resources/port.rb +0 -791
- data/lib/inspec/resources/postfix_conf.rb +0 -35
- data/lib/inspec/resources/postgres.rb +0 -152
- data/lib/inspec/resources/postgres_conf.rb +0 -116
- data/lib/inspec/resources/postgres_hba_conf.rb +0 -86
- data/lib/inspec/resources/postgres_ident_conf.rb +0 -75
- data/lib/inspec/resources/postgres_session.rb +0 -70
- data/lib/inspec/resources/powershell.rb +0 -67
- data/lib/inspec/resources/ppa.rb +0 -2
- data/lib/inspec/resources/processes.rb +0 -219
- data/lib/inspec/resources/rabbitmq_conf.rb +0 -2
- data/lib/inspec/resources/rabbitmq_config.rb +0 -52
- data/lib/inspec/resources/registry_key.rb +0 -296
- data/lib/inspec/resources/runit_service.rb +0 -2
- data/lib/inspec/resources/script.rb +0 -1
- data/lib/inspec/resources/security_identifier.rb +0 -91
- data/lib/inspec/resources/security_policy.rb +0 -182
- data/lib/inspec/resources/service.rb +0 -820
- data/lib/inspec/resources/shadow.rb +0 -150
- data/lib/inspec/resources/ssh_config.rb +0 -98
- data/lib/inspec/resources/sshd_config.rb +0 -2
- data/lib/inspec/resources/ssl.rb +0 -99
- data/lib/inspec/resources/sys_info.rb +0 -119
- data/lib/inspec/resources/systemd_service.rb +0 -2
- data/lib/inspec/resources/sysv_service.rb +0 -2
- data/lib/inspec/resources/toml.rb +0 -30
- data/lib/inspec/resources/upstart_service.rb +0 -2
- data/lib/inspec/resources/user.rb +0 -1
- data/lib/inspec/resources/users.rb +0 -742
- data/lib/inspec/resources/vbscript.rb +0 -67
- data/lib/inspec/resources/virtualization.rb +0 -255
- data/lib/inspec/resources/windows_feature.rb +0 -126
- data/lib/inspec/resources/windows_hotfix.rb +0 -37
- data/lib/inspec/resources/windows_registry_key.rb +0 -2
- data/lib/inspec/resources/windows_task.rb +0 -112
- data/lib/inspec/resources/wmi.rb +0 -109
- data/lib/inspec/resources/x509_certificate.rb +0 -143
- data/lib/inspec/resources/xinetd_conf.rb +0 -103
- data/lib/inspec/resources/xml.rb +0 -48
- data/lib/inspec/resources/yaml.rb +0 -42
- data/lib/inspec/resources/yum.rb +0 -162
- data/lib/inspec/resources/zfs_dataset.rb +0 -62
- data/lib/inspec/resources/zfs_pool.rb +0 -50
- data/lib/inspec/rspec_extensions.rb +0 -116
- data/lib/inspec/rule.rb +0 -389
- data/lib/inspec/runner.rb +0 -333
- data/lib/inspec/runner_mock.rb +0 -37
- data/lib/inspec/runner_rspec.rb +0 -184
- data/lib/inspec/runtime_profile.rb +0 -23
- data/lib/inspec/schema.rb +0 -245
- data/lib/inspec/secrets.rb +0 -15
- data/lib/inspec/secrets/yaml.rb +0 -29
- data/lib/inspec/shell.rb +0 -211
- data/lib/inspec/shell_detector.rb +0 -89
- data/lib/inspec/source_reader.rb +0 -26
- data/lib/inspec/ui.rb +0 -213
- data/lib/inspec/ui_table_helper.rb +0 -12
- data/lib/inspec/utils/command_wrapper.rb +0 -23
- data/lib/inspec/utils/convert.rb +0 -8
- data/lib/inspec/utils/database_helpers.rb +0 -75
- data/lib/inspec/utils/deprecation.rb +0 -6
- data/lib/inspec/utils/deprecation/config_file.rb +0 -109
- data/lib/inspec/utils/deprecation/deprecator.rb +0 -118
- data/lib/inspec/utils/deprecation/errors.rb +0 -14
- data/lib/inspec/utils/deprecation/global_method.rb +0 -9
- data/lib/inspec/utils/enumerable_delegation.rb +0 -7
- data/lib/inspec/utils/erlang_parser.rb +0 -190
- data/lib/inspec/utils/file_reader.rb +0 -24
- data/lib/inspec/utils/filter.rb +0 -461
- data/lib/inspec/utils/filter_array.rb +0 -25
- data/lib/inspec/utils/find_files.rb +0 -44
- data/lib/inspec/utils/hash.rb +0 -37
- data/lib/inspec/utils/json_log.rb +0 -15
- data/lib/inspec/utils/modulator.rb +0 -9
- data/lib/inspec/utils/nginx_parser.rb +0 -101
- data/lib/inspec/utils/object_traversal.rb +0 -47
- data/lib/inspec/utils/parser.rb +0 -277
- data/lib/inspec/utils/pkey_reader.rb +0 -17
- data/lib/inspec/utils/simpleconfig.rb +0 -121
- data/lib/inspec/utils/spdx.rb +0 -10
- data/lib/inspec/utils/spdx.txt +0 -383
- data/lib/inspec/utils/telemetry.rb +0 -3
- data/lib/inspec/utils/telemetry/collector.rb +0 -81
- data/lib/inspec/utils/telemetry/data_series.rb +0 -44
- data/lib/inspec/utils/telemetry/global_methods.rb +0 -22
- data/lib/inspec/version.rb +0 -3
- data/lib/matchers/matchers.rb +0 -341
- data/lib/plugins/README.md +0 -16
- data/lib/plugins/inspec-artifact/lib/inspec-artifact.rb +0 -12
- data/lib/plugins/inspec-artifact/lib/inspec-artifact/base.rb +0 -170
- data/lib/plugins/inspec-artifact/lib/inspec-artifact/cli.rb +0 -116
- data/lib/plugins/inspec-artifact/test/functional/inspec_artifact_test.rb +0 -50
- data/lib/plugins/inspec-compliance/README.md +0 -207
- data/lib/plugins/inspec-compliance/lib/inspec-compliance.rb +0 -12
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/api.rb +0 -362
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/api/login.rb +0 -198
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/cli.rb +0 -269
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/configuration.rb +0 -103
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/http.rb +0 -117
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/images/cc-token.png +0 -0
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/support.rb +0 -34
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/target.rb +0 -146
- data/lib/plugins/inspec-compliance/test/functional/inspec_compliance_test.rb +0 -53
- data/lib/plugins/inspec-compliance/test/integration/default/cli.rb +0 -91
- data/lib/plugins/inspec-compliance/test/unit/api/login_test.rb +0 -190
- data/lib/plugins/inspec-compliance/test/unit/api_test.rb +0 -386
- data/lib/plugins/inspec-compliance/test/unit/target_test.rb +0 -155
- data/lib/plugins/inspec-habitat/Berksfile +0 -5
- data/lib/plugins/inspec-habitat/README.md +0 -150
- data/lib/plugins/inspec-habitat/kitchen.yml +0 -28
- data/lib/plugins/inspec-habitat/lib/inspec-habitat.rb +0 -11
- data/lib/plugins/inspec-habitat/lib/inspec-habitat/cli.rb +0 -41
- data/lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb +0 -265
- data/lib/plugins/inspec-habitat/templates/habitat/plan.sh.erb +0 -6
- data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/Berksfile +0 -2
- data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/README.md +0 -3
- data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/files/hab_setup.exp +0 -28
- data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/metadata.rb +0 -9
- data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/recipes/default.rb +0 -61
- data/lib/plugins/inspec-habitat/test/functional/inspec_habitat_test.rb +0 -34
- data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/README.md +0 -3
- data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/controls/inspec_habitat.rb +0 -40
- data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/inspec.yml +0 -10
- data/lib/plugins/inspec-habitat/test/support/example_profile/README.md +0 -3
- data/lib/plugins/inspec-habitat/test/support/example_profile/controls/example.rb +0 -7
- data/lib/plugins/inspec-habitat/test/support/example_profile/inspec.yml +0 -10
- data/lib/plugins/inspec-habitat/test/unit/profile_test.rb +0 -242
- data/lib/plugins/inspec-init/README.md +0 -31
- data/lib/plugins/inspec-init/lib/inspec-init.rb +0 -12
- data/lib/plugins/inspec-init/lib/inspec-init/cli.rb +0 -15
- data/lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb +0 -243
- data/lib/plugins/inspec-init/lib/inspec-init/cli_profile.rb +0 -47
- data/lib/plugins/inspec-init/lib/inspec-init/renderer.rb +0 -97
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Gemfile +0 -11
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/LICENSE +0 -2
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/README.md +0 -28
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Rakefile +0 -40
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template.rb +0 -14
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/cli_command.rb +0 -62
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/plugin.rb +0 -53
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/version.rb +0 -8
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/fixtures/README.md +0 -24
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/README.md +0 -12
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/inspec_plugin_template_test.rb +0 -110
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/helper.rb +0 -24
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/README.md +0 -17
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/cli_args_test.rb +0 -67
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/plugin_def_test.rb +0 -51
- data/lib/plugins/inspec-init/templates/profiles/aws/libraries/.gitkeep +0 -0
- data/lib/plugins/inspec-init/templates/profiles/azure/libraries/.gitkeep +0 -0
- data/lib/plugins/inspec-init/templates/profiles/gcp/libraries/.gitkeep +0 -0
- data/lib/plugins/inspec-init/templates/profiles/os/README.md +0 -3
- data/lib/plugins/inspec-init/templates/profiles/os/controls/example.rb +0 -18
- data/lib/plugins/inspec-init/templates/profiles/os/inspec.yml +0 -10
- data/lib/plugins/inspec-init/templates/profiles/os/libraries/.gitkeep +0 -0
- data/lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb +0 -184
- data/lib/plugins/inspec-init/test/functional/inspec_init_profile_test.rb +0 -121
- data/lib/plugins/inspec-plugin-manager-cli/README.md +0 -6
- data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli.rb +0 -17
- data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +0 -518
- data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/plugin.rb +0 -12
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/config_dirs/empty/.gitkeep +0 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-egg-white-omelette/lib/inspec-egg-white-omelette.rb +0 -2
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-egg-white-omelette/lib/inspec-egg-white-omelette/.gitkeep +0 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-wrong-structure/.gitkeep +0 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name.rb +0 -1
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name/.gitkeep +0 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/functional/help_test.rb +0 -23
- data/lib/plugins/inspec-plugin-manager-cli/test/functional/helper.rb +0 -62
- data/lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb +0 -368
- data/lib/plugins/inspec-plugin-manager-cli/test/functional/list_test.rb +0 -101
- data/lib/plugins/inspec-plugin-manager-cli/test/functional/search_test.rb +0 -129
- data/lib/plugins/inspec-plugin-manager-cli/test/functional/uninstall_test.rb +0 -63
- data/lib/plugins/inspec-plugin-manager-cli/test/functional/update_test.rb +0 -84
- data/lib/plugins/inspec-plugin-manager-cli/test/unit/cli_args_test.rb +0 -77
- data/lib/plugins/inspec-plugin-manager-cli/test/unit/plugin_def_test.rb +0 -39
- data/lib/plugins/shared/core_plugin_test_helper.rb +0 -153
- data/lib/plugins/things-for-train-integration.rb +0 -14
- data/lib/source_readers/flat.rb +0 -36
- data/lib/source_readers/inspec.rb +0 -66
@@ -1,45 +0,0 @@
|
|
1
|
-
_inspec() {
|
2
|
-
local _inspec_top_level_commands="<%= top_level_commands.join(" ") %>"
|
3
|
-
<% subcommands_with_commands.each do |name, subcommands| -%>
|
4
|
-
local _inspec_<%= name %>_commands="<%= subcommands.join(" ") -%>"
|
5
|
-
<% end -%>
|
6
|
-
|
7
|
-
cur=${COMP_WORDS[COMP_CWORD]}
|
8
|
-
prev=${COMP_WORDS[COMP_CWORD-1]}
|
9
|
-
|
10
|
-
if [ "$COMP_CWORD" -eq 1 ]; then
|
11
|
-
case "$prev" in
|
12
|
-
inspec)
|
13
|
-
COMPREPLY=( $( compgen -W "$_inspec_top_level_commands" -- "$cur" ) )
|
14
|
-
;;
|
15
|
-
esac
|
16
|
-
elif [ "$COMP_CWORD" -eq 2 ]; then
|
17
|
-
case "$prev" in
|
18
|
-
archive|check|exec|json)
|
19
|
-
COMPREPLY=( $( compgen -f -- "$cur" ) )
|
20
|
-
;;
|
21
|
-
help)
|
22
|
-
COMPREPLY=( $( compgen -W "$_inspec_top_level_commands" -- "$cur" ) )
|
23
|
-
;;
|
24
|
-
<% subcommands_with_commands.each do |name, subcommands| -%>
|
25
|
-
<%= name %>)
|
26
|
-
COMPREPLY=( $( compgen -W "$_inspec_<%= name %>_commands" -- "$cur" ) )
|
27
|
-
;;
|
28
|
-
<% end -%>
|
29
|
-
esac
|
30
|
-
elif [ "$COMP_CWORD" -eq 3 ]; then
|
31
|
-
prev2=${COMP_WORDS[COMP_CWORD-2]}
|
32
|
-
case "$prev2-$prev" in
|
33
|
-
compliance-upload)
|
34
|
-
COMPREPLY=( $( compgen -f -- "$cur" ) )
|
35
|
-
;;
|
36
|
-
<% subcommands_with_commands.each do |name, subcommands| -%>
|
37
|
-
<%= name %>-help)
|
38
|
-
COMPREPLY=( $( compgen -W "$_inspec_<%= name %>_commands" -- "$cur" ) )
|
39
|
-
;;
|
40
|
-
<% end -%>
|
41
|
-
esac
|
42
|
-
fi
|
43
|
-
}
|
44
|
-
|
45
|
-
complete -F _inspec inspec
|
@@ -1,34 +0,0 @@
|
|
1
|
-
function __fish_inspec_no_command --description 'Test if inspec has yet to be given the main command'
|
2
|
-
set -l cmd (commandline -opc)
|
3
|
-
test (count $cmd) -eq 1
|
4
|
-
end
|
5
|
-
|
6
|
-
function __fish_inspec_using_command
|
7
|
-
set -l cmd (commandline -opc)
|
8
|
-
set -q cmd[2]; and test "$argv[1]" = $cmd[2]
|
9
|
-
end
|
10
|
-
|
11
|
-
function __fish_inspec_using_command_and_no_subcommand
|
12
|
-
set -l cmd (commandline -opc)
|
13
|
-
test (count $cmd) -eq 2; and test "$argv[1]" = "$cmd[2]"
|
14
|
-
end
|
15
|
-
|
16
|
-
function __fish_inspec_using_subcommand --argument-names cmd_main cmd_sub
|
17
|
-
set -l cmd (commandline -opc)
|
18
|
-
set -q cmd[3]; and test "$cmd_main" = $cmd[2] -a "$cmd_sub" = $cmd[3]
|
19
|
-
end
|
20
|
-
|
21
|
-
<% top_level_commands_with_descriptions.each do |command_and_description| %>
|
22
|
-
<% command, description = command_and_description.split(':') %>
|
23
|
-
<% description.gsub!(/\\/, '') %>
|
24
|
-
# <%= command %> commands
|
25
|
-
complete -c inspec -f -n '__fish_inspec_no_command' -a <%= command %> -d "<%= description %>"
|
26
|
-
# <%= command %> help
|
27
|
-
complete -c inspec -f -n '__fish_inspec_using_command help' -a <%= command %> -d "<%= description %>"
|
28
|
-
|
29
|
-
<% (subcommands_with_commands_and_descriptions[command] || []).each do |command_and_description| %>
|
30
|
-
<% subcommand, description = command_and_description.split(':') %>
|
31
|
-
<% description.gsub!(/\\/, '') %>
|
32
|
-
complete -c inspec -f -n '__fish_inspec_using_command_and_no_subcommand <%= command %>' -a <%= subcommand %> -d "<%= description %>"
|
33
|
-
<% end %>
|
34
|
-
<% end %>
|
@@ -1,61 +0,0 @@
|
|
1
|
-
function _inspec() {
|
2
|
-
local curcontext="$curcontext" state line
|
3
|
-
typeset -A opt_args
|
4
|
-
|
5
|
-
local -a _top_level_commands <%= subcommands_with_commands_and_descriptions.keys.map {|i| "_#{i}_commands" }.join(' ') %>
|
6
|
-
|
7
|
-
_top_level_commands=(
|
8
|
-
<%= top_level_commands_with_descriptions.map {|i| " "*8 + "\"#{i}\"" }. join("\n") %>
|
9
|
-
)
|
10
|
-
|
11
|
-
<% subcommands_with_commands_and_descriptions.each do |name, entry| -%>
|
12
|
-
_<%= name %>_commands=(
|
13
|
-
<%= entry.map {|i| " "*8 + "\"#{i}\"" }.join("\n") %>
|
14
|
-
)
|
15
|
-
|
16
|
-
<% end -%>
|
17
|
-
_arguments '1:::->toplevel' && return 0
|
18
|
-
_arguments '2:::->subcommand' && return 0
|
19
|
-
_arguments '3:::->subsubcommand' && return 0
|
20
|
-
|
21
|
-
#
|
22
|
-
# Are you thinking? "Jeez, whoever wrote this really doesn't get
|
23
|
-
# zsh's completion system?" If so, you are correct. However, I
|
24
|
-
# have goodnews! Pull requests are accepted!
|
25
|
-
#
|
26
|
-
case $state in
|
27
|
-
toplevel)
|
28
|
-
_describe -t commands "InSpec subcommands" _top_level_commands
|
29
|
-
;;
|
30
|
-
subcommand)
|
31
|
-
case "$words[2]" in
|
32
|
-
archive|check|exec|json)
|
33
|
-
_alternative 'files:filenames:_files'
|
34
|
-
;;
|
35
|
-
help)
|
36
|
-
_describe -t commands "InSpec subcommands" _top_level_commands
|
37
|
-
;;
|
38
|
-
<% subcommands_with_commands_and_descriptions.each do |name, entry| -%>
|
39
|
-
<%= name %>)
|
40
|
-
_describe -t <%= name %>_commands "InSpec <%= name -%> subcommands" _<%= name %>_commands
|
41
|
-
;;
|
42
|
-
<% end -%>
|
43
|
-
esac
|
44
|
-
;;
|
45
|
-
subsubcommand)
|
46
|
-
case "$words[2]-$words[3]" in
|
47
|
-
compliance-upload)
|
48
|
-
_alternative 'files:filenames:_files'
|
49
|
-
;;
|
50
|
-
<% subcommands_with_commands_and_descriptions.each do |name, entry| -%>
|
51
|
-
<%= name %>-help)
|
52
|
-
_describe -t <%= name %>_commands "InSpec <%= name %> subcommands" _<%= name %>_commands
|
53
|
-
;;
|
54
|
-
<% end -%>
|
55
|
-
esac
|
56
|
-
|
57
|
-
esac
|
58
|
-
|
59
|
-
}
|
60
|
-
|
61
|
-
compdef _inspec inspec
|
data/lib/inspec/config.rb
DELETED
@@ -1,511 +0,0 @@
|
|
1
|
-
# Represents InSpec configuration. Merges defaults, config file options,
|
2
|
-
# and CLI arguments.
|
3
|
-
|
4
|
-
require "pp"
|
5
|
-
require "stringio"
|
6
|
-
require "forwardable"
|
7
|
-
require "thor"
|
8
|
-
require "base64"
|
9
|
-
require "inspec/plugin/v2/filter"
|
10
|
-
|
11
|
-
module Inspec
|
12
|
-
class Config
|
13
|
-
include Inspec::Plugin::V2::FilterPredicates
|
14
|
-
|
15
|
-
# These are options that apply to any transport
|
16
|
-
GENERIC_CREDENTIALS = %w{
|
17
|
-
backend
|
18
|
-
logger
|
19
|
-
sudo
|
20
|
-
sudo_password
|
21
|
-
sudo_command
|
22
|
-
sudo_options
|
23
|
-
shell
|
24
|
-
shell_options
|
25
|
-
shell_command
|
26
|
-
}.freeze
|
27
|
-
|
28
|
-
KNOWN_VERSIONS = [
|
29
|
-
"1.1",
|
30
|
-
"1.2",
|
31
|
-
].freeze
|
32
|
-
|
33
|
-
extend Forwardable
|
34
|
-
|
35
|
-
# Many parts of InSpec expect to treat the Config as a Hash
|
36
|
-
def_delegators :@final_options, :each, :delete, :[], :[]=, :key?
|
37
|
-
attr_reader :final_options
|
38
|
-
|
39
|
-
# This makes it easy to make a config with a mock backend.
|
40
|
-
def self.mock(opts = {})
|
41
|
-
Inspec::Config.new({ backend: :mock }.merge(opts), StringIO.new("{}"))
|
42
|
-
end
|
43
|
-
|
44
|
-
# Use this to get a cached version of the config. This prevents you from
|
45
|
-
# being required to pass it around everywhere.
|
46
|
-
def self.cached
|
47
|
-
@cached_config
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.cached=(cfg)
|
51
|
-
@cached_config ||= cfg
|
52
|
-
end
|
53
|
-
|
54
|
-
# This gets called when the first config is created.
|
55
|
-
def initialize(cli_opts = {}, cfg_io = nil, command_name = nil)
|
56
|
-
@command_name = command_name || (ARGV.empty? ? nil : ARGV[0].to_sym)
|
57
|
-
@defaults = Defaults.for_command(@command_name)
|
58
|
-
@plugin_cfg = {}
|
59
|
-
|
60
|
-
@cli_opts = cli_opts.dup
|
61
|
-
cfg_io = resolve_cfg_io(@cli_opts, cfg_io)
|
62
|
-
@cfg_file_contents = read_cfg_file_io(cfg_io)
|
63
|
-
|
64
|
-
@merged_options = merge_options
|
65
|
-
@final_options = finalize_options
|
66
|
-
self.class.cached = self
|
67
|
-
end
|
68
|
-
|
69
|
-
def diagnose
|
70
|
-
return unless self[:diagnose]
|
71
|
-
|
72
|
-
puts "InSpec version: #{Inspec::VERSION}"
|
73
|
-
puts "Train version: #{Train::VERSION}"
|
74
|
-
puts "Command line configuration:"
|
75
|
-
pp @cli_opts
|
76
|
-
puts "JSON configuration file:"
|
77
|
-
pp @cfg_file_contents
|
78
|
-
puts "Merged configuration:"
|
79
|
-
pp @merged_options
|
80
|
-
puts
|
81
|
-
end
|
82
|
-
|
83
|
-
# return all telemetry options from config
|
84
|
-
# @return [Hash]
|
85
|
-
def telemetry_options
|
86
|
-
final_options.select { |key, _| key.include?("telemetry") }
|
87
|
-
end
|
88
|
-
|
89
|
-
#-----------------------------------------------------------------------#
|
90
|
-
# Train Credential Handling
|
91
|
-
#-----------------------------------------------------------------------#
|
92
|
-
|
93
|
-
# Returns a Hash with Symbol keys as follows:
|
94
|
-
# backend: machine name of the Train transport needed
|
95
|
-
# If present, any of the GENERIC_CREDENTIALS.
|
96
|
-
# All other keys are specific to the backend.
|
97
|
-
#
|
98
|
-
# The credentials are gleaned from:
|
99
|
-
# * the Train transport defaults. Train handles this on transport creation,
|
100
|
-
# so this method doesn't load defaults.
|
101
|
-
# * individual InSpec CLI options (which in many cases may have the
|
102
|
-
# transport name prefixed, which is stripped before being added
|
103
|
-
# to the creds hash)
|
104
|
-
# * the --target CLI option, which is interpreted:
|
105
|
-
# - as a transport://credset format, which looks up the creds in
|
106
|
-
# the config file in the credentials section
|
107
|
-
# - as an arbitrary URI, which is parsed by Train.unpack_target_from_uri
|
108
|
-
|
109
|
-
def unpack_train_credentials
|
110
|
-
# Internally, use indifferent access while we build the creds
|
111
|
-
credentials = Thor::CoreExt::HashWithIndifferentAccess.new({})
|
112
|
-
|
113
|
-
# Helper methods prefixed with _utc_ (Unpack Train Credentials)
|
114
|
-
|
115
|
-
credentials.merge!(_utc_generic_credentials)
|
116
|
-
|
117
|
-
_utc_determine_backend(credentials)
|
118
|
-
transport_name = credentials[:backend].to_s
|
119
|
-
|
120
|
-
_utc_merge_credset(credentials, transport_name)
|
121
|
-
_utc_merge_transport_options(credentials, transport_name)
|
122
|
-
|
123
|
-
# Convert to all-Symbol keys
|
124
|
-
credentials.each_with_object({}) do |(option, value), creds|
|
125
|
-
creds[option.to_sym] = value
|
126
|
-
creds
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
#-----------------------------------------------------------------------#
|
131
|
-
# Fetching Plugin Data
|
132
|
-
#-----------------------------------------------------------------------#
|
133
|
-
def fetch_plugin_config(plugin_name)
|
134
|
-
Thor::CoreExt::HashWithIndifferentAccess.new(@plugin_cfg[plugin_name] || {})
|
135
|
-
end
|
136
|
-
|
137
|
-
# clear the cached config
|
138
|
-
def self.__reset
|
139
|
-
@cached_config = nil
|
140
|
-
end
|
141
|
-
|
142
|
-
private
|
143
|
-
|
144
|
-
def _utc_merge_transport_options(credentials, transport_name)
|
145
|
-
# Ask Train for the names of the transport options
|
146
|
-
transport_options = Train.options(transport_name).keys.map(&:to_s)
|
147
|
-
|
148
|
-
# If there are any options with those (unprefixed) names, merge them in.
|
149
|
-
unprefixed_transport_options = final_options.select do |option_name, _value|
|
150
|
-
transport_options.include? option_name # e.g., 'host'
|
151
|
-
end
|
152
|
-
credentials.merge!(unprefixed_transport_options)
|
153
|
-
|
154
|
-
# If there are any prefixed options, merge them in, stripping the prefix.
|
155
|
-
transport_prefix = transport_name.downcase.tr("-", "_") + "_"
|
156
|
-
transport_options.each do |bare_option_name|
|
157
|
-
prefixed_option_name = transport_prefix + bare_option_name.to_s
|
158
|
-
if final_options.key?(prefixed_option_name)
|
159
|
-
credentials[bare_option_name.to_s] = final_options[prefixed_option_name]
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
# fetch any info that applies to all transports (like sudo information)
|
165
|
-
def _utc_generic_credentials
|
166
|
-
@final_options.select { |option, _value| GENERIC_CREDENTIALS.include?(option) }
|
167
|
-
end
|
168
|
-
|
169
|
-
def _utc_determine_backend(credentials)
|
170
|
-
return if credentials.key?(:backend)
|
171
|
-
|
172
|
-
# Default to local
|
173
|
-
unless @final_options.key?(:target)
|
174
|
-
credentials[:backend] = "local"
|
175
|
-
return
|
176
|
-
end
|
177
|
-
|
178
|
-
# Look into target
|
179
|
-
%r{^(?<transport_name>[a-z_\-0-9]+)://.*$} =~ final_options[:target]
|
180
|
-
unless transport_name
|
181
|
-
raise ArgumentError, "Could not recognize a backend from the target #{final_options[:target]} - use a URI format with the backend name as the URI schema. Example: 'ssh://somehost.com' or 'transport://credset' or 'transport://' if credentials are provided outside of InSpec."
|
182
|
-
end
|
183
|
-
|
184
|
-
credentials[:backend] = transport_name.to_s # these are indeed stored in Train as Strings.
|
185
|
-
end
|
186
|
-
|
187
|
-
def _utc_merge_credset(credentials, transport_name)
|
188
|
-
# Look for Config File credentials/transport_name/credset
|
189
|
-
credset_name = _utc_find_credset_name(credentials, transport_name)
|
190
|
-
|
191
|
-
if credset_name
|
192
|
-
credset = @cfg_file_contents.dig("credentials", transport_name, credset_name)
|
193
|
-
if credset
|
194
|
-
credentials.merge!(credset)
|
195
|
-
else
|
196
|
-
# OK, we had a target that looked like transport://something
|
197
|
-
# But we don't know what that something is - there was no
|
198
|
-
# matching credset with it. Let train parse it.
|
199
|
-
credentials.merge!(Train.unpack_target_from_uri(final_options[:target]))
|
200
|
-
end
|
201
|
-
elsif final_options.key?(:target)
|
202
|
-
# Not sure what target looked like at all!
|
203
|
-
# Let train parse it.
|
204
|
-
credentials.merge!(Train.unpack_target_from_uri(final_options[:target]))
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
def _utc_find_credset_name(_credentials, transport_name)
|
209
|
-
return unless final_options[:target]
|
210
|
-
|
211
|
-
match = final_options[:target].match(%r{^#{transport_name}://(?<credset_name>[\w\-]+)$})
|
212
|
-
match ? match[:credset_name] : nil
|
213
|
-
end
|
214
|
-
|
215
|
-
#-----------------------------------------------------------------------#
|
216
|
-
# Reading Config Files
|
217
|
-
#-----------------------------------------------------------------------#
|
218
|
-
|
219
|
-
# Regardless of our situation, end up with a readable IO object
|
220
|
-
def resolve_cfg_io(cli_opts, cfg_io)
|
221
|
-
raise(ArgumentError, "Inspec::Config must use an IO to read from") if cfg_io && !cfg_io.respond_to?(:read)
|
222
|
-
|
223
|
-
cfg_io ||= check_for_piped_config(cli_opts)
|
224
|
-
return cfg_io if cfg_io
|
225
|
-
|
226
|
-
path = determine_cfg_path(cli_opts)
|
227
|
-
|
228
|
-
ver = KNOWN_VERSIONS.max
|
229
|
-
path ? File.open(path) : StringIO.new({ "version" => ver }.to_json)
|
230
|
-
end
|
231
|
-
|
232
|
-
def check_for_piped_config(cli_opts)
|
233
|
-
cli_opt = cli_opts[:config] || cli_opts[:json_config]
|
234
|
-
Inspec.deprecate(:cli_option_json_config) if cli_opts.key?(:json_config)
|
235
|
-
|
236
|
-
return nil unless cli_opt
|
237
|
-
return nil unless cli_opt == "-"
|
238
|
-
|
239
|
-
# This warning is here so that if a user invokes inspec with --config=-,
|
240
|
-
# they will have an explanation for why it appears to hang.
|
241
|
-
Inspec::Log.warn "Reading JSON config from standard input" if STDIN.tty?
|
242
|
-
STDIN
|
243
|
-
end
|
244
|
-
|
245
|
-
def determine_cfg_path(cli_opts)
|
246
|
-
path = cli_opts[:config] || cli_opts[:json_config]
|
247
|
-
Inspec.deprecate(:cli_option_json_config) if cli_opts.key?(:json_config)
|
248
|
-
|
249
|
-
if path.nil?
|
250
|
-
default_path = File.join(Inspec.config_dir, "config.json")
|
251
|
-
path = default_path if File.exist?(default_path)
|
252
|
-
elsif !File.exist?(path)
|
253
|
-
raise ArgumentError, "Could not read configuration file at #{path}"
|
254
|
-
end
|
255
|
-
path
|
256
|
-
end
|
257
|
-
|
258
|
-
# When reading STDIN, read it once into a class variable and cache it.
|
259
|
-
# Don't cache other IO objects though, as we use several different StringIOs
|
260
|
-
# during unit testing. Refs #3792
|
261
|
-
def self.stdin_contents # rubocop: disable Lint/IneffectiveAccessModifier
|
262
|
-
@stdin_content ||= STDIN.read
|
263
|
-
end
|
264
|
-
|
265
|
-
def read_cfg_file_io(cfg_io)
|
266
|
-
contents = cfg_io == STDIN ? self.class.stdin_contents : cfg_io.read
|
267
|
-
begin
|
268
|
-
@cfg_file_contents = JSON.parse(contents)
|
269
|
-
validate_config_file_contents!
|
270
|
-
rescue JSON::ParserError => e
|
271
|
-
raise Inspec::ConfigError::MalformedJson, "Failed to load JSON configuration: #{e}\nConfig was: #{contents}"
|
272
|
-
end
|
273
|
-
@cfg_file_contents
|
274
|
-
end
|
275
|
-
|
276
|
-
def file_version
|
277
|
-
@cfg_file_contents["version"] || :legacy
|
278
|
-
end
|
279
|
-
|
280
|
-
def legacy_file?
|
281
|
-
file_version == :legacy
|
282
|
-
end
|
283
|
-
|
284
|
-
def config_file_cli_options
|
285
|
-
if legacy_file?
|
286
|
-
# Assume everything in the file is a CLI option
|
287
|
-
@cfg_file_contents
|
288
|
-
else
|
289
|
-
@cfg_file_contents["cli_options"] || {}
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
def config_file_reporter_options
|
294
|
-
# This is assumed to be top-level in both legacy and 1.1.
|
295
|
-
# Technically, you could sneak it in the 1.1 cli opts area.
|
296
|
-
@cfg_file_contents.key?("reporter") ? { "reporter" => @cfg_file_contents["reporter"] } : {}
|
297
|
-
end
|
298
|
-
|
299
|
-
#-----------------------------------------------------------------------#
|
300
|
-
# Validation
|
301
|
-
#-----------------------------------------------------------------------#
|
302
|
-
def validate_config_file_contents!
|
303
|
-
version = @cfg_file_contents["version"]
|
304
|
-
|
305
|
-
# Assume legacy format, which is unconstrained
|
306
|
-
return unless version
|
307
|
-
|
308
|
-
unless KNOWN_VERSIONS.include?(version)
|
309
|
-
raise Inspec::ConfigError::Invalid, "Unsupported config file version '#{version}' - currently supported versions: #{KNOWN_VERSIONS.join(",")}"
|
310
|
-
end
|
311
|
-
|
312
|
-
# Use Gem::Version for comparision operators
|
313
|
-
cfg_version = Gem::Version.new(version)
|
314
|
-
version_1_2 = Gem::Version.new("1.2")
|
315
|
-
|
316
|
-
# TODO: proper schema version loading and validation
|
317
|
-
valid_fields = %w{version cli_options credentials compliance reporter}.sort
|
318
|
-
valid_fields << "plugins" if cfg_version >= version_1_2
|
319
|
-
@cfg_file_contents.keys.each do |seen_field|
|
320
|
-
unless valid_fields.include?(seen_field)
|
321
|
-
raise Inspec::ConfigError::Invalid, "Unrecognized top-level configuration field #{seen_field}. Recognized fields: #{valid_fields.join(", ")}"
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
validate_plugins! if cfg_version >= version_1_2
|
326
|
-
end
|
327
|
-
|
328
|
-
def validate_reporters!(reporters)
|
329
|
-
return if reporters.nil?
|
330
|
-
|
331
|
-
# TODO: move this into a reporter plugin type system
|
332
|
-
valid_types = %w{
|
333
|
-
automate
|
334
|
-
cli
|
335
|
-
documentation
|
336
|
-
html
|
337
|
-
json
|
338
|
-
json-automate
|
339
|
-
json-min
|
340
|
-
json-rspec
|
341
|
-
junit
|
342
|
-
progress
|
343
|
-
yaml
|
344
|
-
}
|
345
|
-
|
346
|
-
reporters.each do |reporter_name, reporter_config|
|
347
|
-
raise NotImplementedError, "'#{reporter_name}' is not a valid reporter type." unless valid_types.include?(reporter_name)
|
348
|
-
|
349
|
-
next unless reporter_name == "automate"
|
350
|
-
|
351
|
-
%w{token url}.each do |option|
|
352
|
-
raise Inspec::ReporterError, "You must specify a automate #{option} via the config file." if reporter_config[option].nil?
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
|
-
# check to make sure we are only reporting one type to stdout
|
357
|
-
stdout_reporters = 0
|
358
|
-
reporters.each_value do |reporter_config|
|
359
|
-
stdout_reporters += 1 if reporter_config["stdout"] == true
|
360
|
-
end
|
361
|
-
|
362
|
-
raise ArgumentError, "The option --reporter can only have a single report outputting to stdout." if stdout_reporters > 1
|
363
|
-
end
|
364
|
-
|
365
|
-
def validate_plugins!
|
366
|
-
return unless @cfg_file_contents.key? "plugins"
|
367
|
-
|
368
|
-
data = @cfg_file_contents["plugins"]
|
369
|
-
unless data.is_a?(Hash)
|
370
|
-
raise Inspec::ConfigError::Invalid, "The 'plugin' field in your config file must be a hash (key-value list), not an array."
|
371
|
-
end
|
372
|
-
|
373
|
-
data.each do |plugin_name, plugin_settings|
|
374
|
-
# Enforce that every key is a valid inspec or train plugin name
|
375
|
-
unless valid_plugin_name?(plugin_name)
|
376
|
-
raise Inspec::ConfigError::Invalid, "Plugin settings should ne named after the the InSpec or Train plugin. Valid names must begin with inspec- or train-, not '#{plugin_name}' "
|
377
|
-
end
|
378
|
-
|
379
|
-
# Enforce that every entry is hash-valued
|
380
|
-
unless plugin_settings.is_a?(Hash)
|
381
|
-
raise Inspec::ConfigError::Invalid, "The plugin settings for '#{plugin_name}' in your config file should be a Hash (key-value list)."
|
382
|
-
end
|
383
|
-
end
|
384
|
-
|
385
|
-
@plugin_cfg = data
|
386
|
-
end
|
387
|
-
|
388
|
-
#-----------------------------------------------------------------------#
|
389
|
-
# Merging Options
|
390
|
-
#-----------------------------------------------------------------------#
|
391
|
-
def merge_options
|
392
|
-
options = Thor::CoreExt::HashWithIndifferentAccess.new({})
|
393
|
-
|
394
|
-
# Lowest precedence: default, which may vary by command
|
395
|
-
options.merge!(@defaults)
|
396
|
-
|
397
|
-
# Middle precedence: merge in any CLI options defined from the config file
|
398
|
-
options.merge!(config_file_cli_options)
|
399
|
-
# Reporter options may be defined top-level.
|
400
|
-
options.merge!(config_file_reporter_options)
|
401
|
-
|
402
|
-
# Highest precedence: merge in any options defined via the CLI
|
403
|
-
options.merge!(@cli_opts)
|
404
|
-
|
405
|
-
options
|
406
|
-
end
|
407
|
-
|
408
|
-
#-----------------------------------------------------------------------#
|
409
|
-
# Finalization
|
410
|
-
#-----------------------------------------------------------------------#
|
411
|
-
def finalize_options
|
412
|
-
options = @merged_options.dup
|
413
|
-
|
414
|
-
finalize_set_top_level_command(options)
|
415
|
-
finalize_parse_reporters(options)
|
416
|
-
finalize_handle_sudo(options)
|
417
|
-
finalize_compliance_login(options)
|
418
|
-
|
419
|
-
Thor::CoreExt::HashWithIndifferentAccess.new(options)
|
420
|
-
end
|
421
|
-
|
422
|
-
def finalize_set_top_level_command(options)
|
423
|
-
options[:type] = @command_name
|
424
|
-
require "inspec/base_cli"
|
425
|
-
Inspec::BaseCLI.inspec_cli_command = @command_name # TODO: move to a more relevant location
|
426
|
-
end
|
427
|
-
|
428
|
-
def finalize_parse_reporters(options) # rubocop:disable Metrics/AbcSize
|
429
|
-
# default to cli report for ad-hoc runners
|
430
|
-
options["reporter"] = ["cli"] if options["reporter"].nil?
|
431
|
-
|
432
|
-
# parse out cli to proper report format
|
433
|
-
if options["reporter"].is_a?(Array)
|
434
|
-
reports = {}
|
435
|
-
options["reporter"].each do |report|
|
436
|
-
reporter_name, destination = report.split(":", 2)
|
437
|
-
if destination.nil? || destination.strip == "-"
|
438
|
-
reports[reporter_name] = { "stdout" => true }
|
439
|
-
else
|
440
|
-
reports[reporter_name] = {
|
441
|
-
"file" => destination,
|
442
|
-
"stdout" => false,
|
443
|
-
}
|
444
|
-
reports[reporter_name]["target_id"] = options["target_id"] if options["target_id"]
|
445
|
-
end
|
446
|
-
end
|
447
|
-
options["reporter"] = reports
|
448
|
-
end
|
449
|
-
|
450
|
-
# add in stdout if not specified
|
451
|
-
if options["reporter"].is_a?(Hash)
|
452
|
-
options["reporter"].each do |reporter_name, config|
|
453
|
-
options["reporter"][reporter_name] = {} if config.nil?
|
454
|
-
options["reporter"][reporter_name]["stdout"] = true if options["reporter"][reporter_name].empty?
|
455
|
-
options["reporter"][reporter_name]["target_id"] = options["target_id"] if options["target_id"]
|
456
|
-
end
|
457
|
-
end
|
458
|
-
|
459
|
-
validate_reporters!(options["reporter"])
|
460
|
-
options
|
461
|
-
end
|
462
|
-
|
463
|
-
def finalize_handle_sudo(options)
|
464
|
-
# Due to limitations in Thor it is not possible to set an argument to be
|
465
|
-
# both optional and its value to be mandatory. E.g. the user supplying
|
466
|
-
# the --password argument is optional and not always required, but
|
467
|
-
# whenever it is used, it requires a value. Handle options that were
|
468
|
-
# defined in such a way and require a value here:
|
469
|
-
%w{password sudo-password}.each do |option_name|
|
470
|
-
snake_case_option_name = option_name.tr("-", "_").to_s
|
471
|
-
next unless options[snake_case_option_name] == -1 # Thor sets -1 for missing value - see #1918
|
472
|
-
|
473
|
-
raise ArgumentError, "Please provide a value for --#{option_name}. For example: --#{option_name}=hello."
|
474
|
-
end
|
475
|
-
|
476
|
-
# Infer `--sudo` if using `--sudo-password` without `--sudo`
|
477
|
-
if options["sudo_password"] && !options["sudo"]
|
478
|
-
options["sudo"] = true
|
479
|
-
Inspec::Log.warn "`--sudo-password` used without `--sudo`. Adding `--sudo`."
|
480
|
-
end
|
481
|
-
end
|
482
|
-
|
483
|
-
def finalize_compliance_login(options)
|
484
|
-
# check for compliance settings
|
485
|
-
# This is always a hash, comes from config file, not CLI opts
|
486
|
-
if options.key?("compliance")
|
487
|
-
require "plugins/inspec-compliance/lib/inspec-compliance/api"
|
488
|
-
InspecPlugins::Compliance::API.login(options["compliance"])
|
489
|
-
end
|
490
|
-
end
|
491
|
-
|
492
|
-
class Defaults
|
493
|
-
DEFAULTS = {
|
494
|
-
exec: {
|
495
|
-
"reporter" => ["cli"],
|
496
|
-
"show_progress" => false,
|
497
|
-
"color" => true,
|
498
|
-
"create_lockfile" => true,
|
499
|
-
"backend_cache" => true,
|
500
|
-
},
|
501
|
-
shell: {
|
502
|
-
"reporter" => ["cli"],
|
503
|
-
},
|
504
|
-
}.freeze
|
505
|
-
|
506
|
-
def self.for_command(command_name)
|
507
|
-
DEFAULTS[command_name] || {}
|
508
|
-
end
|
509
|
-
end
|
510
|
-
end
|
511
|
-
end
|