akerl-r10k 3.14.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +1 -0
- data/.github/pull_request_template.md +4 -0
- data/.github/workflows/docker.yml +64 -0
- data/.github/workflows/release.yml +37 -0
- data/.github/workflows/rspec_tests.yml +81 -0
- data/.github/workflows/stale.yml +21 -0
- data/.gitignore +10 -0
- data/.travis.yml +42 -0
- data/CHANGELOG.mkd +1879 -0
- data/CODEOWNERS +2 -0
- data/CONTRIBUTING.mkd +105 -0
- data/Gemfile +15 -0
- data/LICENSE +14 -0
- data/README.mkd +139 -0
- data/Rakefile +3 -0
- data/bin/r10k +17 -0
- data/doc/common-patterns.mkd +45 -0
- data/doc/dynamic-environments/configuration.mkd +850 -0
- data/doc/dynamic-environments/git-environments.mkd +75 -0
- data/doc/dynamic-environments/introduction.mkd +69 -0
- data/doc/dynamic-environments/master-configuration.mkd +40 -0
- data/doc/dynamic-environments/quickstart.mkd +201 -0
- data/doc/dynamic-environments/svn-environments.mkd +45 -0
- data/doc/dynamic-environments/usage.mkd +163 -0
- data/doc/dynamic-environments/workflow-guide.mkd +247 -0
- data/doc/dynamic-environments.mkd +31 -0
- data/doc/faq.mkd +164 -0
- data/doc/git/cloning-and-mirroring.mkd +60 -0
- data/doc/git/providers.mkd +133 -0
- data/doc/puppetfile.mkd +355 -0
- data/doc/updating-your-puppetfile.mkd +38 -0
- data/docker/.gitignore +1 -0
- data/docker/.rspec +4 -0
- data/docker/Gemfile +11 -0
- data/docker/Makefile +99 -0
- data/docker/README.md +28 -0
- data/docker/docker-compose.yml +18 -0
- data/docker/r10k/Dockerfile +68 -0
- data/docker/r10k/adduser.sh +13 -0
- data/docker/r10k/docker-entrypoint.d/10-analytics.sh +30 -0
- data/docker/r10k/docker-entrypoint.sh +10 -0
- data/docker/r10k/release.Dockerfile +55 -0
- data/docker/spec/dockerfile_spec.rb +37 -0
- data/docker/spec/fixtures/Puppetfile +2 -0
- data/integration/Gemfile +19 -0
- data/integration/README.mkd +29 -0
- data/integration/Rakefile +79 -0
- data/integration/component/pre-suite/05_install_dev_r10k.rb +12 -0
- data/integration/files/README.mkd +4 -0
- data/integration/files/hiera.yaml +8 -0
- data/integration/files/modules/helloworld/manifests/init.pp +3 -0
- data/integration/files/modules/hieratest/manifests/init.pp +3 -0
- data/integration/files/modules/unicode/files/pretend_unicode +1 -0
- data/integration/files/modules/unicode/manifests/init.pp +6 -0
- data/integration/files/pre-suite/git_config.pp.erb +19 -0
- data/integration/files/pre-suite/prod_env.config +3 -0
- data/integration/files/r10k_conf.yaml.erb +9 -0
- data/integration/lib/README.mkd +4 -0
- data/integration/lib/git_utils.rb +205 -0
- data/integration/lib/master_manipulator.rb +205 -0
- data/integration/lib/r10k_utils.rb +222 -0
- data/integration/manifests/README.mkd +4 -0
- data/integration/pre-suite/00_pe_install.rb +6 -0
- data/integration/pre-suite/10_git_config.rb +48 -0
- data/integration/pre-suite/20_pe_r10k.rb +55 -0
- data/integration/pre-suite/README.mkd +5 -0
- data/integration/tests/Puppetfile/HTTP_PROXY_affects_forge_source.rb +72 -0
- data/integration/tests/Puppetfile/HTTP_PROXY_affects_git_source.rb +70 -0
- data/integration/tests/README.mkd +4 -0
- data/integration/tests/basic_functionality/basic_deployment.rb +176 -0
- data/integration/tests/basic_functionality/install_pe_only_module_with_puppetfile.rb +83 -0
- data/integration/tests/basic_functionality/negative/neg_deploy_with_invalid_r10k_yaml.rb +51 -0
- data/integration/tests/basic_functionality/negative/neg_deploy_with_missing_r10k_yaml.rb +28 -0
- data/integration/tests/basic_functionality/negative/neg_invalid_git_provider.rb +45 -0
- data/integration/tests/basic_functionality/negative/negative_bad_proxy.rb +34 -0
- data/integration/tests/basic_functionality/proxy_specified_in_configuration.rb +103 -0
- data/integration/tests/basic_functionality/proxy_with_pe_only_module.rb +128 -0
- data/integration/tests/basic_functionality/proxy_with_puppetfile.rb +61 -0
- data/integration/tests/basic_functionality/rugged_git_provider_with_ssh.rb +109 -0
- data/integration/tests/basic_functionality/rugged_git_provider_without_ssh.rb +108 -0
- data/integration/tests/command_line/deploy_env_without_mod_update.rb +76 -0
- data/integration/tests/command_line/negative/neg_deploy_env_with_module_update.rb +77 -0
- data/integration/tests/command_line/negative/neg_invalid_cmd_line_arg.rb +23 -0
- data/integration/tests/git_source/HTTP_proxy_and_git_source.rb +70 -0
- data/integration/tests/git_source/git_source_git.rb +128 -0
- data/integration/tests/git_source/git_source_repeated_remote.rb +68 -0
- data/integration/tests/git_source/git_source_ssh.rb +87 -0
- data/integration/tests/git_source/git_source_submodule.rb +70 -0
- data/integration/tests/git_source/negative/neg_git_broken_remote.rb +38 -0
- data/integration/tests/git_source/negative/neg_git_unauthorized_https.rb +46 -0
- data/integration/tests/git_source/negative/neg_git_unauthorized_ssh.rb +73 -0
- data/integration/tests/git_source/negative/neg_git_unicode_branch.rb +35 -0
- data/integration/tests/i18n/deploy_module_with_unicode_in_file_name.rb +64 -0
- data/integration/tests/purging/content_not_purged_at_root.rb +89 -0
- data/integration/tests/purging/default_purging.rb +125 -0
- data/integration/tests/purging/does_not_purge_files_on_white_list.rb +93 -0
- data/integration/tests/purging/invalid_whitelist_types.rb +63 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_1000_branches.rb +66 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +112 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +118 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_hiera.rb +100 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_multi_source.rb +133 -0
- data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +161 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_basedir.rb +46 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_forge_module.rb +48 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module.rb +45 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +43 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_remote.rb +45 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_branch_name_collision.rb +64 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_disk_full.rb +75 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_duplicate_module_names.rb +44 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_inaccessible_forge.rb +58 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_env_name.rb +34 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_puppet_file.rb +36 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_module_specified_at_deleted_release.rb +49 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_read_only.rb +58 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +45 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_10000_files.rb +75 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +105 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_module.rb +81 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_custom_module.rb +49 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_large_files.rb +75 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_module_already_installed.rb +82 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_module_last_release_deleted.rb +68 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_non-existent_base_dir.rb +94 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +89 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_switch_forge_git_module.rb +117 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_unicode_paths.rb +60 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_upgrade_forge_mod_revert_change.rb +166 -0
- data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +163 -0
- data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +111 -0
- data/integration/tests/user_scenario/complex_workflow/multi_env_unamanaged.rb +78 -0
- data/integration/tests/user_scenario/complex_workflow/single_env_git_module_update.rb +100 -0
- data/lib/r10k/action/base.rb +41 -0
- data/lib/r10k/action/cri_runner.rb +72 -0
- data/lib/r10k/action/deploy/deploy_helpers.rb +38 -0
- data/lib/r10k/action/deploy/display.rb +128 -0
- data/lib/r10k/action/deploy/environment.rb +260 -0
- data/lib/r10k/action/deploy/module.rb +139 -0
- data/lib/r10k/action/deploy.rb +9 -0
- data/lib/r10k/action/puppetfile/check.rb +35 -0
- data/lib/r10k/action/puppetfile/cri_runner.rb +26 -0
- data/lib/r10k/action/puppetfile/install.rb +48 -0
- data/lib/r10k/action/puppetfile/purge.rb +37 -0
- data/lib/r10k/action/puppetfile.rb +10 -0
- data/lib/r10k/action/runner.rb +171 -0
- data/lib/r10k/action/visitor.rb +34 -0
- data/lib/r10k/cli/deploy.rb +126 -0
- data/lib/r10k/cli/ext/logging.rb +15 -0
- data/lib/r10k/cli/help.rb +7 -0
- data/lib/r10k/cli/puppetfile.rb +73 -0
- data/lib/r10k/cli/version.rb +31 -0
- data/lib/r10k/cli.rb +51 -0
- data/lib/r10k/content_synchronizer.rb +95 -0
- data/lib/r10k/deployment/config.rb +56 -0
- data/lib/r10k/deployment.rb +132 -0
- data/lib/r10k/environment/bare.rb +13 -0
- data/lib/r10k/environment/base.rb +230 -0
- data/lib/r10k/environment/git.rb +93 -0
- data/lib/r10k/environment/name.rb +109 -0
- data/lib/r10k/environment/plain.rb +16 -0
- data/lib/r10k/environment/svn.rb +98 -0
- data/lib/r10k/environment/tarball.rb +78 -0
- data/lib/r10k/environment/with_modules.rb +174 -0
- data/lib/r10k/environment.rb +39 -0
- data/lib/r10k/errors/formatting.rb +28 -0
- data/lib/r10k/errors.rb +66 -0
- data/lib/r10k/feature/collection.rb +23 -0
- data/lib/r10k/feature.rb +56 -0
- data/lib/r10k/features.rb +20 -0
- data/lib/r10k/forge/module_release.rb +229 -0
- data/lib/r10k/git/alternates.rb +63 -0
- data/lib/r10k/git/cache.rb +107 -0
- data/lib/r10k/git/errors.rb +34 -0
- data/lib/r10k/git/rugged/bare_repository.rb +85 -0
- data/lib/r10k/git/rugged/base_repository.rb +104 -0
- data/lib/r10k/git/rugged/cache.rb +19 -0
- data/lib/r10k/git/rugged/credentials.rb +205 -0
- data/lib/r10k/git/rugged/thin_repository.rb +96 -0
- data/lib/r10k/git/rugged/working_repository.rb +149 -0
- data/lib/r10k/git/rugged.rb +17 -0
- data/lib/r10k/git/shellgit/bare_repository.rb +43 -0
- data/lib/r10k/git/shellgit/base_repository.rb +137 -0
- data/lib/r10k/git/shellgit/cache.rb +11 -0
- data/lib/r10k/git/shellgit/thin_repository.rb +73 -0
- data/lib/r10k/git/shellgit/working_repository.rb +112 -0
- data/lib/r10k/git/shellgit.rb +9 -0
- data/lib/r10k/git/stateful_repository.rb +109 -0
- data/lib/r10k/git.rb +200 -0
- data/lib/r10k/initializers.rb +93 -0
- data/lib/r10k/instance_cache.rb +32 -0
- data/lib/r10k/keyed_factory.rb +39 -0
- data/lib/r10k/logging/terminaloutputter.rb +36 -0
- data/lib/r10k/logging.rb +186 -0
- data/lib/r10k/module/base.rb +182 -0
- data/lib/r10k/module/definition.rb +64 -0
- data/lib/r10k/module/forge.rb +208 -0
- data/lib/r10k/module/git.rb +156 -0
- data/lib/r10k/module/local.rb +40 -0
- data/lib/r10k/module/metadata_file.rb +31 -0
- data/lib/r10k/module/svn.rb +129 -0
- data/lib/r10k/module/tarball.rb +101 -0
- data/lib/r10k/module.rb +57 -0
- data/lib/r10k/module_loader/puppetfile/dsl.rb +42 -0
- data/lib/r10k/module_loader/puppetfile.rb +290 -0
- data/lib/r10k/puppetfile.rb +211 -0
- data/lib/r10k/settings/collection.rb +123 -0
- data/lib/r10k/settings/container.rb +97 -0
- data/lib/r10k/settings/definition.rb +124 -0
- data/lib/r10k/settings/enum_definition.rb +30 -0
- data/lib/r10k/settings/helpers.rb +38 -0
- data/lib/r10k/settings/list.rb +107 -0
- data/lib/r10k/settings/loader.rb +99 -0
- data/lib/r10k/settings/mixin.rb +54 -0
- data/lib/r10k/settings/uri_definition.rb +19 -0
- data/lib/r10k/settings.rb +312 -0
- data/lib/r10k/source/base.rb +93 -0
- data/lib/r10k/source/exec.rb +51 -0
- data/lib/r10k/source/git.rb +178 -0
- data/lib/r10k/source/hash.rb +182 -0
- data/lib/r10k/source/svn.rb +142 -0
- data/lib/r10k/source/yaml.rb +20 -0
- data/lib/r10k/source/yamldir.rb +32 -0
- data/lib/r10k/source.rb +42 -0
- data/lib/r10k/svn/remote.rb +68 -0
- data/lib/r10k/svn/working_dir.rb +125 -0
- data/lib/r10k/svn.rb +6 -0
- data/lib/r10k/tarball.rb +183 -0
- data/lib/r10k/util/attempt.rb +84 -0
- data/lib/r10k/util/basedir.rb +65 -0
- data/lib/r10k/util/cacheable.rb +31 -0
- data/lib/r10k/util/cleaner.rb +21 -0
- data/lib/r10k/util/commands.rb +31 -0
- data/lib/r10k/util/downloader.rb +134 -0
- data/lib/r10k/util/exec_env.rb +36 -0
- data/lib/r10k/util/license.rb +24 -0
- data/lib/r10k/util/platform.rb +42 -0
- data/lib/r10k/util/purgeable.rb +154 -0
- data/lib/r10k/util/setopts.rb +78 -0
- data/lib/r10k/util/subprocess/result.rb +56 -0
- data/lib/r10k/util/subprocess/runner/jruby.rb +23 -0
- data/lib/r10k/util/subprocess/runner/posix.rb +103 -0
- data/lib/r10k/util/subprocess/runner/pump.rb +59 -0
- data/lib/r10k/util/subprocess/runner/windows.rb +23 -0
- data/lib/r10k/util/subprocess/runner.rb +26 -0
- data/lib/r10k/util/subprocess/subprocess_error.rb +24 -0
- data/lib/r10k/util/subprocess.rb +85 -0
- data/lib/r10k/util/symbolize_keys.rb +35 -0
- data/lib/r10k/version.rb +6 -0
- data/lib/r10k.rb +11 -0
- data/locales/config.yaml +21 -0
- data/locales/r10k.pot +693 -0
- data/r10k.gemspec +52 -0
- data/r10k.yaml.example +140 -0
- data/spec/fixtures/empty/.empty +0 -0
- data/spec/fixtures/integration/git/puppet-boolean-bare.tar +0 -0
- data/spec/fixtures/module/forge/bad_module/metadata.json +1 -0
- data/spec/fixtures/module/forge/eight_hundred/Modulefile +8 -0
- data/spec/fixtures/module/forge/eight_hundred/metadata.json +19 -0
- data/spec/fixtures/tarball/tarball.tar.gz +0 -0
- data/spec/fixtures/unit/action/r10k.yaml +5 -0
- data/spec/fixtures/unit/action/r10k_cachedir.yaml +2 -0
- data/spec/fixtures/unit/action/r10k_creds.yaml +9 -0
- data/spec/fixtures/unit/action/r10k_forge_auth.yaml +4 -0
- data/spec/fixtures/unit/action/r10k_forge_auth_no_url.yaml +3 -0
- data/spec/fixtures/unit/action/r10k_generate_types.yaml +3 -0
- data/spec/fixtures/unit/action/r10k_logging.yaml +12 -0
- data/spec/fixtures/unit/action/r10k_puppet_path.yaml +3 -0
- data/spec/fixtures/unit/puppetfile/argument-error/Puppetfile +1 -0
- data/spec/fixtures/unit/puppetfile/default-branch-override/Puppetfile +5 -0
- data/spec/fixtures/unit/puppetfile/duplicate-module-error/Puppetfile +10 -0
- data/spec/fixtures/unit/puppetfile/forge-override/Puppetfile +8 -0
- data/spec/fixtures/unit/puppetfile/invalid-syntax/Puppetfile +1 -0
- data/spec/fixtures/unit/puppetfile/load-error/Puppetfile +1 -0
- data/spec/fixtures/unit/puppetfile/name-error/Puppetfile +1 -0
- data/spec/fixtures/unit/puppetfile/valid-forge-with-version/Puppetfile +1 -0
- data/spec/fixtures/unit/puppetfile/valid-forge-without-version/Puppetfile +1 -0
- data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile +10 -0
- data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile.new +10 -0
- data/spec/fixtures/unit/puppetfile/various-modules/modules/apt/.gitkeep +1 -0
- data/spec/fixtures/unit/puppetfile/various-modules/modules/baz/.gitkeep +1 -0
- data/spec/fixtures/unit/puppetfile/various-modules/modules/buzz/.gitkeep +1 -0
- data/spec/fixtures/unit/puppetfile/various-modules/modules/canary/.gitkeep +1 -0
- data/spec/fixtures/unit/puppetfile/various-modules/modules/fizz/.gitkeep +1 -0
- data/spec/fixtures/unit/puppetfile/various-modules/modules/rpm/.gitkeep +1 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/expected_1 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/managed_symlink_file +1 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_allowlisted_2/ignored_1 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_expected_1 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_unmanaged_1 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/unmanaged_symlink_dir +1 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/managed_symlink_dir +1 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/unmanaged_1 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_one/unmanaged_symlink_file +1 -0
- data/spec/fixtures/unit/util/purgeable/managed_two/.hidden/unmanaged_3 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_two/expected_2 +0 -0
- data/spec/fixtures/unit/util/purgeable/managed_two/unmanaged_2 +0 -0
- data/spec/fixtures/unit/util/subprocess/runner/no-execute.sh +3 -0
- data/spec/integration/git/rugged/bare_repository_spec.rb +13 -0
- data/spec/integration/git/rugged/cache_spec.rb +33 -0
- data/spec/integration/git/rugged/thin_repository_spec.rb +14 -0
- data/spec/integration/git/rugged/working_repository_spec.rb +48 -0
- data/spec/integration/git/shellgit/bare_repository_spec.rb +13 -0
- data/spec/integration/git/shellgit/thin_repository_spec.rb +14 -0
- data/spec/integration/git/shellgit/working_repository_spec.rb +13 -0
- data/spec/integration/git/stateful_repository_spec.rb +175 -0
- data/spec/integration/util/purageable_spec.rb +41 -0
- data/spec/matchers/exit_with.rb +28 -0
- data/spec/matchers/match_realpath.rb +18 -0
- data/spec/r10k-mocks/mock_config.rb +33 -0
- data/spec/r10k-mocks/mock_env.rb +18 -0
- data/spec/r10k-mocks/mock_source.rb +17 -0
- data/spec/r10k-mocks.rb +3 -0
- data/spec/shared-contexts/git-fixtures.rb +55 -0
- data/spec/shared-contexts/tarball.rb +32 -0
- data/spec/shared-examples/deploy-actions.rb +69 -0
- data/spec/shared-examples/git/bare_repository.rb +132 -0
- data/spec/shared-examples/git/thin_repository.rb +26 -0
- data/spec/shared-examples/git/working_repository.rb +207 -0
- data/spec/shared-examples/git-repository.rb +38 -0
- data/spec/shared-examples/puppetfile-action.rb +39 -0
- data/spec/shared-examples/settings/ancestry.rb +44 -0
- data/spec/shared-examples/subprocess-runner.rb +89 -0
- data/spec/spec_helper.rb +41 -0
- data/spec/unit/action/cri_runner_spec.rb +72 -0
- data/spec/unit/action/deploy/deploy_helpers_spec.rb +38 -0
- data/spec/unit/action/deploy/display_spec.rb +61 -0
- data/spec/unit/action/deploy/environment_spec.rb +640 -0
- data/spec/unit/action/deploy/module_spec.rb +476 -0
- data/spec/unit/action/puppetfile/check_spec.rb +53 -0
- data/spec/unit/action/puppetfile/cri_runner_spec.rb +47 -0
- data/spec/unit/action/puppetfile/install_spec.rb +112 -0
- data/spec/unit/action/puppetfile/purge_spec.rb +60 -0
- data/spec/unit/action/runner_spec.rb +407 -0
- data/spec/unit/action/visitor_spec.rb +39 -0
- data/spec/unit/cli_spec.rb +9 -0
- data/spec/unit/deployment/config_spec.rb +33 -0
- data/spec/unit/deployment_spec.rb +162 -0
- data/spec/unit/environment/bare_spec.rb +13 -0
- data/spec/unit/environment/base_spec.rb +122 -0
- data/spec/unit/environment/git_spec.rb +114 -0
- data/spec/unit/environment/name_spec.rb +181 -0
- data/spec/unit/environment/plain_spec.rb +8 -0
- data/spec/unit/environment/svn_spec.rb +146 -0
- data/spec/unit/environment/tarball_spec.rb +45 -0
- data/spec/unit/environment/with_modules_spec.rb +122 -0
- data/spec/unit/errors/formatting_spec.rb +84 -0
- data/spec/unit/feature_spec.rb +50 -0
- data/spec/unit/forge/module_release_spec.rb +213 -0
- data/spec/unit/git/alternates_spec.rb +116 -0
- data/spec/unit/git/cache_spec.rb +66 -0
- data/spec/unit/git/rugged/cache_spec.rb +48 -0
- data/spec/unit/git/rugged/credentials_spec.rb +215 -0
- data/spec/unit/git/shellgit/cache_spec.rb +27 -0
- data/spec/unit/git/stateful_repository_spec.rb +45 -0
- data/spec/unit/git_spec.rb +102 -0
- data/spec/unit/initializers_spec.rb +68 -0
- data/spec/unit/instance_cache_spec.rb +78 -0
- data/spec/unit/keyed_factory_spec.rb +51 -0
- data/spec/unit/logging/terminaloutputter_spec.rb +53 -0
- data/spec/unit/logging_spec.rb +68 -0
- data/spec/unit/module/base_spec.rb +118 -0
- data/spec/unit/module/forge_spec.rb +271 -0
- data/spec/unit/module/git_spec.rb +387 -0
- data/spec/unit/module/metadata_file_spec.rb +68 -0
- data/spec/unit/module/svn_spec.rb +208 -0
- data/spec/unit/module/tarball_spec.rb +70 -0
- data/spec/unit/module_loader/puppetfile_spec.rb +421 -0
- data/spec/unit/module_spec.rb +114 -0
- data/spec/unit/puppetfile_spec.rb +304 -0
- data/spec/unit/settings/collection_spec.rb +123 -0
- data/spec/unit/settings/container_spec.rb +92 -0
- data/spec/unit/settings/definition_spec.rb +79 -0
- data/spec/unit/settings/enum_definition_spec.rb +20 -0
- data/spec/unit/settings/inheritance_spec.rb +38 -0
- data/spec/unit/settings/list_spec.rb +88 -0
- data/spec/unit/settings/loader_spec.rb +110 -0
- data/spec/unit/settings/uri_definition_spec.rb +23 -0
- data/spec/unit/settings_spec.rb +303 -0
- data/spec/unit/source/base_spec.rb +31 -0
- data/spec/unit/source/exec_spec.rb +81 -0
- data/spec/unit/source/git_spec.rb +233 -0
- data/spec/unit/source/hash_spec.rb +54 -0
- data/spec/unit/source/svn_spec.rb +196 -0
- data/spec/unit/source/yaml_spec.rb +42 -0
- data/spec/unit/source_spec.rb +10 -0
- data/spec/unit/svn/remote_spec.rb +21 -0
- data/spec/unit/svn/working_dir_spec.rb +56 -0
- data/spec/unit/tarball_spec.rb +57 -0
- data/spec/unit/util/attempt_spec.rb +82 -0
- data/spec/unit/util/cacheable_spec.rb +23 -0
- data/spec/unit/util/commands_spec.rb +61 -0
- data/spec/unit/util/downloader_spec.rb +98 -0
- data/spec/unit/util/exec_env_spec.rb +56 -0
- data/spec/unit/util/purgeable_spec.rb +267 -0
- data/spec/unit/util/setopts_spec.rb +83 -0
- data/spec/unit/util/subprocess/result_spec.rb +36 -0
- data/spec/unit/util/subprocess/runner/posix_spec.rb +7 -0
- data/spec/unit/util/subprocess/runner/pump_spec.rb +79 -0
- data/spec/unit/util/subprocess/runner/windows_spec.rb +7 -0
- data/spec/unit/util/subprocess/subprocess_error_spec.rb +26 -0
- data/spec/unit/util/subprocess_spec.rb +65 -0
- data/spec/unit/util/symbolize_keys_spec.rb +67 -0
- metadata +637 -0
data/lib/r10k/tarball.rb
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'find'
|
3
|
+
require 'minitar'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'uri'
|
6
|
+
require 'zlib'
|
7
|
+
require 'r10k/settings'
|
8
|
+
require 'r10k/settings/mixin'
|
9
|
+
require 'r10k/util/platform'
|
10
|
+
require 'r10k/util/cacheable'
|
11
|
+
require 'r10k/util/downloader'
|
12
|
+
|
13
|
+
module R10K
|
14
|
+
class Tarball
|
15
|
+
|
16
|
+
include R10K::Settings::Mixin
|
17
|
+
include R10K::Util::Cacheable
|
18
|
+
include R10K::Util::Downloader
|
19
|
+
|
20
|
+
def_setting_attr :proxy # Defaults to global proxy setting
|
21
|
+
def_setting_attr :cache_root, R10K::Util::Cacheable.default_cachedir
|
22
|
+
|
23
|
+
# @!attribute [rw] name
|
24
|
+
# @return [String] The tarball's name
|
25
|
+
attr_accessor :name
|
26
|
+
|
27
|
+
# @!attribute [rw] source
|
28
|
+
# @return [String] The tarball's source
|
29
|
+
attr_accessor :source
|
30
|
+
|
31
|
+
# @!attribute [rw] checksum
|
32
|
+
# @return [String] The tarball's expected sha256 digest
|
33
|
+
attr_accessor :checksum
|
34
|
+
|
35
|
+
# @param name [String] The name of the tarball content
|
36
|
+
# @param source [String] The source for the tarball content
|
37
|
+
# @param checksum [String] The sha256 digest of the tarball content
|
38
|
+
def initialize(name, source, checksum: nil)
|
39
|
+
@name = name
|
40
|
+
@source = source
|
41
|
+
@checksum = checksum
|
42
|
+
|
43
|
+
# At this time, the only checksum type supported is sha256. In the future,
|
44
|
+
# we may decide to support other algorithms if a use case arises. TBD.
|
45
|
+
checksum_algorithm = :SHA256
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [String] Directory. Where the cache_basename file will be created.
|
49
|
+
def cache_dirname
|
50
|
+
File.join(settings[:cache_root], 'tarball')
|
51
|
+
end
|
52
|
+
|
53
|
+
# The final cache_path should match one of the templates:
|
54
|
+
#
|
55
|
+
# - {cachedir}/{checksum}.tar.gz
|
56
|
+
# - {cachedir}/{source}.tar.gz
|
57
|
+
#
|
58
|
+
# @return [String] File. The full file path the tarball will be cached to.
|
59
|
+
def cache_path
|
60
|
+
File.join(cache_dirname, cache_basename)
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [String] The basename of the tarball cache file.
|
64
|
+
def cache_basename
|
65
|
+
if checksum.nil?
|
66
|
+
sanitized_dirname(source) + '.tar.gz'
|
67
|
+
else
|
68
|
+
checksum + '.tar.gz'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Extract the cached tarball to the target directory.
|
73
|
+
#
|
74
|
+
# @param target_dir [String] Where to unpack the tarball
|
75
|
+
def unpack(target_dir)
|
76
|
+
file = File.open(cache_path, 'rb')
|
77
|
+
reader = Zlib::GzipReader.new(file)
|
78
|
+
begin
|
79
|
+
Minitar.unpack(reader, target_dir)
|
80
|
+
ensure
|
81
|
+
reader.close
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# @param target_dir [String] The directory to check if is in sync with the
|
86
|
+
# tarball content
|
87
|
+
# @param ignore_untracked_files [Boolean] If true, consider the target
|
88
|
+
# dir to be in sync as long as all tracked content matches.
|
89
|
+
#
|
90
|
+
# @return [Boolean]
|
91
|
+
def insync?(target_dir, ignore_untracked_files: false)
|
92
|
+
target_tree_entries = Find.find(target_dir).map(&:to_s) - [target_dir]
|
93
|
+
each_tarball_entry do |entry|
|
94
|
+
found = target_tree_entries.delete(File.join(target_dir, entry.full_name.chomp('/')))
|
95
|
+
return false if found.nil?
|
96
|
+
next if entry.directory?
|
97
|
+
return false unless file_digest(found) == reader_digest(entry)
|
98
|
+
end
|
99
|
+
|
100
|
+
if ignore_untracked_files
|
101
|
+
# We wouldn't have gotten this far if there were discrepancies in
|
102
|
+
# tracked content
|
103
|
+
true
|
104
|
+
else
|
105
|
+
# If there are still files in target_tree_entries, then there is
|
106
|
+
# untracked content present in the target tree. If not, we're in sync.
|
107
|
+
target_tree_entries.empty?
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Download the tarball from @source to @cache_path
|
112
|
+
def get
|
113
|
+
Tempfile.open(cache_basename) do |tempfile|
|
114
|
+
tempfile.binmode
|
115
|
+
src_uri = URI.parse(source)
|
116
|
+
|
117
|
+
temp_digest = case src_uri.scheme
|
118
|
+
when 'file', nil
|
119
|
+
copy(src_uri.path, tempfile)
|
120
|
+
when %r{^[a-z]$} # Windows drive letter
|
121
|
+
copy(src_uri.to_s, tempfile)
|
122
|
+
when %r{^https?$}
|
123
|
+
download(src_uri, tempfile)
|
124
|
+
else
|
125
|
+
raise "Unexpected source scheme #{src_uri.scheme}"
|
126
|
+
end
|
127
|
+
|
128
|
+
# Verify the download
|
129
|
+
unless (checksum == temp_digest) || checksum.nil?
|
130
|
+
raise 'Downloaded file does not match checksum'
|
131
|
+
end
|
132
|
+
|
133
|
+
# Move the download to cache_path
|
134
|
+
FileUtils::mkdir_p(cache_dirname)
|
135
|
+
begin
|
136
|
+
FileUtils.mv(tempfile.path, cache_path)
|
137
|
+
rescue Errno::EACCES
|
138
|
+
# It may be the case that permissions don't permit moving the file
|
139
|
+
# into place, but do permit overwriting an existing in-place file.
|
140
|
+
FileUtils.cp(tempfile.path, cache_path)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# Checks the cached tarball's digest against the expected checksum. Returns
|
146
|
+
# false if no cached file is present. If the tarball has no expected
|
147
|
+
# checksum, any cached file is assumed to be valid.
|
148
|
+
#
|
149
|
+
# @return [Boolean]
|
150
|
+
def cache_valid?
|
151
|
+
return false unless File.exist?(cache_path)
|
152
|
+
return true if checksum.nil?
|
153
|
+
checksum == file_digest(cache_path)
|
154
|
+
end
|
155
|
+
|
156
|
+
# List all of the files contained in the tarball and their paths. This is
|
157
|
+
# useful for implementing R10K::Purgable
|
158
|
+
#
|
159
|
+
# @return [Array] A normalized list of file paths contained in the archive
|
160
|
+
def paths
|
161
|
+
names = Array.new
|
162
|
+
each_tarball_entry { |entry| names << Pathname.new(entry).cleanpath.to_s }
|
163
|
+
names - ['.']
|
164
|
+
end
|
165
|
+
|
166
|
+
def cache_checksum
|
167
|
+
raise R10K::Error, _("Cache not present at %{path}") % {path: cache_path} unless File.exist?(cache_path)
|
168
|
+
file_digest(cache_path)
|
169
|
+
end
|
170
|
+
|
171
|
+
private
|
172
|
+
|
173
|
+
def each_tarball_entry(&block)
|
174
|
+
File.open(cache_path, 'rb') do |file|
|
175
|
+
Zlib::GzipReader.wrap(file) do |reader|
|
176
|
+
Archive::Tar::Minitar::Input.each_entry(reader) do |entry|
|
177
|
+
yield entry
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'r10k/logging'
|
2
|
+
require 'r10k/errors/formatting'
|
3
|
+
require 'r10k/util/setopts'
|
4
|
+
require 'colored2'
|
5
|
+
|
6
|
+
module R10K
|
7
|
+
module Util
|
8
|
+
|
9
|
+
# Attempt a series of dependent nested tasks and cleanly handle errors.
|
10
|
+
#
|
11
|
+
# @api private
|
12
|
+
class Attempt
|
13
|
+
|
14
|
+
include R10K::Logging
|
15
|
+
include R10K::Util::Setopts
|
16
|
+
|
17
|
+
# @!attribute [r] status
|
18
|
+
# @return [Symbol] The status of this task
|
19
|
+
attr_reader :status
|
20
|
+
|
21
|
+
def initialize(initial, opts = {})
|
22
|
+
@initial = initial
|
23
|
+
@tries = []
|
24
|
+
@status = :notrun
|
25
|
+
setopts(opts, {:trace => :self})
|
26
|
+
end
|
27
|
+
|
28
|
+
# Run this attempt to completion.
|
29
|
+
#
|
30
|
+
# @todo determine the structure of the ret
|
31
|
+
# @return [Object] The aggregate result of all work performed.
|
32
|
+
def run
|
33
|
+
@status = :running
|
34
|
+
result = apply(@initial, @tries)
|
35
|
+
@status = :ok if @status == :running
|
36
|
+
result
|
37
|
+
end
|
38
|
+
|
39
|
+
# Add another action to take for this attempt
|
40
|
+
#
|
41
|
+
# @yieldparam [Object] The result of the previous action.
|
42
|
+
# @yieldreturn [Object, Array<Object>, NilClass] The result of this action.
|
43
|
+
# If the value is an object, it will be passed to the next attempt. If
|
44
|
+
# the value is an Array then each element will be individually passed
|
45
|
+
# to the next try. If the value is false or nil then no further action
|
46
|
+
# will be taken.
|
47
|
+
def try(&block)
|
48
|
+
@tries << block
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def ok?
|
53
|
+
@status == :ok
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def apply(input, tries)
|
59
|
+
return input if tries.empty?
|
60
|
+
|
61
|
+
case input
|
62
|
+
when Array
|
63
|
+
apply_all(input, tries)
|
64
|
+
when NilClass, FalseClass
|
65
|
+
input
|
66
|
+
else
|
67
|
+
apply_one(input, tries)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def apply_all(values, tries)
|
72
|
+
values.map { |v| apply_one(v, tries) }
|
73
|
+
end
|
74
|
+
|
75
|
+
def apply_one(value, tries)
|
76
|
+
apply(tries.first.call(value), tries.drop(1))
|
77
|
+
rescue => e
|
78
|
+
@status = :failed
|
79
|
+
logger.error R10K::Errors::Formatting.format_exception(e, @trace)
|
80
|
+
e
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'r10k/deployment'
|
2
|
+
require 'r10k/logging'
|
3
|
+
require 'r10k/util/purgeable'
|
4
|
+
|
5
|
+
module R10K
|
6
|
+
module Util
|
7
|
+
|
8
|
+
# Represents a directory that can purge unmanaged contents
|
9
|
+
#
|
10
|
+
# @todo pick a better name than basedir. Expect this class to be renamed.
|
11
|
+
#
|
12
|
+
# @api private
|
13
|
+
class Basedir
|
14
|
+
|
15
|
+
include R10K::Util::Purgeable
|
16
|
+
include R10K::Logging
|
17
|
+
|
18
|
+
# Create a new Basedir by selecting sources from a deployment that match
|
19
|
+
# the specified path.
|
20
|
+
#
|
21
|
+
# @param path [String]
|
22
|
+
# @param deployment [R10K::Deployment]
|
23
|
+
#
|
24
|
+
# @return [R10K::Util::Basedir]
|
25
|
+
def self.from_deployment(path, deployment)
|
26
|
+
sources = deployment.sources.select { |source| source.managed_directory == path }
|
27
|
+
new(path, sources)
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param path [String] The path to the directory to manage
|
31
|
+
# @param sources [Array<#desired_contents>] A list of objects that may create filesystem entries
|
32
|
+
def initialize(path, sources)
|
33
|
+
if sources.is_a? R10K::Deployment
|
34
|
+
raise ArgumentError, _("Expected Array<#desired_contents>, got R10K::Deployment")
|
35
|
+
end
|
36
|
+
@path = path
|
37
|
+
@sources = sources
|
38
|
+
end
|
39
|
+
|
40
|
+
# Return the path of the basedir
|
41
|
+
# @note This implements a required method for the Purgeable mixin
|
42
|
+
# @return [Array]
|
43
|
+
def managed_directories
|
44
|
+
[@path]
|
45
|
+
end
|
46
|
+
|
47
|
+
# List all environments that should exist in this basedir
|
48
|
+
# @note This implements a required method for the Purgeable mixin
|
49
|
+
# @return [Array<String>]
|
50
|
+
def desired_contents
|
51
|
+
@sources.flat_map do |src|
|
52
|
+
src.desired_contents.collect { |env| File.join(@path, env) }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def purge!
|
57
|
+
@sources.each do |source|
|
58
|
+
logger.debug1 _("Source %{source_name} in %{path} manages contents %{contents}") % {source_name: source.name, path: @path, contents: source.desired_contents.inspect}
|
59
|
+
end
|
60
|
+
|
61
|
+
super
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module R10K
|
2
|
+
module Util
|
3
|
+
|
4
|
+
# Utility mixin for classes that need to implement caches
|
5
|
+
#
|
6
|
+
# @abstract Classes using this mixin need to implement {#managed_directory} and
|
7
|
+
# {#desired_contents}
|
8
|
+
module Cacheable
|
9
|
+
|
10
|
+
# Provide a default cachedir location. This is consumed by R10K::Settings
|
11
|
+
# for appropriate global default values.
|
12
|
+
#
|
13
|
+
# @return [String] Path to the default cache directory
|
14
|
+
def self.default_cachedir(basename = 'cache')
|
15
|
+
if R10K::Util::Platform.windows?
|
16
|
+
File.join(ENV['LOCALAPPDATA'], 'r10k', basename)
|
17
|
+
else
|
18
|
+
File.join(ENV['HOME'] || '/root', '.r10k', basename)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Reformat a string into something that can be used as a directory
|
23
|
+
#
|
24
|
+
# @param string [String] An identifier to create a sanitized dirname for
|
25
|
+
# @return [String] A sanitized dirname for the given string
|
26
|
+
def sanitized_dirname(string)
|
27
|
+
string.gsub(/(\w+:\/\/)(.*)(@)/, '\1').gsub(/[^@\w\.-]/, '-')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'r10k/logging'
|
2
|
+
require 'r10k/util/purgeable'
|
3
|
+
|
4
|
+
module R10K
|
5
|
+
module Util
|
6
|
+
class Cleaner
|
7
|
+
|
8
|
+
include R10K::Logging
|
9
|
+
include R10K::Util::Purgeable
|
10
|
+
|
11
|
+
attr_reader :managed_directories, :desired_contents, :purge_exclusions
|
12
|
+
|
13
|
+
def initialize(managed_directories, desired_contents, purge_exclusions = [])
|
14
|
+
@managed_directories = managed_directories
|
15
|
+
@desired_contents = desired_contents
|
16
|
+
@purge_exclusions = purge_exclusions
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module R10K
|
2
|
+
module Util
|
3
|
+
module Commands
|
4
|
+
module_function
|
5
|
+
|
6
|
+
# Find the full path of a shell command.
|
7
|
+
#
|
8
|
+
# On POSIX platforms, the PATHEXT environment variable will be unset, so
|
9
|
+
# the first command named 'cmd' will be returned.
|
10
|
+
#
|
11
|
+
# On Windows platforms, the PATHEXT environment variable will contain a
|
12
|
+
# semicolon delimited list of executable file extensions, so the first
|
13
|
+
# command with a matching path extension will be returned.
|
14
|
+
#
|
15
|
+
# @param cmd [String] The name of the command to search for
|
16
|
+
# @return [String, nil] The path to the file if found, nil otherwise
|
17
|
+
def which(cmd)
|
18
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
19
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |dir|
|
20
|
+
exts.each do |ext|
|
21
|
+
path = File.join(dir, "#{cmd}#{ext}")
|
22
|
+
if File.executable?(path) && File.file?(path)
|
23
|
+
return path
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'digest'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module R10K
|
5
|
+
module Util
|
6
|
+
|
7
|
+
# Utility mixin for classes that need to download files
|
8
|
+
module Downloader
|
9
|
+
|
10
|
+
# Downloader objects need to checksum downloaded or saved content. The
|
11
|
+
# algorithm used to perform this checksumming (and therefore the kinds of
|
12
|
+
# checksums returned by various methods) is reported by this method.
|
13
|
+
#
|
14
|
+
# @return [Symbol] The checksum algorithm the downloader uses
|
15
|
+
def checksum_algorithm
|
16
|
+
@checksum_algorithm ||= :SHA256
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# Set the checksum algorithm the downloader should use. It should be a
|
22
|
+
# symbol, and a valid Ruby 'digest' library algorithm. The default is
|
23
|
+
# :SHA256.
|
24
|
+
#
|
25
|
+
# @param algorithm [Symbol] The checksum algorithm the downloader should use
|
26
|
+
def checksum_algorithm=(algorithm)
|
27
|
+
@checksum_algorithm = algorithm
|
28
|
+
end
|
29
|
+
|
30
|
+
CHUNK_SIZE = 64 * 1024 # 64 kb
|
31
|
+
|
32
|
+
# @param src_uri [URI] The URI to download from
|
33
|
+
# @param dst_file [String] The file or path to save to
|
34
|
+
# @return [String] The downloaded file's hex digest
|
35
|
+
def download(src_uri, dst_file)
|
36
|
+
digest = Digest(checksum_algorithm).new
|
37
|
+
http_get(src_uri) do |resp|
|
38
|
+
File.open(dst_file, 'wb') do |output_stream|
|
39
|
+
resp.read_body do |chunk|
|
40
|
+
output_stream.write(chunk)
|
41
|
+
digest.update(chunk)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
digest.hexdigest
|
47
|
+
end
|
48
|
+
|
49
|
+
# @param src_file The file or path to copy from
|
50
|
+
# @param dst_file The file or path to copy to
|
51
|
+
# @return [String] The copied file's sha256 hex digest
|
52
|
+
def copy(src_file, dst_file)
|
53
|
+
digest = Digest(checksum_algorithm).new
|
54
|
+
File.open(src_file, 'rb') do |input_stream|
|
55
|
+
File.open(dst_file, 'wb') do |output_stream|
|
56
|
+
until input_stream.eof?
|
57
|
+
chunk = input_stream.read(CHUNK_SIZE)
|
58
|
+
output_stream.write(chunk)
|
59
|
+
digest.update(chunk)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
digest.hexdigest
|
65
|
+
end
|
66
|
+
|
67
|
+
# Start a Net::HTTP::Get connection, then yield the Net::HTTPSuccess object
|
68
|
+
# to the caller's block. Follow redirects if Net::HTTPRedirection responses
|
69
|
+
# are encountered, and use a proxy if directed.
|
70
|
+
#
|
71
|
+
# @param uri [URI] The URI to download the file from
|
72
|
+
# @param redirect_limit [Integer] How many redirects to permit before failing
|
73
|
+
# @param proxy [URI, String] The URI to use as a proxy
|
74
|
+
def http_get(uri, redirect_limit: 10, proxy: nil, &block)
|
75
|
+
raise "HTTP redirect too deep" if redirect_limit.zero?
|
76
|
+
|
77
|
+
session = Net::HTTP.new(uri.host, uri.port, *proxy_to_array(proxy))
|
78
|
+
session.use_ssl = true if uri.scheme == 'https'
|
79
|
+
session.start
|
80
|
+
|
81
|
+
begin
|
82
|
+
session.request_get(uri) do |response|
|
83
|
+
case response
|
84
|
+
when Net::HTTPRedirection
|
85
|
+
redirect = response['location']
|
86
|
+
session.finish
|
87
|
+
return http_get(URI.parse(redirect), redirect_limit: redirect_limit - 1, proxy: proxy, &block)
|
88
|
+
when Net::HTTPSuccess
|
89
|
+
yield response
|
90
|
+
else
|
91
|
+
raise "Unexpected response code #{response.code}: #{response}"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
ensure
|
95
|
+
session.finish if session.active?
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# Helper method to translate a proxy URI to array arguments for
|
100
|
+
# Net::HTTP#new. A nil argument returns nil array elements.
|
101
|
+
def proxy_to_array(proxy_uri)
|
102
|
+
if proxy_uri
|
103
|
+
px = proxy_uri.is_a?(URI) ? proxy_uri : URI.parse(proxy_uri)
|
104
|
+
[px.host, px.port, px.user, px.password]
|
105
|
+
else
|
106
|
+
[nil, nil, nil, nil]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Return the sha256 digest of the file at the given path
|
111
|
+
#
|
112
|
+
# @param path [String] The path to the file
|
113
|
+
# @return [String] The file's sha256 hex digest
|
114
|
+
def file_digest(path)
|
115
|
+
File.open(path) do |file|
|
116
|
+
reader_digest(file)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Return the sha256 digest of the readable data
|
121
|
+
#
|
122
|
+
# @param reader [String] An object that responds to #read
|
123
|
+
# @return [String] The read data's sha256 hex digest
|
124
|
+
def reader_digest(reader)
|
125
|
+
digest = Digest(checksum_algorithm).new
|
126
|
+
while chunk = reader.read(CHUNK_SIZE)
|
127
|
+
digest.update(chunk)
|
128
|
+
end
|
129
|
+
|
130
|
+
digest.hexdigest
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module R10K
|
2
|
+
module Util
|
3
|
+
|
4
|
+
# Utility methods for dealing with environment variables
|
5
|
+
module ExecEnv
|
6
|
+
module_function
|
7
|
+
|
8
|
+
# Swap out all environment settings
|
9
|
+
#
|
10
|
+
# @param env [Hash] The new environment to use
|
11
|
+
# @return [void]
|
12
|
+
def reset(env)
|
13
|
+
env.each_pair do |key, value|
|
14
|
+
ENV[key] = value
|
15
|
+
end
|
16
|
+
|
17
|
+
(ENV.keys - env.keys).each do |key|
|
18
|
+
ENV.delete(key)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Add the specified settings to the env for the supplied block
|
23
|
+
#
|
24
|
+
# @param env [Hash] The values to add to the environment
|
25
|
+
# @param block [Proc] The code to call with the modified environnment
|
26
|
+
# @return [void]
|
27
|
+
def withenv(env, &block)
|
28
|
+
original = ENV.to_hash
|
29
|
+
reset(original.merge(env))
|
30
|
+
block.call
|
31
|
+
ensure
|
32
|
+
reset(original)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'r10k/errors'
|
2
|
+
require 'r10k/features'
|
3
|
+
|
4
|
+
module R10K
|
5
|
+
module Util
|
6
|
+
module License
|
7
|
+
extend R10K::Logging
|
8
|
+
|
9
|
+
def self.load
|
10
|
+
if R10K::Features.available?(:pe_license)
|
11
|
+
logger.debug2 _("pe_license feature is available, loading PE license key")
|
12
|
+
begin
|
13
|
+
return PELicense.load_license_key
|
14
|
+
rescue PELicense::InvalidLicenseError => e
|
15
|
+
raise R10K::Error.wrap(e, _("Invalid PE license detected: %{error_msg}") % {error_msg: e.message} )
|
16
|
+
end
|
17
|
+
else
|
18
|
+
logger.debug2 _("pe_license feature is not available, PE only Puppet modules will not be downloadable.")
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
|
3
|
+
module R10K
|
4
|
+
module Util
|
5
|
+
module Platform
|
6
|
+
FIPS_FILE = "/proc/sys/crypto/fips_enabled"
|
7
|
+
|
8
|
+
def self.platform
|
9
|
+
# Test JRuby first to handle JRuby on Windows as well.
|
10
|
+
if self.jruby?
|
11
|
+
:jruby
|
12
|
+
elsif self.windows?
|
13
|
+
:windows
|
14
|
+
else
|
15
|
+
:posix
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# We currently only suport FIPS mode on redhat 7, where it is
|
20
|
+
# toggled via a file.
|
21
|
+
def self.fips?
|
22
|
+
if File.exist?(FIPS_FILE)
|
23
|
+
File.read(FIPS_FILE).chomp == "1"
|
24
|
+
else
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.windows?
|
30
|
+
RbConfig::CONFIG['host_os'] =~ /mswin|win32|dos|mingw|cygwin/i
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.jruby?
|
34
|
+
RUBY_PLATFORM == "java"
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.posix?
|
38
|
+
!windows? && !jruby?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|