lib/utils/hash.rb
# encoding: utf-8 # author: Dominik Richter # author: Christoph Hartmann class ::Hash # Inspired by: http://stackoverflow.com/a/9381776 def deep_merge(second) merger = proc { |_key, v1, v2| v1.is_a?(Hash) && v2.is_a?(Hash) ? v1.merge(v2, &merger) : v2 } merge(second, &merger) end # converts a deep hash into a flat hash # hash = { # 'a' => 1, # 'b' => {'c' => 2}, # } # hash.smash # => {"a"=>1, "b-c"=>2} def smash(prefix = nil) inject({}) do |acc, (key, value)| index = prefix.to_s + key.to_s if value.is_a?(Hash) acc.merge(value.smash(index + '-')) else acc.merge(index => value) end end end # deep check if all values are contained def contains(contains) hash = smash contains = contains.smash contains.each do |key, val| return false if hash[key] != val end true end end
Source Files
- lib/bundles/inspec-artifact.rb
- lib/bundles/inspec-artifact/cli.rb
- lib/bundles/inspec-compliance.rb
- lib/bundles/inspec-compliance/api.rb
- lib/bundles/inspec-compliance/api/login.rb
- lib/bundles/inspec-compliance/cli.rb
- lib/bundles/inspec-compliance/configuration.rb
- lib/bundles/inspec-compliance/http.rb
- lib/bundles/inspec-compliance/support.rb
- lib/bundles/inspec-compliance/target.rb
- lib/bundles/inspec-compliance/test/integration/default/cli.rb
- lib/bundles/inspec-habitat.rb
- lib/bundles/inspec-habitat/cli.rb
- lib/bundles/inspec-habitat/log.rb
- lib/bundles/inspec-habitat/profile.rb
- lib/bundles/inspec-init.rb
- lib/bundles/inspec-init/cli.rb
- lib/bundles/inspec-init/renderer.rb
- lib/bundles/inspec-init/templates/profile/controls/example.rb
- lib/bundles/inspec-supermarket.rb
- lib/bundles/inspec-supermarket/api.rb
- lib/bundles/inspec-supermarket/cli.rb
- lib/bundles/inspec-supermarket/target.rb
- lib/fetchers/git.rb
- lib/fetchers/local.rb
- lib/fetchers/mock.rb
- lib/fetchers/url.rb
- lib/inspec.rb
- lib/inspec/archive/tar.rb
- lib/inspec/archive/zip.rb
- lib/inspec/backend.rb
- lib/inspec/base_cli.rb
- lib/inspec/cached_fetcher.rb
- lib/inspec/cli.rb
- lib/inspec/control_eval_context.rb
- lib/inspec/dependencies/cache.rb
- lib/inspec/dependencies/dependency_set.rb
- lib/inspec/dependencies/lockfile.rb
- lib/inspec/dependencies/requirement.rb
- lib/inspec/dependencies/resolver.rb
- lib/inspec/describe.rb
- lib/inspec/dsl.rb
- lib/inspec/dsl_shared.rb
- lib/inspec/env_printer.rb
- lib/inspec/errors.rb
- lib/inspec/exceptions.rb
- lib/inspec/expect.rb
- lib/inspec/fetcher.rb
- lib/inspec/file_provider.rb
- lib/inspec/formatters.rb
- lib/inspec/formatters/base.rb
- lib/inspec/formatters/json_rspec.rb
- lib/inspec/formatters/show_progress.rb
- lib/inspec/library_eval_context.rb
- lib/inspec/log.rb
- lib/inspec/metadata.rb
- lib/inspec/method_source.rb
- lib/inspec/objects.rb
- lib/inspec/objects/attribute.rb
- lib/inspec/objects/control.rb
- lib/inspec/objects/describe.rb
- lib/inspec/objects/each_loop.rb
- lib/inspec/objects/list.rb
- lib/inspec/objects/or_test.rb
- lib/inspec/objects/ruby_helper.rb
- lib/inspec/objects/tag.rb
- lib/inspec/objects/test.rb
- lib/inspec/objects/value.rb
- lib/inspec/plugins.rb
- lib/inspec/plugins/cli.rb
- lib/inspec/plugins/fetcher.rb
- lib/inspec/plugins/resource.rb
- lib/inspec/plugins/secret.rb
- lib/inspec/plugins/source_reader.rb
- lib/inspec/polyfill.rb
- lib/inspec/profile.rb
- lib/inspec/profile_context.rb
- lib/inspec/profile_vendor.rb
- lib/inspec/reporters.rb
- lib/inspec/reporters/automate.rb
- lib/inspec/reporters/base.rb
- lib/inspec/reporters/cli.rb
- lib/inspec/reporters/json.rb
- lib/inspec/reporters/json_merged.rb
- lib/inspec/reporters/json_min.rb
- lib/inspec/reporters/junit.rb
- lib/inspec/reporters/yaml.rb
- lib/inspec/require_loader.rb
- lib/inspec/resource.rb
- lib/inspec/rule.rb
- lib/inspec/runner.rb
- lib/inspec/runner_mock.rb
- lib/inspec/runner_rspec.rb
- lib/inspec/runtime_profile.rb
- lib/inspec/schema.rb
- lib/inspec/secrets.rb
- lib/inspec/secrets/yaml.rb
- lib/inspec/shell.rb
- lib/inspec/shell_detector.rb
- lib/inspec/source_reader.rb
- lib/inspec/version.rb
- lib/matchers/matchers.rb
- lib/resource_support/aws.rb
- lib/resource_support/aws/aws_backend_base.rb
- lib/resource_support/aws/aws_backend_factory_mixin.rb
- lib/resource_support/aws/aws_plural_resource_mixin.rb
- lib/resource_support/aws/aws_resource_mixin.rb
- lib/resource_support/aws/aws_singular_resource_mixin.rb
- lib/resources/aide_conf.rb
- lib/resources/apache.rb
- lib/resources/apache_conf.rb
- lib/resources/apt.rb
- lib/resources/audit_policy.rb
- lib/resources/auditd.rb
- lib/resources/auditd_conf.rb
- lib/resources/aws/aws_cloudtrail_trail.rb
- lib/resources/aws/aws_cloudtrail_trails.rb
- lib/resources/aws/aws_cloudwatch_alarm.rb
- lib/resources/aws/aws_cloudwatch_log_metric_filter.rb
- lib/resources/aws/aws_config_delivery_channel.rb
- lib/resources/aws/aws_config_recorder.rb
- lib/resources/aws/aws_ec2_instance.rb
- lib/resources/aws/aws_ec2_instances.rb
- lib/resources/aws/aws_ecs_cluster.rb
- lib/resources/aws/aws_elb.rb
- lib/resources/aws/aws_elbs.rb
- lib/resources/aws/aws_flow_log.rb
- lib/resources/aws/aws_iam_access_key.rb
- lib/resources/aws/aws_iam_access_keys.rb
- lib/resources/aws/aws_iam_group.rb
- lib/resources/aws/aws_iam_groups.rb
- lib/resources/aws/aws_iam_password_policy.rb
- lib/resources/aws/aws_iam_policies.rb
- lib/resources/aws/aws_iam_policy.rb
- lib/resources/aws/aws_iam_role.rb
- lib/resources/aws/aws_iam_root_user.rb
- lib/resources/aws/aws_iam_user.rb
- lib/resources/aws/aws_iam_users.rb
- lib/resources/aws/aws_kms_key.rb
- lib/resources/aws/aws_kms_keys.rb
- lib/resources/aws/aws_rds_instance.rb
- lib/resources/aws/aws_route_table.rb
- lib/resources/aws/aws_route_tables.rb
- lib/resources/aws/aws_s3_bucket.rb
- lib/resources/aws/aws_s3_bucket_object.rb
- lib/resources/aws/aws_s3_buckets.rb
- lib/resources/aws/aws_security_group.rb
- lib/resources/aws/aws_security_groups.rb
- lib/resources/aws/aws_sns_subscription.rb
- lib/resources/aws/aws_sns_topic.rb
- lib/resources/aws/aws_sns_topics.rb
- lib/resources/aws/aws_subnet.rb
- lib/resources/aws/aws_subnets.rb
- lib/resources/aws/aws_vpc.rb
- lib/resources/aws/aws_vpcs.rb
- lib/resources/azure/azure_backend.rb
- lib/resources/azure/azure_generic_resource.rb
- lib/resources/azure/azure_resource_group.rb
- lib/resources/azure/azure_virtual_machine.rb
- lib/resources/azure/azure_virtual_machine_data_disk.rb
- lib/resources/bash.rb
- lib/resources/bond.rb
- lib/resources/bridge.rb
- lib/resources/chocolatey_package.rb
- lib/resources/command.rb
- lib/resources/cpan.rb
- lib/resources/cran.rb
- lib/resources/crontab.rb
- lib/resources/csv.rb
- lib/resources/dh_params.rb
- lib/resources/directory.rb
- lib/resources/docker.rb
- lib/resources/docker_container.rb
- lib/resources/docker_image.rb
- lib/resources/docker_object.rb
- lib/resources/docker_plugin.rb
- lib/resources/docker_service.rb
- lib/resources/elasticsearch.rb
- lib/resources/etc_fstab.rb
- lib/resources/etc_group.rb
- lib/resources/etc_hosts.rb
- lib/resources/etc_hosts_allow_deny.rb
- lib/resources/file.rb
- lib/resources/filesystem.rb
- lib/resources/firewalld.rb
- lib/resources/gem.rb
- lib/resources/groups.rb
- lib/resources/grub_conf.rb
- lib/resources/host.rb
- lib/resources/http.rb
- lib/resources/iis_app.rb
- lib/resources/iis_app_pool.rb
- lib/resources/iis_site.rb
- lib/resources/inetd_conf.rb
- lib/resources/ini.rb
- lib/resources/interface.rb
- lib/resources/iptables.rb
- lib/resources/json.rb
- lib/resources/kernel_module.rb
- lib/resources/kernel_parameter.rb
- lib/resources/key_rsa.rb
- lib/resources/limits_conf.rb
- lib/resources/login_def.rb
- lib/resources/mount.rb
- lib/resources/mssql_session.rb
- lib/resources/mysql.rb
- lib/resources/mysql_conf.rb
- lib/resources/mysql_session.rb
- lib/resources/nginx.rb
- lib/resources/nginx_conf.rb
- lib/resources/npm.rb
- lib/resources/ntp_conf.rb
- lib/resources/oneget.rb
- lib/resources/oracledb_session.rb
- lib/resources/os.rb
- lib/resources/os_env.rb
- lib/resources/package.rb
- lib/resources/packages.rb
- lib/resources/parse_config.rb
- lib/resources/passwd.rb
- lib/resources/pip.rb
- lib/resources/platform.rb
- lib/resources/port.rb
- lib/resources/postgres.rb
- lib/resources/postgres_conf.rb
- lib/resources/postgres_hba_conf.rb
- lib/resources/postgres_ident_conf.rb
- lib/resources/postgres_session.rb
- lib/resources/powershell.rb
- lib/resources/processes.rb
- lib/resources/rabbitmq_conf.rb
- lib/resources/registry_key.rb
- lib/resources/security_policy.rb
- lib/resources/service.rb
- lib/resources/shadow.rb
- lib/resources/ssh_conf.rb
- lib/resources/ssl.rb
- lib/resources/sys_info.rb
- lib/resources/toml.rb
- lib/resources/users.rb
- lib/resources/vbscript.rb
- lib/resources/virtualization.rb
- lib/resources/windows_feature.rb
- lib/resources/windows_hotfix.rb
- lib/resources/windows_task.rb
- lib/resources/wmi.rb
- lib/resources/x509_certificate.rb
- lib/resources/xinetd.rb
- lib/resources/xml.rb
- lib/resources/yaml.rb
- lib/resources/yum.rb
- lib/resources/zfs_dataset.rb
- lib/resources/zfs_pool.rb
- lib/source_readers/flat.rb
- lib/source_readers/inspec.rb
- lib/utils/command_wrapper.rb
- lib/utils/convert.rb
- lib/utils/database_helpers.rb
- lib/utils/enumerable_delegation.rb
- lib/utils/erlang_parser.rb
- lib/utils/file_reader.rb
- lib/utils/filter.rb
- lib/utils/filter_array.rb
- lib/utils/find_files.rb
- lib/utils/hash.rb
- lib/utils/json_log.rb
- lib/utils/latest_version.rb
- lib/utils/modulator.rb
- lib/utils/nginx_parser.rb
- lib/utils/object_traversal.rb
- lib/utils/parser.rb
- lib/utils/pkey_reader.rb
- lib/utils/plugin_registry.rb
- lib/utils/simpleconfig.rb
- lib/utils/spdx.rb