chef-cli 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +32 -0
- data/LICENSE +201 -0
- data/Rakefile +70 -0
- data/bin/chef +25 -0
- data/chef-cli.gemspec +53 -0
- data/lib/chef-cli.rb +19 -0
- data/lib/chef-cli/authenticated_http.rb +22 -0
- data/lib/chef-cli/builtin_commands.rb +62 -0
- data/lib/chef-cli/chef_runner.rb +114 -0
- data/lib/chef-cli/chef_server_api_multi.rb +73 -0
- data/lib/chef-cli/cli.rb +206 -0
- data/lib/chef-cli/command/base.rb +89 -0
- data/lib/chef-cli/command/clean_policy_cookbooks.rb +115 -0
- data/lib/chef-cli/command/clean_policy_revisions.rb +112 -0
- data/lib/chef-cli/command/delete_policy.rb +121 -0
- data/lib/chef-cli/command/delete_policy_group.rb +121 -0
- data/lib/chef-cli/command/describe_cookbook.rb +98 -0
- data/lib/chef-cli/command/diff.rb +316 -0
- data/lib/chef-cli/command/env.rb +99 -0
- data/lib/chef-cli/command/exec.rb +45 -0
- data/lib/chef-cli/command/export.rb +156 -0
- data/lib/chef-cli/command/gem.rb +48 -0
- data/lib/chef-cli/command/generate.rb +123 -0
- data/lib/chef-cli/command/generator_commands.rb +83 -0
- data/lib/chef-cli/command/generator_commands/attribute.rb +37 -0
- data/lib/chef-cli/command/generator_commands/base.rb +157 -0
- data/lib/chef-cli/command/generator_commands/build_cookbook.rb +126 -0
- data/lib/chef-cli/command/generator_commands/chef_exts/generator_desc_resource.rb +40 -0
- data/lib/chef-cli/command/generator_commands/chef_exts/quieter_doc_formatter.rb +38 -0
- data/lib/chef-cli/command/generator_commands/chef_exts/recipe_dsl_ext.rb +39 -0
- data/lib/chef-cli/command/generator_commands/cookbook.rb +251 -0
- data/lib/chef-cli/command/generator_commands/cookbook_code_file.rb +100 -0
- data/lib/chef-cli/command/generator_commands/cookbook_file.rb +46 -0
- data/lib/chef-cli/command/generator_commands/generator_generator.rb +175 -0
- data/lib/chef-cli/command/generator_commands/helpers.rb +37 -0
- data/lib/chef-cli/command/generator_commands/policyfile.rb +125 -0
- data/lib/chef-cli/command/generator_commands/recipe.rb +37 -0
- data/lib/chef-cli/command/generator_commands/repo.rb +140 -0
- data/lib/chef-cli/command/generator_commands/resource.rb +37 -0
- data/lib/chef-cli/command/generator_commands/template.rb +47 -0
- data/lib/chef-cli/command/install.rb +121 -0
- data/lib/chef-cli/command/provision.rb +38 -0
- data/lib/chef-cli/command/push.rb +118 -0
- data/lib/chef-cli/command/push_archive.rb +126 -0
- data/lib/chef-cli/command/shell_init.rb +185 -0
- data/lib/chef-cli/command/show_policy.rb +164 -0
- data/lib/chef-cli/command/undelete.rb +155 -0
- data/lib/chef-cli/command/update.rb +140 -0
- data/lib/chef-cli/command/verify.rb +548 -0
- data/lib/chef-cli/commands_map.rb +113 -0
- data/lib/chef-cli/completions/bash.sh.erb +5 -0
- data/lib/chef-cli/completions/chef.fish.erb +10 -0
- data/lib/chef-cli/completions/zsh.zsh.erb +21 -0
- data/lib/chef-cli/component_test.rb +226 -0
- data/lib/chef-cli/configurable.rb +88 -0
- data/lib/chef-cli/cookbook_metadata.rb +45 -0
- data/lib/chef-cli/cookbook_omnifetch.rb +32 -0
- data/lib/chef-cli/cookbook_profiler/git.rb +152 -0
- data/lib/chef-cli/cookbook_profiler/identifiers.rb +72 -0
- data/lib/chef-cli/cookbook_profiler/null_scm.rb +31 -0
- data/lib/chef-cli/dist.rb +31 -0
- data/lib/chef-cli/exceptions.rb +153 -0
- data/lib/chef-cli/generator.rb +165 -0
- data/lib/chef-cli/helpers.rb +170 -0
- data/lib/chef-cli/pager.rb +104 -0
- data/lib/chef-cli/policyfile/artifactory_cookbook_source.rb +102 -0
- data/lib/chef-cli/policyfile/attribute_merge_checker.rb +110 -0
- data/lib/chef-cli/policyfile/chef_repo_cookbook_source.rb +138 -0
- data/lib/chef-cli/policyfile/chef_server_cookbook_source.rb +99 -0
- data/lib/chef-cli/policyfile/chef_server_lock_fetcher.rb +167 -0
- data/lib/chef-cli/policyfile/community_cookbook_source.rb +95 -0
- data/lib/chef-cli/policyfile/comparison_base.rb +123 -0
- data/lib/chef-cli/policyfile/cookbook_location_specification.rb +154 -0
- data/lib/chef-cli/policyfile/cookbook_locks.rb +466 -0
- data/lib/chef-cli/policyfile/cookbook_sources.rb +23 -0
- data/lib/chef-cli/policyfile/delivery_supermarket_source.rb +89 -0
- data/lib/chef-cli/policyfile/differ.rb +263 -0
- data/lib/chef-cli/policyfile/dsl.rb +288 -0
- data/lib/chef-cli/policyfile/git_lock_fetcher.rb +265 -0
- data/lib/chef-cli/policyfile/included_policies_cookbook_source.rb +156 -0
- data/lib/chef-cli/policyfile/lister.rb +229 -0
- data/lib/chef-cli/policyfile/local_lock_fetcher.rb +132 -0
- data/lib/chef-cli/policyfile/lock_applier.rb +80 -0
- data/lib/chef-cli/policyfile/lock_fetcher_mixin.rb +37 -0
- data/lib/chef-cli/policyfile/null_cookbook_source.rb +49 -0
- data/lib/chef-cli/policyfile/policyfile_location_specification.rb +128 -0
- data/lib/chef-cli/policyfile/read_cookbook_for_compat_mode_upload.rb +124 -0
- data/lib/chef-cli/policyfile/remote_lock_fetcher.rb +108 -0
- data/lib/chef-cli/policyfile/reports/install.rb +69 -0
- data/lib/chef-cli/policyfile/reports/table_printer.rb +57 -0
- data/lib/chef-cli/policyfile/reports/upload.rb +70 -0
- data/lib/chef-cli/policyfile/solution_dependencies.rb +311 -0
- data/lib/chef-cli/policyfile/source_uri.rb +57 -0
- data/lib/chef-cli/policyfile/storage_config.rb +112 -0
- data/lib/chef-cli/policyfile/undo_record.rb +139 -0
- data/lib/chef-cli/policyfile/undo_stack.rb +128 -0
- data/lib/chef-cli/policyfile/uploader.rb +222 -0
- data/lib/chef-cli/policyfile_compiler.rb +528 -0
- data/lib/chef-cli/policyfile_lock.rb +581 -0
- data/lib/chef-cli/policyfile_services/clean_policies.rb +95 -0
- data/lib/chef-cli/policyfile_services/clean_policy_cookbooks.rb +123 -0
- data/lib/chef-cli/policyfile_services/export_repo.rb +419 -0
- data/lib/chef-cli/policyfile_services/install.rb +167 -0
- data/lib/chef-cli/policyfile_services/push.rb +112 -0
- data/lib/chef-cli/policyfile_services/push_archive.rb +164 -0
- data/lib/chef-cli/policyfile_services/rm_policy.rb +141 -0
- data/lib/chef-cli/policyfile_services/rm_policy_group.rb +85 -0
- data/lib/chef-cli/policyfile_services/show_policy.rb +234 -0
- data/lib/chef-cli/policyfile_services/undelete.rb +108 -0
- data/lib/chef-cli/policyfile_services/update_attributes.rb +110 -0
- data/lib/chef-cli/service_exception_inspectors.rb +24 -0
- data/lib/chef-cli/service_exception_inspectors/base.rb +39 -0
- data/lib/chef-cli/service_exception_inspectors/http.rb +119 -0
- data/lib/chef-cli/service_exceptions.rb +142 -0
- data/lib/chef-cli/shell_out.rb +36 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/Berksfile +3 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/README.md +146 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/kitchen.yml +21 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/build_cookbook/test-fixture-recipe.rb +8 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/chefignore +110 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/cookbook_readmes/README-policy.md +9 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/cookbook_readmes/README.md +66 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/delivery-config.json +17 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/delivery-project.toml +34 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/gitignore +22 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/README.md +20 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/README.md +27 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/attributes/default.rb +7 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/metadata.rb +6 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb +8 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/data_bags/README.md +56 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/data_bags/example/example_item.json +4 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/dot-chef-repo.txt +6 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/environments/README.md +9 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/environments/example.json +13 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/policyfiles/README.md +24 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/roles/README.md +9 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/repo/roles/example.json +13 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/spec_helper.rb +2 -0
- data/lib/chef-cli/skeletons/code_generator/files/default/spec_helper_policyfile.rb +2 -0
- data/lib/chef-cli/skeletons/code_generator/metadata.rb +8 -0
- data/lib/chef-cli/skeletons/code_generator/recipes/attribute.rb +11 -0
- data/lib/chef-cli/skeletons/code_generator/recipes/build_cookbook.rb +175 -0
- data/lib/chef-cli/skeletons/code_generator/recipes/cookbook.rb +167 -0
- data/lib/chef-cli/skeletons/code_generator/recipes/cookbook_file.rb +23 -0
- data/lib/chef-cli/skeletons/code_generator/recipes/helpers.rb +19 -0
- data/lib/chef-cli/skeletons/code_generator/recipes/policyfile.rb +7 -0
- data/lib/chef-cli/skeletons/code_generator/recipes/recipe.rb +50 -0
- data/lib/chef-cli/skeletons/code_generator/recipes/repo.rb +71 -0
- data/lib/chef-cli/skeletons/code_generator/recipes/resource.rb +12 -0
- data/lib/chef-cli/skeletons/code_generator/recipes/template.rb +31 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/CHANGELOG.md.erb +11 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/LICENSE.all_rights.erb +3 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/LICENSE.apachev2.erb +201 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/LICENSE.gplv2.erb +339 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/LICENSE.gplv3.erb +674 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/LICENSE.mit.erb +21 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/Policyfile.rb.erb +25 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/README.md.erb +4 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/attribute.rb.erb +0 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/Berksfile.erb +7 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/metadata.rb.erb +10 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/recipe.rb.erb +9 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/cookbook_file.erb +0 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/helpers.rb.erb +39 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/inspec_default_test.rb.erb +16 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/kitchen.yml.erb +38 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_dokken.yml.erb +36 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_policyfile.yml.erb +32 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/metadata.rb.erb +20 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/recipe.rb.erb +5 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/recipe_spec.rb.erb +29 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/repo/gitignore.erb +128 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/resource.rb.erb +1 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/template.erb +0 -0
- data/lib/chef-cli/ui.rb +57 -0
- data/lib/chef-cli/version.rb +20 -0
- data/lib/kitchen/provisioner/policyfile_zero.rb +195 -0
- data/spec/shared/a_file_generator.rb +125 -0
- data/spec/shared/a_generated_file.rb +12 -0
- data/spec/shared/command_with_ui_object.rb +11 -0
- data/spec/shared/custom_generator_cookbook.rb +136 -0
- data/spec/shared/fixture_cookbook_checksums.rb +46 -0
- data/spec/shared/setup_git_committer_config.rb +54 -0
- data/spec/shared/setup_git_cookbooks.rb +53 -0
- data/spec/spec_helper.rb +51 -0
- data/spec/test_helpers.rb +84 -0
- data/spec/unit/chef_runner_spec.rb +139 -0
- data/spec/unit/chef_server_api_multi_spec.rb +120 -0
- data/spec/unit/cli_spec.rb +375 -0
- data/spec/unit/command/base_spec.rb +195 -0
- data/spec/unit/command/clean_policy_cookbooks_spec.rb +180 -0
- data/spec/unit/command/clean_policy_revisions_spec.rb +180 -0
- data/spec/unit/command/delete_policy_group_spec.rb +206 -0
- data/spec/unit/command/delete_policy_spec.rb +206 -0
- data/spec/unit/command/diff_spec.rb +311 -0
- data/spec/unit/command/env_spec.rb +86 -0
- data/spec/unit/command/exec_spec.rb +178 -0
- data/spec/unit/command/export_spec.rb +199 -0
- data/spec/unit/command/generate_spec.rb +142 -0
- data/spec/unit/command/generator_commands/attribute_spec.rb +31 -0
- data/spec/unit/command/generator_commands/base_spec.rb +180 -0
- data/spec/unit/command/generator_commands/build_cookbook_spec.rb +377 -0
- data/spec/unit/command/generator_commands/chef_exts/generator_desc_resource_spec.rb +77 -0
- data/spec/unit/command/generator_commands/chef_exts/recipe_dsl_ext_spec.rb +111 -0
- data/spec/unit/command/generator_commands/cookbook_file_spec.rb +31 -0
- data/spec/unit/command/generator_commands/cookbook_spec.rb +769 -0
- data/spec/unit/command/generator_commands/generator_generator_spec.rb +227 -0
- data/spec/unit/command/generator_commands/helpers_spec.rb +31 -0
- data/spec/unit/command/generator_commands/policyfile_spec.rb +223 -0
- data/spec/unit/command/generator_commands/recipe_spec.rb +37 -0
- data/spec/unit/command/generator_commands/repo_spec.rb +374 -0
- data/spec/unit/command/generator_commands/resource_spec.rb +31 -0
- data/spec/unit/command/generator_commands/template_spec.rb +31 -0
- data/spec/unit/command/install_spec.rb +179 -0
- data/spec/unit/command/push_archive_spec.rb +153 -0
- data/spec/unit/command/push_spec.rb +198 -0
- data/spec/unit/command/shell_init_spec.rb +339 -0
- data/spec/unit/command/show_policy_spec.rb +234 -0
- data/spec/unit/command/undelete_spec.rb +244 -0
- data/spec/unit/command/update_spec.rb +283 -0
- data/spec/unit/command/verify_spec.rb +341 -0
- data/spec/unit/commands_map_spec.rb +57 -0
- data/spec/unit/component_test_spec.rb +128 -0
- data/spec/unit/configurable_spec.rb +68 -0
- data/spec/unit/cookbook_metadata_spec.rb +96 -0
- data/spec/unit/cookbook_profiler/git_spec.rb +176 -0
- data/spec/unit/cookbook_profiler/identifiers_spec.rb +81 -0
- data/spec/unit/fixtures/chef-runner-cookbooks/test_cookbook/recipes/recipe_one.rb +9 -0
- data/spec/unit/fixtures/chef-runner-cookbooks/test_cookbook/recipes/recipe_two.rb +9 -0
- data/spec/unit/fixtures/command/cli_test_command.rb +26 -0
- data/spec/unit/fixtures/command/explicit_path_example.rb +7 -0
- data/spec/unit/fixtures/configurable/test_config_loader.rb +5 -0
- data/spec/unit/fixtures/configurable/test_configurable.rb +10 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/.kitchen.yml +16 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/Berksfile +3 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/README.md +4 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/chefignore +96 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/metadata.rb +8 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/recipes/default.rb +8 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/.kitchen.yml +16 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/Berksfile +3 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/README.md +4 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/chefignore +96 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/metadata.rb +8 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/recipes/default.rb +8 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/Berksfile +3 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/README.md +4 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/chefignore +96 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/kitchen.yml +16 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/metadata.rb +8 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/recipes/default.rb +8 -0
- data/spec/unit/fixtures/cookbooks_api/chef_server_universe.json +56 -0
- data/spec/unit/fixtures/cookbooks_api/pruned_chef_server_universe.json +30 -0
- data/spec/unit/fixtures/cookbooks_api/pruned_small_universe.json +1322 -0
- data/spec/unit/fixtures/cookbooks_api/small_universe.json +2987 -0
- data/spec/unit/fixtures/cookbooks_api/universe.json +1 -0
- data/spec/unit/fixtures/cookbooks_api/update_fixtures.rb +33 -0
- data/spec/unit/fixtures/dev_cookbooks/README.md +16 -0
- data/spec/unit/fixtures/dev_cookbooks/bar-cookbook.gitbundle +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/bin/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/embedded/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/embedded/bin/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_component/bin/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/apps/berkshelf/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/apps/test-kitchen/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/bin/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/bin/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/berkshelf/integration_test +2 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/berkshelf/verify_me +5 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/chef-dk/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/chef/verify_me +3 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/test-kitchen/verify_me +2 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/bin/.keep +0 -0
- data/spec/unit/fixtures/example_app/Policyfile.rb +0 -0
- data/spec/unit/fixtures/example_cookbook/.gitignore +17 -0
- data/spec/unit/fixtures/example_cookbook/.kitchen.yml +16 -0
- data/spec/unit/fixtures/example_cookbook/Berksfile +3 -0
- data/spec/unit/fixtures/example_cookbook/README.md +4 -0
- data/spec/unit/fixtures/example_cookbook/chefignore +96 -0
- data/spec/unit/fixtures/example_cookbook/metadata.rb +8 -0
- data/spec/unit/fixtures/example_cookbook/recipes/default.rb +8 -0
- data/spec/unit/fixtures/example_cookbook_metadata_json_only/.gitignore +17 -0
- data/spec/unit/fixtures/example_cookbook_metadata_json_only/.kitchen.yml +16 -0
- data/spec/unit/fixtures/example_cookbook_metadata_json_only/Berksfile +3 -0
- data/spec/unit/fixtures/example_cookbook_metadata_json_only/README.md +4 -0
- data/spec/unit/fixtures/example_cookbook_metadata_json_only/chefignore +96 -0
- data/spec/unit/fixtures/example_cookbook_metadata_json_only/metadata.json +5 -0
- data/spec/unit/fixtures/example_cookbook_metadata_json_only/recipes/default.rb +8 -0
- data/spec/unit/fixtures/example_cookbook_no_metadata/.gitignore +17 -0
- data/spec/unit/fixtures/example_cookbook_no_metadata/.kitchen.yml +16 -0
- data/spec/unit/fixtures/example_cookbook_no_metadata/Berksfile +3 -0
- data/spec/unit/fixtures/example_cookbook_no_metadata/README.md +4 -0
- data/spec/unit/fixtures/example_cookbook_no_metadata/chefignore +96 -0
- data/spec/unit/fixtures/example_cookbook_no_metadata/recipes/default.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/another-local-cookbook/README.md +4 -0
- data/spec/unit/fixtures/local_path_cookbooks/another-local-cookbook/chefignore +96 -0
- data/spec/unit/fixtures/local_path_cookbooks/another-local-cookbook/metadata.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/another-local-cookbook/recipes/default.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/cookbook-with-a-dep/Berksfile +3 -0
- data/spec/unit/fixtures/local_path_cookbooks/cookbook-with-a-dep/README.md +4 -0
- data/spec/unit/fixtures/local_path_cookbooks/cookbook-with-a-dep/chefignore +96 -0
- data/spec/unit/fixtures/local_path_cookbooks/cookbook-with-a-dep/metadata.rb +9 -0
- data/spec/unit/fixtures/local_path_cookbooks/cookbook-with-a-dep/recipes/default.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/.kitchen.yml +16 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/Berksfile +3 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/README.md +4 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/chefignore +96 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/extra/extra_file.txt +0 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/metadata.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/recipes/default.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/metadata-missing/README.md +2 -0
- data/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/.kitchen.yml +16 -0
- data/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/README.md +4 -0
- data/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/metadata.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/recipes/default.rb +8 -0
- data/spec/unit/generator_spec.rb +119 -0
- data/spec/unit/pager_spec.rb +117 -0
- data/spec/unit/policyfile/artifactory_cookbook_source_spec.rb +59 -0
- data/spec/unit/policyfile/attribute_merge_checker_spec.rb +80 -0
- data/spec/unit/policyfile/chef_repo_cookbook_source_spec.rb +93 -0
- data/spec/unit/policyfile/chef_server_cookbook_source_spec.rb +55 -0
- data/spec/unit/policyfile/chef_server_lock_fetcher_spec.rb +161 -0
- data/spec/unit/policyfile/community_cookbook_source_spec.rb +83 -0
- data/spec/unit/policyfile/comparison_base_spec.rb +340 -0
- data/spec/unit/policyfile/cookbook_location_specification_spec.rb +347 -0
- data/spec/unit/policyfile/cookbook_locks_spec.rb +527 -0
- data/spec/unit/policyfile/delivery_supermarket_source_spec.rb +129 -0
- data/spec/unit/policyfile/differ_spec.rb +686 -0
- data/spec/unit/policyfile/git_lock_fetcher_spec.rb +155 -0
- data/spec/unit/policyfile/included_policies_cookbook_source_spec.rb +242 -0
- data/spec/unit/policyfile/lister_spec.rb +268 -0
- data/spec/unit/policyfile/local_lock_fetcher_spec.rb +199 -0
- data/spec/unit/policyfile/lock_applier_spec.rb +100 -0
- data/spec/unit/policyfile/lock_fetcher_mixin_spec.rb +60 -0
- data/spec/unit/policyfile/null_cookbook_source_spec.rb +34 -0
- data/spec/unit/policyfile/read_cookbook_for_compat_mode_upload_spec.rb +92 -0
- data/spec/unit/policyfile/remote_lock_fetcher_spec.rb +129 -0
- data/spec/unit/policyfile/reports/install_spec.rb +114 -0
- data/spec/unit/policyfile/reports/upload_spec.rb +94 -0
- data/spec/unit/policyfile/solution_dependencies_spec.rb +170 -0
- data/spec/unit/policyfile/source_uri_spec.rb +36 -0
- data/spec/unit/policyfile/storage_config_spec.rb +180 -0
- data/spec/unit/policyfile/undo_record_spec.rb +258 -0
- data/spec/unit/policyfile/undo_stack_spec.rb +265 -0
- data/spec/unit/policyfile/uploader_spec.rb +410 -0
- data/spec/unit/policyfile_demands_spec.rb +1197 -0
- data/spec/unit/policyfile_evaluation_spec.rb +628 -0
- data/spec/unit/policyfile_includes_dsl_spec.rb +220 -0
- data/spec/unit/policyfile_includes_spec.rb +720 -0
- data/spec/unit/policyfile_install_with_includes_spec.rb +232 -0
- data/spec/unit/policyfile_lock_build_spec.rb +1065 -0
- data/spec/unit/policyfile_lock_install_spec.rb +137 -0
- data/spec/unit/policyfile_lock_serialization_spec.rb +424 -0
- data/spec/unit/policyfile_lock_validation_spec.rb +608 -0
- data/spec/unit/policyfile_services/clean_policies_spec.rb +236 -0
- data/spec/unit/policyfile_services/clean_policy_cookbooks_spec.rb +272 -0
- data/spec/unit/policyfile_services/export_repo_spec.rb +473 -0
- data/spec/unit/policyfile_services/install_spec.rb +209 -0
- data/spec/unit/policyfile_services/push_archive_spec.rb +359 -0
- data/spec/unit/policyfile_services/push_spec.rb +249 -0
- data/spec/unit/policyfile_services/rm_policy_group_spec.rb +237 -0
- data/spec/unit/policyfile_services/rm_policy_spec.rb +263 -0
- data/spec/unit/policyfile_services/show_policy_spec.rb +887 -0
- data/spec/unit/policyfile_services/undelete_spec.rb +302 -0
- data/spec/unit/policyfile_services/update_attributes_spec.rb +229 -0
- data/spec/unit/policyfile_services/update_spec.rb +162 -0
- data/spec/unit/service_exception_inspectors/base_spec.rb +41 -0
- data/spec/unit/service_exception_inspectors/http_spec.rb +138 -0
- data/spec/unit/shell_out_spec.rb +34 -0
- metadata +796 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright:: Copyright (c) 2014-2018 Chef Software Inc.
|
|
3
|
+
# License:: Apache License, Version 2.0
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
require_relative "null_cookbook_source"
|
|
19
|
+
require_relative "community_cookbook_source"
|
|
20
|
+
require_relative "chef_server_cookbook_source"
|
|
21
|
+
require_relative "chef_repo_cookbook_source"
|
|
22
|
+
require_relative "delivery_supermarket_source"
|
|
23
|
+
require_relative "artifactory_cookbook_source"
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright:: Copyright (c) 2014-2018 Chef Software Inc.
|
|
3
|
+
# License:: Apache License, Version 2.0
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
require "forwardable" unless defined?(Forwardable)
|
|
19
|
+
|
|
20
|
+
require "semverse"
|
|
21
|
+
|
|
22
|
+
require_relative "community_cookbook_source"
|
|
23
|
+
|
|
24
|
+
module ChefCLI
|
|
25
|
+
module Policyfile
|
|
26
|
+
|
|
27
|
+
# Fetches cookbooks from a supermarket, similar to CommunityCookbookSource
|
|
28
|
+
# (which it delegates to), except that only the latest versions of any
|
|
29
|
+
# cookbook can be used.
|
|
30
|
+
#
|
|
31
|
+
# This is intended to be used in an environment where the team wants to
|
|
32
|
+
# make only the newest version of a given cookbook available in order to
|
|
33
|
+
# force developers to integrate continuously at the component artifact
|
|
34
|
+
# (cookbook) level. To achieve this goal, two constraints must be imposed:
|
|
35
|
+
#
|
|
36
|
+
# * Cookbook changes pass through a Ci pipeline and are ultimately uploaded
|
|
37
|
+
# to a private supermarket (or equivalent, i.e. mini-mart) after final
|
|
38
|
+
# approval (which can be automated or not)
|
|
39
|
+
# * Version numbers for cookbooks that pass through the Ci pipeline always
|
|
40
|
+
# increase over time (so that largest version number == newest)
|
|
41
|
+
#
|
|
42
|
+
# In the future, alternative approaches may be persued to achieve the goal
|
|
43
|
+
# of continuously integrating at the cookbook level without imposing those
|
|
44
|
+
# constraints.
|
|
45
|
+
#
|
|
46
|
+
class DeliverySupermarketSource
|
|
47
|
+
|
|
48
|
+
extend Forwardable
|
|
49
|
+
|
|
50
|
+
def_delegator :@community_source, :uri
|
|
51
|
+
def_delegator :@community_source, :source_options_for
|
|
52
|
+
def_delegator :@community_source, :null?
|
|
53
|
+
def_delegator :@community_source, :preferred_cookbooks
|
|
54
|
+
def_delegator :@community_source, :preferred_source_for?
|
|
55
|
+
def_delegator :@community_source, :preferred_for
|
|
56
|
+
|
|
57
|
+
def initialize(uri)
|
|
58
|
+
@community_source = CommunityCookbookSource.new(uri)
|
|
59
|
+
yield self if block_given?
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def ==(other)
|
|
63
|
+
other.kind_of?(self.class) && other.uri == uri
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def default_source_args
|
|
67
|
+
[:delivery_supermarket, uri]
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def universe_graph
|
|
71
|
+
@universe_graph ||= begin
|
|
72
|
+
@community_source.universe_graph.inject({}) do |truncated, (cookbook_name, version_and_deps_list)|
|
|
73
|
+
sorted_versions = version_and_deps_list.keys.sort_by do |version_string|
|
|
74
|
+
Semverse::Version.new(version_string)
|
|
75
|
+
end
|
|
76
|
+
greatest_version = sorted_versions.last
|
|
77
|
+
truncated[cookbook_name] = { greatest_version => version_and_deps_list[greatest_version] }
|
|
78
|
+
truncated
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def desc
|
|
84
|
+
"delivery_supermarket(#{uri})"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright:: Copyright (c) 2015 Chef Software Inc.
|
|
3
|
+
# License:: Apache License, Version 2.0
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
require "diff/lcs"
|
|
19
|
+
require "diff/lcs/hunk"
|
|
20
|
+
require "paint"
|
|
21
|
+
require "ffi_yajl" unless defined?(FFI_Yajl)
|
|
22
|
+
|
|
23
|
+
module ChefCLI
|
|
24
|
+
module Policyfile
|
|
25
|
+
class Differ
|
|
26
|
+
|
|
27
|
+
POLICY_SECTIONS = %w{ revision_id run_list named_run_lists cookbook_locks default_attributes override_attributes }.freeze
|
|
28
|
+
LINES_OF_CONTEXT = 3
|
|
29
|
+
INITIAL_FILE_LENGTH_DIFFERENCE = 0
|
|
30
|
+
FORMAT = :unified
|
|
31
|
+
|
|
32
|
+
attr_reader :old_lock
|
|
33
|
+
attr_reader :old_name
|
|
34
|
+
attr_reader :new_lock
|
|
35
|
+
attr_reader :new_name
|
|
36
|
+
attr_reader :ui
|
|
37
|
+
|
|
38
|
+
def initialize(old_name: nil, old_lock: nil, new_name: nil, new_lock: nil, ui: nil)
|
|
39
|
+
@old_lock = old_lock
|
|
40
|
+
@new_lock = new_lock
|
|
41
|
+
@old_name = old_name
|
|
42
|
+
@new_name = new_name
|
|
43
|
+
@ui = ui
|
|
44
|
+
|
|
45
|
+
@added_cookbooks = nil
|
|
46
|
+
@removed_cookbooks = nil
|
|
47
|
+
@modified_cookbooks = nil
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def lock_name
|
|
51
|
+
old_lock["name"]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def old_cookbook_locks
|
|
55
|
+
old_lock["cookbook_locks"]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def new_cookbook_locks
|
|
59
|
+
new_lock["cookbook_locks"]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def updated_sections
|
|
63
|
+
@updated_sections ||= POLICY_SECTIONS.select do |key|
|
|
64
|
+
old_lock[key] != new_lock[key]
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def different?
|
|
69
|
+
!updated_sections.empty?
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def run_report
|
|
73
|
+
unless different?
|
|
74
|
+
ui.err("No changes for policy lock '#{lock_name}' between '#{old_name}' and '#{new_name}'")
|
|
75
|
+
return true
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
ui.print("Policy lock '#{lock_name}' differs between '#{old_name}' and '#{new_name}':\n\n")
|
|
79
|
+
|
|
80
|
+
report_rev_id_changes
|
|
81
|
+
report_run_list_changes
|
|
82
|
+
report_added_cookbooks
|
|
83
|
+
report_removed_cookbooks
|
|
84
|
+
report_modified_cookbooks
|
|
85
|
+
report_default_attribute_changes
|
|
86
|
+
report_override_attribute_changes
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def report_rev_id_changes
|
|
90
|
+
h1("REVISION ID CHANGED")
|
|
91
|
+
old_rev = old_lock["revision_id"]
|
|
92
|
+
new_rev = new_lock["revision_id"]
|
|
93
|
+
diff_lines([ old_rev ], [ new_rev ])
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def report_run_list_changes
|
|
97
|
+
return nil unless updated_sections.include?("run_list")
|
|
98
|
+
h1("RUN LIST CHANGED")
|
|
99
|
+
|
|
100
|
+
old_run_list = old_lock["run_list"]
|
|
101
|
+
new_run_list = new_lock["run_list"]
|
|
102
|
+
|
|
103
|
+
diff_lines(old_run_list, new_run_list)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def report_removed_cookbooks
|
|
107
|
+
return nil if removed_cookbooks.empty?
|
|
108
|
+
h1("REMOVED COOKBOOKS")
|
|
109
|
+
removed_cookbooks.each do |cb_name|
|
|
110
|
+
ui.print("\n")
|
|
111
|
+
old_lock = pretty_json(old_cookbook_locks[cb_name])
|
|
112
|
+
new_lock = []
|
|
113
|
+
h2(cb_name)
|
|
114
|
+
diff_lines(old_lock, new_lock)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def report_added_cookbooks
|
|
119
|
+
return nil if added_cookbooks.empty?
|
|
120
|
+
h1("ADDED COOKBOOKS")
|
|
121
|
+
added_cookbooks.each do |cb_name|
|
|
122
|
+
ui.print("\n")
|
|
123
|
+
old_lock = []
|
|
124
|
+
new_lock = pretty_json(new_cookbook_locks[cb_name])
|
|
125
|
+
h2(cb_name)
|
|
126
|
+
diff_lines(old_lock, new_lock)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def report_modified_cookbooks
|
|
131
|
+
return nil if modified_cookbooks.empty?
|
|
132
|
+
h1("MODIFIED COOKBOOKS")
|
|
133
|
+
modified_cookbooks.each do |cb_name|
|
|
134
|
+
ui.print("\n")
|
|
135
|
+
old_lock = pretty_json(old_cookbook_locks[cb_name])
|
|
136
|
+
new_lock = pretty_json(new_cookbook_locks[cb_name])
|
|
137
|
+
h2(cb_name)
|
|
138
|
+
diff_lines(old_lock, new_lock)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def report_default_attribute_changes
|
|
143
|
+
return nil unless updated_sections.include?("default_attributes")
|
|
144
|
+
|
|
145
|
+
h1("DEFAULT ATTRIBUTES CHANGED")
|
|
146
|
+
|
|
147
|
+
old_default = pretty_json(old_lock["default_attributes"])
|
|
148
|
+
new_default = pretty_json(new_lock["default_attributes"])
|
|
149
|
+
diff_lines(old_default, new_default)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def report_override_attribute_changes
|
|
153
|
+
return nil unless updated_sections.include?("override_attributes")
|
|
154
|
+
|
|
155
|
+
h1("OVERRIDE ATTRIBUTES CHANGED")
|
|
156
|
+
|
|
157
|
+
old_override = pretty_json(old_lock["override_attributes"])
|
|
158
|
+
new_override = pretty_json(new_lock["override_attributes"])
|
|
159
|
+
diff_lines(old_override, new_override)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def added_cookbooks
|
|
163
|
+
detect_cookbook_changes if @added_cookbooks.nil?
|
|
164
|
+
@added_cookbooks
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def removed_cookbooks
|
|
168
|
+
detect_cookbook_changes if @removed_cookbooks.nil?
|
|
169
|
+
@removed_cookbooks
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def modified_cookbooks
|
|
173
|
+
detect_cookbook_changes if @modified_cookbooks.nil?
|
|
174
|
+
@modified_cookbooks
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
private
|
|
178
|
+
|
|
179
|
+
def h1(str)
|
|
180
|
+
ui.msg(str)
|
|
181
|
+
ui.msg("=" * str.size)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def h2(str)
|
|
185
|
+
ui.msg(str)
|
|
186
|
+
ui.msg("-" * str.size)
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def diff_lines(old_lines, new_lines)
|
|
190
|
+
file_length_difference = INITIAL_FILE_LENGTH_DIFFERENCE
|
|
191
|
+
|
|
192
|
+
previous_hunk = nil
|
|
193
|
+
|
|
194
|
+
diffs = Diff::LCS.diff(old_lines, new_lines)
|
|
195
|
+
|
|
196
|
+
ui.print("\n")
|
|
197
|
+
|
|
198
|
+
diffs.each do |piece|
|
|
199
|
+
hunk = Diff::LCS::Hunk.new(old_lines, new_lines, piece, LINES_OF_CONTEXT, file_length_difference)
|
|
200
|
+
|
|
201
|
+
file_length_difference = hunk.file_length_difference
|
|
202
|
+
|
|
203
|
+
maybe_contiguous_hunks = (previous_hunk.nil? || hunk.merge(previous_hunk))
|
|
204
|
+
|
|
205
|
+
if !maybe_contiguous_hunks
|
|
206
|
+
print_color_diff("#{previous_hunk.diff(FORMAT)}\n")
|
|
207
|
+
end
|
|
208
|
+
previous_hunk = hunk
|
|
209
|
+
end
|
|
210
|
+
print_color_diff("#{previous_hunk.diff(FORMAT)}\n") unless previous_hunk.nil?
|
|
211
|
+
ui.print("\n")
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def print_color_diff(hunk)
|
|
215
|
+
hunk.to_s.each_line do |line|
|
|
216
|
+
ui.print(Paint[line, color_for_line(line)])
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def color_for_line(line)
|
|
221
|
+
case line[0].chr
|
|
222
|
+
when "+"
|
|
223
|
+
:green
|
|
224
|
+
when "-"
|
|
225
|
+
:red
|
|
226
|
+
when "@"
|
|
227
|
+
line[1].chr == "@" ? :blue : nil
|
|
228
|
+
else
|
|
229
|
+
nil
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def pretty_json(data)
|
|
234
|
+
FFI_Yajl::Encoder.encode(data, pretty: true).lines.map { |l| l.chomp }
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def detect_cookbook_changes
|
|
238
|
+
all_locked_cookbooks = old_cookbook_locks.keys | new_cookbook_locks.keys
|
|
239
|
+
|
|
240
|
+
@added_cookbooks = []
|
|
241
|
+
@removed_cookbooks = []
|
|
242
|
+
@modified_cookbooks = []
|
|
243
|
+
|
|
244
|
+
all_locked_cookbooks.each do |cb_name|
|
|
245
|
+
if old_cookbook_locks.key?(cb_name) && new_cookbook_locks.key?(cb_name)
|
|
246
|
+
old_cb_lock = old_cookbook_locks[cb_name]
|
|
247
|
+
new_cb_lock = new_cookbook_locks[cb_name]
|
|
248
|
+
if old_cb_lock != new_cb_lock
|
|
249
|
+
@modified_cookbooks << cb_name
|
|
250
|
+
end
|
|
251
|
+
elsif old_cookbook_locks.key?(cb_name)
|
|
252
|
+
@removed_cookbooks << cb_name
|
|
253
|
+
elsif new_cookbook_locks.key?(cb_name)
|
|
254
|
+
@added_cookbooks << cb_name
|
|
255
|
+
else
|
|
256
|
+
raise "Bug: cookbook lock #{cb_name} cannot be determined as new/removed/modified/unmodified"
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
end
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright:: Copyright (c) 2014-2019, Chef Software Inc.
|
|
3
|
+
# License:: Apache License, Version 2.0
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
require_relative "cookbook_sources"
|
|
19
|
+
require_relative "cookbook_location_specification"
|
|
20
|
+
require_relative "storage_config"
|
|
21
|
+
require_relative "policyfile_location_specification"
|
|
22
|
+
|
|
23
|
+
require "chef/node/attribute"
|
|
24
|
+
require "chef/run_list/run_list_item"
|
|
25
|
+
|
|
26
|
+
module ChefCLI
|
|
27
|
+
module Policyfile
|
|
28
|
+
class DSL
|
|
29
|
+
|
|
30
|
+
RUN_LIST_ITEM_COMPONENT = %r{^[.[:alnum:]_-]+$}.freeze
|
|
31
|
+
|
|
32
|
+
include StorageConfigDelegation
|
|
33
|
+
|
|
34
|
+
attr_writer :name
|
|
35
|
+
|
|
36
|
+
attr_reader :errors
|
|
37
|
+
attr_writer :run_list
|
|
38
|
+
attr_writer :default_source
|
|
39
|
+
attr_reader :cookbook_location_specs
|
|
40
|
+
attr_reader :included_policies
|
|
41
|
+
|
|
42
|
+
attr_reader :named_run_lists
|
|
43
|
+
attr_reader :node_attributes
|
|
44
|
+
|
|
45
|
+
attr_reader :storage_config
|
|
46
|
+
|
|
47
|
+
attr_reader :chef_config
|
|
48
|
+
def initialize(storage_config, chef_config: nil)
|
|
49
|
+
@name = nil
|
|
50
|
+
@errors = []
|
|
51
|
+
@run_list = []
|
|
52
|
+
@named_run_lists = {}
|
|
53
|
+
@included_policies = []
|
|
54
|
+
@default_source = [ NullCookbookSource.new ]
|
|
55
|
+
@cookbook_location_specs = {}
|
|
56
|
+
@storage_config = storage_config
|
|
57
|
+
@chef_config = chef_config
|
|
58
|
+
|
|
59
|
+
@node_attributes = Chef::Node::Attribute.new({}, {}, {}, {})
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def name(name = nil)
|
|
63
|
+
unless name.nil?
|
|
64
|
+
@name = name
|
|
65
|
+
end
|
|
66
|
+
@name
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def run_list(*run_list_items)
|
|
70
|
+
run_list_items = run_list_items.flatten
|
|
71
|
+
unless run_list_items.empty?
|
|
72
|
+
validate_run_list_items(run_list_items)
|
|
73
|
+
@run_list = run_list_items
|
|
74
|
+
end
|
|
75
|
+
@run_list
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def named_run_list(name, *run_list_items)
|
|
79
|
+
run_list_items = run_list_items.flatten
|
|
80
|
+
unless run_list_items.empty?
|
|
81
|
+
validate_run_list_items(run_list_items, name)
|
|
82
|
+
@named_run_lists[name] = run_list_items
|
|
83
|
+
end
|
|
84
|
+
@named_run_lists[name]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def default_source(source_type = nil, source_argument = nil, &block)
|
|
88
|
+
return @default_source if source_type.nil?
|
|
89
|
+
case source_type
|
|
90
|
+
when :community, :supermarket
|
|
91
|
+
set_default_community_source(source_argument, &block)
|
|
92
|
+
when :delivery_supermarket
|
|
93
|
+
set_default_delivery_supermarket_source(source_argument, &block)
|
|
94
|
+
when :chef_server
|
|
95
|
+
set_default_chef_server_source(source_argument, &block)
|
|
96
|
+
when :chef_repo
|
|
97
|
+
set_default_chef_repo_source(source_argument, &block)
|
|
98
|
+
when :artifactory
|
|
99
|
+
set_default_artifactory_source(source_argument, &block)
|
|
100
|
+
else
|
|
101
|
+
@errors << "Invalid default_source type '#{source_type.inspect}'"
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def cookbook(name, *version_and_source_opts)
|
|
106
|
+
source_options =
|
|
107
|
+
if version_and_source_opts.last.is_a?(Hash)
|
|
108
|
+
version_and_source_opts.pop
|
|
109
|
+
else
|
|
110
|
+
{}
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
constraint = version_and_source_opts.first || ">= 0.0.0"
|
|
114
|
+
spec = CookbookLocationSpecification.new(name, constraint, source_options, storage_config)
|
|
115
|
+
|
|
116
|
+
if ( existing_source = @cookbook_location_specs[name] )
|
|
117
|
+
err = "Cookbook '#{name}' assigned to conflicting sources\n\n"
|
|
118
|
+
err << "Previous source: #{existing_source.source_options.inspect}\n"
|
|
119
|
+
err << "Conflicts with: #{source_options.inspect}\n"
|
|
120
|
+
@errors << err
|
|
121
|
+
else
|
|
122
|
+
@cookbook_location_specs[name] = spec
|
|
123
|
+
@errors += spec.errors
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def include_policy(name, source_options = {})
|
|
128
|
+
if ( existing = included_policies.find { |p| p.name == name } )
|
|
129
|
+
err = "Included policy '#{name}' assigned conflicting locations or was already specified\n\n"
|
|
130
|
+
err << "Previous source: #{existing.source_options.inspect}\n"
|
|
131
|
+
err << "Conflicts with: #{source_options.inspect}\n"
|
|
132
|
+
@errors << err
|
|
133
|
+
else
|
|
134
|
+
spec = PolicyfileLocationSpecification.new(name, source_options, storage_config, chef_config)
|
|
135
|
+
included_policies << spec
|
|
136
|
+
@errors += spec.errors
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def default
|
|
141
|
+
@node_attributes.default
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def override
|
|
145
|
+
@node_attributes.override
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def eval_policyfile(policyfile_string)
|
|
149
|
+
@policyfile_filename = policyfile_filename
|
|
150
|
+
instance_eval(policyfile_string, policyfile_filename)
|
|
151
|
+
validate!
|
|
152
|
+
self
|
|
153
|
+
rescue SyntaxError => e
|
|
154
|
+
@errors << "Invalid Ruby syntax in Policyfile '#{policyfile_filename}':\n\n#{e.message}"
|
|
155
|
+
rescue SignalException, SystemExit
|
|
156
|
+
# allow signal from kill, ctrl-C, etc. to bubble up:
|
|
157
|
+
raise
|
|
158
|
+
rescue Exception => e
|
|
159
|
+
error_message = "Evaluation of policyfile '#{policyfile_filename}' raised an exception\n"
|
|
160
|
+
error_message << " Exception: #{e.class.name} \"#{e}\"\n\n"
|
|
161
|
+
trace = filtered_bt(policyfile_filename, e)
|
|
162
|
+
error_message << " Relevant Code:\n"
|
|
163
|
+
error_message << " #{error_context(policyfile_string, policyfile_filename, e)}\n\n"
|
|
164
|
+
unless trace.empty?
|
|
165
|
+
error_message << " Backtrace:\n"
|
|
166
|
+
# TODO: need a way to disable filtering
|
|
167
|
+
error_message << filtered_bt(policyfile_filename, e).inject("") { |formatted_trace, line| formatted_trace << " #{line}\n" }
|
|
168
|
+
end
|
|
169
|
+
@errors << error_message
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
private
|
|
173
|
+
|
|
174
|
+
def set_default_community_source(source_uri, &block)
|
|
175
|
+
set_default_source(CommunityCookbookSource.new(source_uri, &block))
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def set_default_delivery_supermarket_source(source_uri, &block)
|
|
179
|
+
if source_uri.nil?
|
|
180
|
+
@errors << "You must specify the server's URI when using a default_source :delivery_supermarket"
|
|
181
|
+
else
|
|
182
|
+
set_default_source(DeliverySupermarketSource.new(source_uri, &block))
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def set_default_chef_server_source(source_uri, &block)
|
|
187
|
+
if source_uri.nil?
|
|
188
|
+
@errors << "You must specify the server's URI when using a default_source :chef_server"
|
|
189
|
+
else
|
|
190
|
+
set_default_source(ChefServerCookbookSource.new(source_uri, chef_config: chef_config, &block))
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def set_default_artifactory_source(source_uri, &block)
|
|
195
|
+
if source_uri.nil?
|
|
196
|
+
@errors << "You must specify the server's URI when using a default_source :artifactory"
|
|
197
|
+
else
|
|
198
|
+
set_default_source(ArtifactoryCookbookSource.new(source_uri, chef_config: chef_config, &block))
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def set_default_chef_repo_source(path, &block)
|
|
203
|
+
if path.nil?
|
|
204
|
+
@errors << "You must specify the path to the chef-repo when using a default_source :chef_repo"
|
|
205
|
+
else
|
|
206
|
+
set_default_source(ChefRepoCookbookSource.new(File.expand_path(path, storage_config.relative_paths_root), &block))
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def set_default_source(source)
|
|
211
|
+
@default_source.delete_at(0) if @default_source[0].null?
|
|
212
|
+
@default_source << source
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def validate!
|
|
216
|
+
if @run_list.empty?
|
|
217
|
+
@errors << "Invalid run_list. run_list cannot be empty"
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
handle_preferred_cookbooks_conflicts
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def validate_run_list_items(items, run_list_name = nil)
|
|
224
|
+
items.each do |item|
|
|
225
|
+
|
|
226
|
+
run_list_desc = run_list_name.nil? ? "Run List Item '#{item}'" : "Named Run List '#{run_list_name}' Item '#{item}'"
|
|
227
|
+
|
|
228
|
+
item_name = Chef::RunList::RunListItem.new(item).name
|
|
229
|
+
cookbook, separator, recipe = item_name.partition("::")
|
|
230
|
+
|
|
231
|
+
if RUN_LIST_ITEM_COMPONENT.match(cookbook).nil?
|
|
232
|
+
message = "#{run_list_desc} has invalid cookbook name '#{cookbook}'.\nCookbook names can only contain alphanumerics, hyphens, and underscores."
|
|
233
|
+
|
|
234
|
+
# Special case when there's only one colon instead of two:
|
|
235
|
+
if cookbook =~ /[^:]:[^:]/
|
|
236
|
+
message << "\nDid you mean '#{item.sub(":", "::")}'?"
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
@errors << message
|
|
240
|
+
end
|
|
241
|
+
unless separator.empty?
|
|
242
|
+
# we have a cookbook and recipe
|
|
243
|
+
if RUN_LIST_ITEM_COMPONENT.match(recipe).nil?
|
|
244
|
+
@errors << "#{run_list_desc} has invalid recipe name '#{recipe}'.\nRecipe names can only contain alphanumerics, hyphens, and underscores."
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def handle_preferred_cookbooks_conflicts
|
|
251
|
+
conflicting_source_messages = []
|
|
252
|
+
default_source.combination(2).each do |source_a, source_b|
|
|
253
|
+
conflicting_preferences = source_a.preferred_cookbooks & source_b.preferred_cookbooks
|
|
254
|
+
next if conflicting_preferences.empty?
|
|
255
|
+
conflicting_source_messages << "#{source_a.desc} and #{source_b.desc} are both set as the preferred source for cookbook(s) '#{conflicting_preferences.join(', ')}'"
|
|
256
|
+
end
|
|
257
|
+
unless conflicting_source_messages.empty?
|
|
258
|
+
msg = "Multiple sources are marked as the preferred source for some cookbooks. Only one source can be preferred for a cookbook.\n"
|
|
259
|
+
msg << conflicting_source_messages.join("\n") << "\n"
|
|
260
|
+
@errors << msg
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def error_context(policyfile_string, policyfile_filename, exception)
|
|
265
|
+
if ( line_number_to_show = culprit_line_number(policyfile_filename, exception) )
|
|
266
|
+
code = policyfile_string.lines.to_a[line_number_to_show - 1].strip
|
|
267
|
+
"#{line_number_to_show}: #{code}"
|
|
268
|
+
else
|
|
269
|
+
"Could not find relevant code from backtrace"
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
def culprit_line_number(policyfile_filename, exception)
|
|
274
|
+
if ( most_proximate_backtrace_line = filtered_bt(policyfile_filename, exception).first )
|
|
275
|
+
most_proximate_backtrace_line[/^(?:.\:)?[^:]+:([\d]+)/, 1].to_i
|
|
276
|
+
else
|
|
277
|
+
nil
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def filtered_bt(policyfile_filename, exception)
|
|
282
|
+
policyfile_filename_matcher = /^#{Regexp.escape(policyfile_filename)}/
|
|
283
|
+
exception.backtrace.select { |line| line =~ policyfile_filename_matcher }
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
end
|