r10k 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. checksums.yaml +8 -8
  2. data/CHANGELOG.mkd +150 -0
  3. data/README.mkd +10 -1
  4. data/doc/dynamic-environments/configuration.mkd +31 -0
  5. data/doc/dynamic-environments/quickstart.mkd +33 -79
  6. data/doc/faq.mkd +67 -0
  7. data/doc/git/providers.mkd +37 -0
  8. data/doc/puppetfile.mkd +73 -0
  9. data/integration/lib/r10k_utils.rb +47 -2
  10. data/integration/pre-suite/01_git_config.rb +9 -8
  11. data/integration/pre-suite/02_pe_r10k.rb +5 -8
  12. data/integration/scripts/setup_r10k_env_centos5.sh +1 -1
  13. data/integration/scripts/setup_r10k_env_centos6.sh +1 -1
  14. data/integration/scripts/setup_r10k_env_rhel7.sh +1 -1
  15. data/integration/scripts/setup_r10k_env_sles11.sh +1 -1
  16. data/integration/scripts/setup_r10k_env_sles12.sh +1 -1
  17. data/integration/scripts/setup_r10k_env_ubuntu1004.sh +1 -1
  18. data/integration/scripts/setup_r10k_env_ubuntu1204.sh +1 -1
  19. data/integration/scripts/setup_r10k_env_ubuntu1404.sh +1 -1
  20. data/integration/test_run_scripts/all_tests-rugged-pe-centos6.sh +1 -1
  21. data/integration/test_run_scripts/all_tests-rugged-pe-rhel7.sh +1 -1
  22. data/integration/test_run_scripts/all_tests-rugged-pe-sles11.sh +1 -1
  23. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1204.sh +1 -1
  24. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1404.sh +1 -1
  25. data/integration/test_run_scripts/all_tests-shellgit-pe-centos6.sh +1 -1
  26. data/integration/test_run_scripts/all_tests-shellgit-pe-rhel7.sh +1 -1
  27. data/integration/test_run_scripts/all_tests-shellgit-pe-sles11.sh +1 -1
  28. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1204.sh +1 -1
  29. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1404.sh +1 -1
  30. data/integration/test_run_scripts/basic_functionality/all_tests-pe-centos6.sh +1 -1
  31. data/integration/test_run_scripts/command_line/all_tests-pe-centos6.sh +1 -1
  32. data/integration/test_run_scripts/git_source/all_tests-pe-centos6.sh +1 -1
  33. data/integration/test_run_scripts/user_scenario/basic_workflow/all_tests-pe-centos6.sh +1 -1
  34. data/integration/test_run_scripts/user_scenario/complex_workflow/all_tests-pe-centos6.sh +1 -1
  35. data/integration/tests/basic_functionality/install_pe_only_module_with_puppetfile.rb +83 -0
  36. data/integration/tests/basic_functionality/negative/attempt_to_install_peonly_module_without_license.rb +71 -0
  37. data/integration/tests/basic_functionality/negative/neg_deploy_with_invalid_r10k_yaml.rb +7 -2
  38. data/integration/tests/basic_functionality/negative/neg_deploy_with_missing_r10k_yaml.rb +3 -2
  39. data/integration/tests/basic_functionality/negative/neg_invalid_git_provider.rb +3 -2
  40. data/integration/tests/basic_functionality/negative/negative_bad_proxy.rb +56 -0
  41. data/integration/tests/basic_functionality/proxy_specified_in_configuration.rb +103 -0
  42. data/integration/tests/basic_functionality/proxy_with_puppetfile.rb +61 -0
  43. data/integration/tests/basic_functionality/rugged_git_provider_with_ssh.rb +2 -1
  44. data/integration/tests/basic_functionality/rugged_git_provider_without_ssh.rb +2 -1
  45. data/integration/tests/command_line/deploy_env_without_mod_update.rb +3 -2
  46. data/integration/tests/command_line/negative/neg_deploy_env_with_module_update.rb +3 -2
  47. data/integration/tests/command_line/negative/neg_invalid_cli_dep_flag.rb +2 -1
  48. data/integration/tests/command_line/negative/neg_invalid_cli_env_flag.rb +2 -1
  49. data/integration/tests/command_line/negative/neg_invalid_cmd_line_arg.rb +3 -4
  50. data/integration/tests/git_source/git_source_git.rb +7 -2
  51. data/integration/tests/git_source/git_source_ssh.rb +3 -2
  52. data/integration/tests/git_source/git_source_submodule.rb +2 -1
  53. data/integration/tests/git_source/negative/neg_git_broken_remote.rb +2 -1
  54. data/integration/tests/git_source/negative/neg_git_unauthorized_https.rb +2 -1
  55. data/integration/tests/git_source/negative/neg_git_unauthorized_ssh.rb +2 -1
  56. data/integration/tests/git_source/negative/neg_git_unicode_branch.rb +2 -1
  57. data/integration/tests/user_scenario/basic_workflow/multi_env_1000_branches.rb +3 -3
  58. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +2 -1
  59. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +9 -5
  60. data/integration/tests/user_scenario/basic_workflow/multi_env_hiera.rb +9 -2
  61. data/integration/tests/user_scenario/basic_workflow/multi_env_multi_source.rb +2 -1
  62. data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +2 -1
  63. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_basedir.rb +2 -1
  64. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_forge_module.rb +7 -2
  65. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module.rb +3 -4
  66. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +2 -1
  67. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_remote.rb +2 -1
  68. data/integration/tests/user_scenario/basic_workflow/negative/neg_branch_name_collision.rb +2 -1
  69. data/integration/tests/user_scenario/basic_workflow/negative/neg_disk_full.rb +2 -1
  70. data/integration/tests/user_scenario/basic_workflow/negative/neg_duplicate_module_names.rb +10 -4
  71. data/integration/tests/user_scenario/basic_workflow/negative/neg_inaccessible_forge.rb +9 -2
  72. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_env_name.rb +2 -1
  73. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_puppet_file.rb +2 -1
  74. data/integration/tests/user_scenario/basic_workflow/negative/neg_module_specified_at_deleted_release.rb +7 -2
  75. data/integration/tests/user_scenario/basic_workflow/negative/neg_read_only.rb +2 -1
  76. data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +9 -2
  77. data/integration/tests/user_scenario/basic_workflow/single_env_10000_files.rb +2 -1
  78. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +2 -1
  79. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_module.rb +2 -1
  80. data/integration/tests/user_scenario/basic_workflow/single_env_custom_module.rb +2 -1
  81. data/integration/tests/user_scenario/basic_workflow/single_env_large_files.rb +2 -1
  82. data/integration/tests/user_scenario/basic_workflow/single_env_module_already_installed.rb +2 -1
  83. data/integration/tests/user_scenario/basic_workflow/single_env_module_last_release_deleted.rb +2 -1
  84. data/integration/tests/user_scenario/basic_workflow/single_env_non-existent_base_dir.rb +2 -1
  85. data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +3 -2
  86. data/integration/tests/user_scenario/basic_workflow/single_env_switch_forge_git_module.rb +3 -2
  87. data/integration/tests/user_scenario/basic_workflow/single_env_unicode_paths.rb +2 -1
  88. data/integration/tests/user_scenario/basic_workflow/single_env_upgrade_forge_mod_revert_change.rb +4 -3
  89. data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +3 -2
  90. data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +4 -3
  91. data/integration/tests/user_scenario/complex_workflow/multi_env_unamanaged.rb +3 -2
  92. data/integration/tests/user_scenario/complex_workflow/single_env_git_module_update.rb +3 -2
  93. data/lib/r10k/action/base.rb +31 -0
  94. data/lib/r10k/action/deploy/deploy_helpers.rb +34 -0
  95. data/lib/r10k/action/deploy/display.rb +57 -75
  96. data/lib/r10k/action/deploy/environment.rb +52 -15
  97. data/lib/r10k/action/deploy/module.rb +13 -18
  98. data/lib/r10k/action/puppetfile/check.rb +8 -18
  99. data/lib/r10k/action/puppetfile/install.rb +13 -27
  100. data/lib/r10k/action/puppetfile/purge.rb +8 -17
  101. data/lib/r10k/action/runner.rb +39 -3
  102. data/lib/r10k/cli.rb +1 -3
  103. data/lib/r10k/cli/deploy.rb +3 -1
  104. data/lib/r10k/cli/puppetfile.rb +2 -2
  105. data/lib/r10k/deployment.rb +8 -6
  106. data/lib/r10k/deployment/config.rb +18 -65
  107. data/lib/r10k/environment/base.rb +19 -0
  108. data/lib/r10k/environment/git.rb +9 -0
  109. data/lib/r10k/environment/svn.rb +9 -0
  110. data/lib/r10k/forge/module_release.rb +21 -14
  111. data/lib/r10k/git.rb +6 -0
  112. data/lib/r10k/git/alternates.rb +20 -6
  113. data/lib/r10k/git/cache.rb +1 -1
  114. data/lib/r10k/git/rugged/bare_repository.rb +5 -0
  115. data/lib/r10k/git/rugged/base_repository.rb +6 -20
  116. data/lib/r10k/git/rugged/credentials.rb +66 -0
  117. data/lib/r10k/git/rugged/thin_repository.rb +16 -11
  118. data/lib/r10k/git/rugged/working_repository.rb +15 -7
  119. data/lib/r10k/git/shellgit/bare_repository.rb +9 -4
  120. data/lib/r10k/git/shellgit/thin_repository.rb +8 -10
  121. data/lib/r10k/git/stateful_repository.rb +1 -1
  122. data/lib/r10k/initializers.rb +55 -0
  123. data/lib/r10k/module.rb +1 -0
  124. data/lib/r10k/module/base.rb +3 -2
  125. data/lib/r10k/module/forge.rb +14 -6
  126. data/lib/r10k/module/local.rb +36 -0
  127. data/lib/r10k/module/metadata_file.rb +2 -2
  128. data/lib/r10k/puppetfile.rb +1 -1
  129. data/lib/r10k/settings.rb +86 -0
  130. data/lib/r10k/settings/collection.rb +118 -0
  131. data/lib/r10k/settings/definition.rb +112 -0
  132. data/lib/r10k/settings/enum_definition.rb +22 -0
  133. data/lib/r10k/settings/loader.rb +96 -0
  134. data/lib/r10k/settings/uri_definition.rb +19 -0
  135. data/lib/r10k/util/subprocess/runner/windows.rb +4 -4
  136. data/lib/r10k/version.rb +1 -1
  137. data/r10k.gemspec +2 -3
  138. data/spec/fixtures/unit/puppetfile/argument-error/Puppetfile +1 -0
  139. data/spec/fixtures/unit/util/subprocess/{posix/runner → runner}/no-execute.sh +0 -0
  140. data/spec/integration/git/rugged/thin_repository_spec.rb +2 -2
  141. data/spec/integration/git/rugged/working_repository_spec.rb +9 -0
  142. data/spec/integration/git/shellgit/thin_repository_spec.rb +2 -2
  143. data/spec/integration/git/stateful_repository_spec.rb +1 -1
  144. data/spec/r10k-mocks/mock_config.rb +10 -13
  145. data/spec/r10k-mocks/mock_env.rb +8 -0
  146. data/spec/shared-examples/deploy-actions.rb +69 -0
  147. data/spec/shared-examples/puppetfile-action.rb +17 -0
  148. data/spec/unit/action/cri_runner_spec.rb +3 -1
  149. data/spec/unit/action/deploy/deploy_helpers_spec.rb +38 -0
  150. data/spec/unit/action/deploy/display_spec.rb +31 -0
  151. data/spec/unit/action/deploy/environment_spec.rb +56 -0
  152. data/spec/unit/action/deploy/module_spec.rb +17 -0
  153. data/spec/unit/action/puppetfile/check_spec.rb +26 -0
  154. data/spec/unit/action/puppetfile/install_spec.rb +68 -0
  155. data/spec/unit/action/puppetfile/purge_spec.rb +19 -0
  156. data/spec/unit/action/runner_spec.rb +10 -9
  157. data/spec/unit/deployment/config_spec.rb +20 -44
  158. data/spec/unit/deployment_spec.rb +1 -1
  159. data/spec/unit/environment/git_spec.rb +20 -0
  160. data/spec/unit/environment/svn_spec.rb +20 -0
  161. data/spec/unit/forge/module_release_spec.rb +6 -3
  162. data/spec/unit/git/alternates_spec.rb +38 -12
  163. data/spec/unit/git/cache_spec.rb +4 -0
  164. data/spec/unit/git/rugged/credentials_spec.rb +74 -0
  165. data/spec/unit/initializers_spec.rb +68 -0
  166. data/spec/unit/module/base_spec.rb +2 -2
  167. data/spec/unit/module/forge_spec.rb +11 -3
  168. data/spec/unit/module/metadata_file_spec.rb +0 -1
  169. data/spec/unit/puppetfile_spec.rb +11 -0
  170. data/spec/unit/settings/collection_spec.rb +122 -0
  171. data/spec/unit/settings/definition_spec.rb +78 -0
  172. data/spec/unit/settings/enum_definition_spec.rb +20 -0
  173. data/spec/unit/{deployment/config → settings}/loader_spec.rb +50 -2
  174. data/spec/unit/settings/uri_definition_spec.rb +23 -0
  175. data/spec/unit/settings_spec.rb +151 -0
  176. data/spec/unit/util/subprocess/runner/posix_spec.rb +1 -1
  177. data/spec/unit/util/subprocess/runner/windows_spec.rb +7 -0
  178. metadata +53 -90
  179. data/lib/r10k/deployment/config/loader.rb +0 -59
  180. data/lib/shared/puppet/module_tool/metadata.rb +0 -197
  181. data/lib/shared/puppet_forge/connection.rb +0 -64
  182. data/lib/shared/puppet_forge/connection/connection_failure.rb +0 -26
  183. data/lib/shared/puppet_forge/error.rb +0 -41
  184. data/lib/shared/puppet_forge/tar.rb +0 -10
  185. data/lib/shared/puppet_forge/tar/mini.rb +0 -81
  186. data/lib/shared/puppet_forge/unpacker.rb +0 -68
  187. data/lib/shared/puppet_forge/v3.rb +0 -13
  188. data/lib/shared/puppet_forge/v3/module.rb +0 -69
  189. data/lib/shared/puppet_forge/v3/module_release.rb +0 -85
  190. data/lib/shared/puppet_forge/version.rb +0 -3
  191. data/spec/unit/puppet/module_tool/metadata_spec.rb +0 -301
  192. data/spec/unit/puppet_forge/connection/connection_failure_spec.rb +0 -28
  193. data/spec/unit/puppet_forge/connection_spec.rb +0 -41
  194. data/spec/unit/puppet_forge/tar/mini_spec.rb +0 -87
  195. data/spec/unit/puppet_forge/tar_spec.rb +0 -9
  196. data/spec/unit/puppet_forge/unpacker_spec.rb +0 -59
  197. data/spec/unit/puppet_forge/v3/module_release_spec.rb +0 -83
  198. data/spec/unit/puppet_forge/v3/module_spec.rb +0 -75
@@ -1,59 +0,0 @@
1
- require 'r10k/logging'
2
-
3
- module R10K
4
- class Deployment
5
- class Config
6
- class Loader
7
-
8
- include R10K::Logging
9
-
10
- attr_reader :loadpath
11
-
12
- CONFIG_FILE = 'r10k.yaml'
13
- DEFAULT_LOCATION = File.join('/etc/puppetlabs/r10k', CONFIG_FILE)
14
- OLD_DEFAULT_LOCATION = File.join('/etc', CONFIG_FILE)
15
-
16
- # Search for a deployment configuration file (r10k.yaml) in several locations
17
- def initialize
18
- @loadpath = []
19
- populate_loadpath
20
- end
21
-
22
- # @return [String] The path to the first valid configfile
23
- def search
24
-
25
- # If both default files are present, issue a warning.
26
- if (File.file? DEFAULT_LOCATION) && (File.file? OLD_DEFAULT_LOCATION)
27
- logger.warn "Both #{DEFAULT_LOCATION} and #{OLD_DEFAULT_LOCATION} configuration files exist."
28
- logger.warn "#{DEFAULT_LOCATION} will be used."
29
- end
30
-
31
- path = @loadpath.find {|filename| File.file? filename}
32
-
33
- if path == OLD_DEFAULT_LOCATION
34
- logger.warn "The r10k configuration file at #{OLD_DEFAULT_LOCATION} is deprecated."
35
- logger.warn "Please move your r10k configuration to #{DEFAULT_LOCATION}."
36
- end
37
-
38
- path
39
- end
40
-
41
- private
42
-
43
- def populate_loadpath
44
-
45
- # Add the current directory for r10k.yaml
46
- @loadpath << File.join(Dir.getwd, CONFIG_FILE)
47
-
48
- # Add the AIO location for of r10k.yaml
49
- @loadpath << DEFAULT_LOCATION
50
-
51
- # Add the old default location last.
52
- @loadpath << OLD_DEFAULT_LOCATION
53
-
54
- @loadpath
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,197 +0,0 @@
1
- require 'uri'
2
- require 'json'
3
- require 'set'
4
- require 'semantic_puppet/version'
5
-
6
- module Puppet
7
- module ModuleTool
8
-
9
- # This class provides a data structure representing a module's metadata.
10
- # @api private
11
- class Metadata
12
-
13
- attr_accessor :module_name
14
-
15
- DEFAULTS = {
16
- 'name' => nil,
17
- 'version' => nil,
18
- 'author' => nil,
19
- 'summary' => nil,
20
- 'license' => 'Apache-2.0',
21
- 'source' => '',
22
- 'project_page' => nil,
23
- 'issues_url' => nil,
24
- 'dependencies' => Set.new.freeze,
25
- }
26
-
27
- def initialize
28
- @data = DEFAULTS.dup
29
- @data['dependencies'] = @data['dependencies'].dup
30
- end
31
-
32
- # Returns a filesystem-friendly version of this module name.
33
- def dashed_name
34
- @data['name'].tr('/', '-') if @data['name']
35
- end
36
-
37
- # Returns a string that uniquely represents this version of this module.
38
- def release_name
39
- return nil unless @data['name'] && @data['version']
40
- [ dashed_name, @data['version'] ].join('-')
41
- end
42
-
43
- alias :name :module_name
44
- alias :full_module_name :dashed_name
45
-
46
- # Merges the current set of metadata with another metadata hash. This
47
- # method also handles the validation of module names and versions, in an
48
- # effort to be proactive about module publishing constraints.
49
- def update(data, with_dependencies = true)
50
- process_name(data) if data['name']
51
- process_version(data) if data['version']
52
- process_source(data) if data['source']
53
- merge_dependencies(data) if with_dependencies && data['dependencies']
54
-
55
- @data.merge!(data)
56
- return self
57
- end
58
-
59
- # Validates the name and version_requirement for a dependency, then creates
60
- # the Dependency and adds it.
61
- # Returns the Dependency that was added.
62
- def add_dependency(name, version_requirement=nil, repository=nil)
63
- validate_name(name)
64
- validate_version_range(version_requirement) if version_requirement
65
-
66
- if dup = @data['dependencies'].find { |d| d.full_module_name == name && d.version_requirement != version_requirement }
67
- raise ArgumentError, "Dependency conflict for #{full_module_name}: Dependency #{name} was given conflicting version requirements #{version_requirement} and #{dup.version_requirement}. Verify that there are no duplicates in the metadata.json or the Modulefile."
68
- end
69
-
70
- dep = Dependency.new(name, version_requirement, repository)
71
- @data['dependencies'].add(dep)
72
-
73
- dep
74
- end
75
-
76
- # Provides an accessor for the now defunct 'description' property. This
77
- # addresses a regression in Puppet 3.6.x where previously valid templates
78
- # refering to the 'description' property were broken.
79
- # @deprecated
80
- def description
81
- @data['description']
82
- end
83
-
84
- def dependencies
85
- @data['dependencies'].to_a
86
- end
87
-
88
- # Returns a hash of the module's metadata. Used by Puppet's automated
89
- # serialization routines.
90
- #
91
- # @see Puppet::Network::FormatSupport#to_data_hash
92
- def to_hash
93
- @data
94
- end
95
- alias :to_data_hash :to_hash
96
-
97
- def to_json
98
- data = @data.dup.merge('dependencies' => dependencies)
99
-
100
- contents = data.keys.map do |k|
101
- value = (JSON.pretty_generate(data[k]) rescue data[k].to_json)
102
- "#{k.to_json}: #{value}"
103
- end
104
-
105
- "{\n" + contents.join(",\n").gsub(/^/, ' ') + "\n}\n"
106
- end
107
-
108
- # Expose any metadata keys as callable reader methods.
109
- def method_missing(name, *args)
110
- return @data[name.to_s] if @data.key? name.to_s
111
- super
112
- end
113
-
114
- private
115
-
116
- # Do basic validation and parsing of the name parameter.
117
- def process_name(data)
118
- validate_name(data['name'])
119
- author, @module_name = data['name'].split(/[-\/]/, 2)
120
-
121
- data['author'] ||= author if @data['author'] == DEFAULTS['author']
122
- end
123
-
124
- # Do basic validation on the version parameter.
125
- def process_version(data)
126
- validate_version(data['version'])
127
- end
128
-
129
- # Do basic parsing of the source parameter. If the source is hosted on
130
- # GitHub, we can predict sensible defaults for both project_page and
131
- # issues_url.
132
- def process_source(data)
133
- if data['source'] =~ %r[://]
134
- source_uri = URI.parse(data['source'])
135
- else
136
- source_uri = URI.parse("http://#{data['source']}")
137
- end
138
-
139
- if source_uri.host =~ /^(www\.)?github\.com$/
140
- source_uri.scheme = 'https'
141
- source_uri.path.sub!(/\.git$/, '')
142
- data['project_page'] ||= @data['project_page'] || source_uri.to_s
143
- data['issues_url'] ||= @data['issues_url'] || source_uri.to_s.sub(/\/*$/, '') + '/issues'
144
- end
145
-
146
- rescue URI::Error
147
- return
148
- end
149
-
150
- # Validates and parses the dependencies.
151
- def merge_dependencies(data)
152
- data['dependencies'].each do |dep|
153
- add_dependency(dep['name'], dep['version_requirement'], dep['repository'])
154
- end
155
-
156
- # Clear dependencies so @data dependencies are not overwritten
157
- data.delete 'dependencies'
158
- end
159
-
160
- # Validates that the given module name is both namespaced and well-formed.
161
- def validate_name(name)
162
- return if name =~ /\A[a-z0-9]+[-\/][a-z][a-z0-9_]*\Z/i
163
-
164
- namespace, modname = name.split(/[-\/]/, 2)
165
- modname = :namespace_missing if namespace == ''
166
-
167
- err = case modname
168
- when nil, '', :namespace_missing
169
- "the field must be a namespaced module name"
170
- when /[^a-z0-9_]/i
171
- "the module name contains non-alphanumeric (or underscore) characters"
172
- when /^[^a-z]/i
173
- "the module name must begin with a letter"
174
- else
175
- "the namespace contains non-alphanumeric characters"
176
- end
177
-
178
- raise ArgumentError, "Invalid 'name' field in metadata.json: #{err}"
179
- end
180
-
181
- # Validates that the version string can be parsed by SemanticPuppet.
182
- def validate_version(version)
183
- return if SemanticPuppet::Version.valid?(version)
184
-
185
- err = "version string cannot be parsed as a valid Semantic Version"
186
- raise ArgumentError, "Invalid 'version' field in metadata.json: #{err}"
187
- end
188
-
189
- # Validates that the version range can be parsed by SemanticPuppet.
190
- def validate_version_range(version_range)
191
- SemanticPuppet::VersionRange.parse(version_range)
192
- rescue ArgumentError => e
193
- raise ArgumentError, "Invalid 'version_range' field in metadata.json: #{e}"
194
- end
195
- end
196
- end
197
- end
@@ -1,64 +0,0 @@
1
- require 'shared/puppet_forge/version'
2
- require 'shared/puppet_forge/connection/connection_failure'
3
-
4
- require 'faraday'
5
- require 'faraday_middleware'
6
-
7
- module PuppetForge
8
- # Provide a common mixin for adding a HTTP connection to classes.
9
- #
10
- # This module provides a common method for creating HTTP connections as well
11
- # as reusing a single connection object between multiple classes. Including
12
- # classes can invoke #conn to get a reasonably configured HTTP connection.
13
- # Connection objects can be passed with the #conn= method.
14
- #
15
- # @example
16
- # class HTTPThing
17
- # include PuppetForge::Connection
18
- # end
19
- # thing = HTTPThing.new
20
- # thing.conn = thing.make_connection('https://non-standard-forge.site')
21
- #
22
- # @api private
23
- module Connection
24
-
25
- attr_writer :conn
26
-
27
- USER_AGENT = "PuppetForge/#{PuppetForge::VERSION} Faraday/#{Faraday::VERSION} Ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} (#{RUBY_PLATFORM})"
28
-
29
- def self.authorization=(token)
30
- @authorization = token
31
- end
32
-
33
- def self.authorization
34
- @authorization
35
- end
36
-
37
- # @return [Faraday::Connection] An existing Faraday connection if one was
38
- # already set, otherwise a new Faraday connection.
39
- def conn
40
- @conn ||= make_connection('https://forgeapi.puppetlabs.com')
41
- end
42
-
43
- # Generate a new Faraday connection for the given URL.
44
- #
45
- # @param url [String] the base URL for this connection
46
- # @return [Faraday::Connection]
47
- def make_connection(url, adapter_args = nil)
48
- adapter_args ||= [Faraday.default_adapter]
49
- options = { :headers => { :user_agent => USER_AGENT }}
50
-
51
- if token = PuppetForge::Connection.authorization
52
- options[:headers][:authorization] = token
53
- end
54
-
55
- Faraday.new(url, options) do |builder|
56
- builder.response(:json, :content_type => /\bjson$/)
57
- builder.response(:raise_error)
58
- builder.use(:connection_failure)
59
-
60
- builder.adapter(*adapter_args)
61
- end
62
- end
63
- end
64
- end
@@ -1,26 +0,0 @@
1
- require 'faraday'
2
-
3
- module PuppetForge
4
- module Connection
5
- # Wrap Faraday connection failures to include the host and optional proxy
6
- # in use for the failed connection.
7
- class ConnectionFailure < Faraday::Middleware
8
- def call(env)
9
- @app.call(env)
10
- rescue Faraday::ConnectionFailed => e
11
- baseurl = env[:url].dup
12
- baseurl.path = ''
13
- errmsg = "Unable to connect to #{baseurl.to_s}"
14
- if proxy = env[:request][:proxy]
15
- errmsg << " (using proxy #{proxy.uri.to_s})"
16
- end
17
- errmsg << ": #{e.message}"
18
- m = Faraday::ConnectionFailed.new(errmsg)
19
- m.set_backtrace(e.backtrace)
20
- raise m
21
- end
22
- end
23
- end
24
- end
25
-
26
- Faraday::Middleware.register_middleware(:connection_failure => lambda { PuppetForge::Connection::ConnectionFailure })
@@ -1,41 +0,0 @@
1
- module PuppetForge
2
- class Error < RuntimeError
3
- attr_accessor :original
4
- def initialize(message, original=nil)
5
- super(message)
6
- @original = original
7
- end
8
- end
9
-
10
- class ExecutionFailure < PuppetForge::Error
11
- end
12
-
13
- class InvalidPathInPackageError < PuppetForge::Error
14
- def initialize(options)
15
- @entry_path = options[:entry_path]
16
- @directory = options[:directory]
17
- super "Attempt to install file into #{@entry_path.inspect} under #{@directory.inspect}"
18
- end
19
-
20
- def multiline
21
- <<-MSG.strip
22
- Could not install package
23
- Package attempted to install file into
24
- #{@entry_path.inspect} under #{@directory.inspect}.
25
- MSG
26
- end
27
- end
28
-
29
- class ModuleNotFound < PuppetForge::Error
30
- end
31
-
32
- class ModuleReleaseNotFound < PuppetForge::Error
33
- end
34
-
35
- class ModuleReleaseForbidden < PuppetForge::Error
36
- def self.from_response(response)
37
- body = JSON.parse(response[:body])
38
- new(body["message"])
39
- end
40
- end
41
- end
@@ -1,10 +0,0 @@
1
-
2
- module PuppetForge
3
- class Tar
4
- require 'shared/puppet_forge/tar/mini'
5
-
6
- def self.instance
7
- Mini.new
8
- end
9
- end
10
- end
@@ -1,81 +0,0 @@
1
- require 'zlib'
2
- require 'archive/tar/minitar'
3
-
4
- module PuppetForge
5
- class Tar
6
- class Mini
7
-
8
- SYMLINK_FLAGS = [2]
9
- VALID_TAR_FLAGS = (0..7)
10
-
11
- # @return [Hash{:symbol => Array<String>}] a hash with file-category keys pointing to lists of filenames.
12
- def unpack(sourcefile, destdir)
13
- # directories need to be changed outside of the Minitar::unpack because directories don't have a :file_done action
14
- dirlist = []
15
- file_lists = {}
16
- Zlib::GzipReader.open(sourcefile) do |reader|
17
- file_lists = validate_files(reader)
18
- Archive::Tar::Minitar.unpack(reader, destdir, file_lists[:valid]) do |action, name, stats|
19
- case action
20
- when :file_done
21
- FileUtils.chmod('u+rw,g+r,a-st', "#{destdir}/#{name}")
22
- when :file_start
23
- validate_entry(destdir, name)
24
- when :dir
25
- validate_entry(destdir, name)
26
- dirlist << "#{destdir}/#{name}"
27
- end
28
- end
29
- end
30
- dirlist.each {|d| File.chmod(0755, d)}
31
- file_lists
32
- end
33
-
34
- def pack(sourcedir, destfile)
35
- Zlib::GzipWriter.open(destfile) do |writer|
36
- Archive::Tar::Minitar.pack(sourcedir, writer)
37
- end
38
- end
39
-
40
- private
41
-
42
- # Categorize all the files in tarfile as :valid, :invalid, or :symlink.
43
- #
44
- # :invalid files include 'x' and 'g' flags from the PAX standard but and any other non-standard tar flags.
45
- # tar format info: http://pic.dhe.ibm.com/infocenter/zos/v1r13/index.jsp?topic=%2Fcom.ibm.zos.r13.bpxa500%2Ftaf.htm
46
- # pax format info: http://pic.dhe.ibm.com/infocenter/zos/v1r13/index.jsp?topic=%2Fcom.ibm.zos.r13.bpxa500%2Fpxarchfm.htm
47
- # :symlinks are not supported in Puppet modules
48
- # :valid files are any of those that can be used in modules
49
- # @param tarfile name of the tarfile
50
- # @return [Hash{:symbol => Array<String>}] a hash with file-category keys pointing to lists of filenames.
51
- def validate_files(tarfile)
52
- file_lists = {:valid => [], :invalid => [], :symlinks => []}
53
- Archive::Tar::Minitar.open(tarfile).each do |entry|
54
- flag = entry.typeflag
55
- if flag.nil? || flag =~ /[[:digit:]]/ && SYMLINK_FLAGS.include?(flag.to_i)
56
- file_lists[:symlinks] << entry.name
57
- elsif flag.nil? || flag =~ /[[:digit:]]/ && VALID_TAR_FLAGS.include?(flag.to_i)
58
- file_lists[:valid] << entry.name
59
- else
60
- file_lists[:invalid] << entry.name
61
- end
62
- end
63
- file_lists
64
- end
65
-
66
- def validate_entry(destdir, path)
67
- if Pathname.new(path).absolute?
68
- raise PuppetForge::InvalidPathInPackageError, :entry_path => path, :directory => destdir
69
- end
70
-
71
- path = File.expand_path File.join(destdir, path)
72
-
73
- if path !~ /\A#{Regexp.escape destdir}/
74
- raise PuppetForge::InvalidPathInPackageError, :entry_path => path, :directory => destdir
75
- end
76
- end
77
- end
78
- end
79
-
80
- end
81
-