puppet-module 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.markdown +91 -0
- data/LICENSE +17 -0
- data/README.markdown +221 -0
- data/Rakefile +87 -0
- data/VERSION +1 -0
- data/bin/puppet-module +7 -0
- data/lib/puppet/module/tool.rb +124 -0
- data/lib/puppet/module/tool/applications.rb +18 -0
- data/lib/puppet/module/tool/applications/application.rb +83 -0
- data/lib/puppet/module/tool/applications/builder.rb +88 -0
- data/lib/puppet/module/tool/applications/checksummer.rb +38 -0
- data/lib/puppet/module/tool/applications/cleaner.rb +14 -0
- data/lib/puppet/module/tool/applications/freezer.rb +20 -0
- data/lib/puppet/module/tool/applications/generator.rb +117 -0
- data/lib/puppet/module/tool/applications/installer.rb +83 -0
- data/lib/puppet/module/tool/applications/registrar.rb +34 -0
- data/lib/puppet/module/tool/applications/releaser.rb +48 -0
- data/lib/puppet/module/tool/applications/searcher.rb +34 -0
- data/lib/puppet/module/tool/applications/unpacker.rb +69 -0
- data/lib/puppet/module/tool/applications/unreleaser.rb +42 -0
- data/lib/puppet/module/tool/cache.rb +56 -0
- data/lib/puppet/module/tool/checksums.rb +52 -0
- data/lib/puppet/module/tool/cli.rb +127 -0
- data/lib/puppet/module/tool/contents_description.rb +84 -0
- data/lib/puppet/module/tool/dependency.rb +26 -0
- data/lib/puppet/module/tool/metadata.rb +80 -0
- data/lib/puppet/module/tool/modulefile.rb +47 -0
- data/lib/puppet/module/tool/repository.rb +74 -0
- data/lib/puppet/module/tool/skeleton.rb +39 -0
- data/lib/puppet/module/tool/utils.rb +9 -0
- data/lib/puppet/module/tool/utils/interrogation.rb +39 -0
- data/lib/puppet/module/tool/utils/settings.rb +36 -0
- data/lib/puppet/module/tool/utils/uri.rb +16 -0
- data/spec/fixtures/releases/jamtur01-apache/Modulefile +2 -0
- data/spec/fixtures/releases/jamtur01-apache/files/httpd +24 -0
- data/spec/fixtures/releases/jamtur01-apache/files/test.vhost +18 -0
- data/spec/fixtures/releases/jamtur01-apache/lib/puppet/provider/a2mod/debian.rb +21 -0
- data/spec/fixtures/releases/jamtur01-apache/lib/puppet/type/a2mod.rb +12 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/dev.pp +5 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/init.pp +34 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/params.pp +17 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/php.pp +5 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/ssl.pp +15 -0
- data/spec/fixtures/releases/jamtur01-apache/manifests/vhost.pp +15 -0
- data/spec/fixtures/releases/jamtur01-apache/metadata.json +1 -0
- data/spec/fixtures/releases/jamtur01-apache/templates/vhost-default.conf.erb +20 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/apache.pp +1 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/dev.pp +1 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/init.pp +1 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/php.pp +1 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/ssl.pp +1 -0
- data/spec/fixtures/releases/jamtur01-apache/tests/vhost.pp +2 -0
- data/spec/integration/cli_spec.rb +373 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/output_support.rb +19 -0
- data/spec/support/stub_http_support.rb +14 -0
- data/spec/support/testdir_support.rb +26 -0
- data/spec/unit/application_spec.rb +25 -0
- data/spec/unit/repository_spec.rb +51 -0
- data/templates/generator/Modulefile.erb +5 -0
- data/templates/generator/README.erb +3 -0
- data/templates/generator/files/README.markdown +22 -0
- data/templates/generator/lib/puppet/facter/README.markdown +22 -0
- data/templates/generator/lib/puppet/parser/functions/README.markdown +17 -0
- data/templates/generator/lib/puppet/provider/README.markdown +14 -0
- data/templates/generator/lib/puppet/type/README.markdown +14 -0
- data/templates/generator/manifests/README.markdown +28 -0
- data/templates/generator/manifests/init.pp.erb +17 -0
- data/templates/generator/metadata.json +12 -0
- data/templates/generator/spec/README.markdown +7 -0
- data/templates/generator/spec/spec.opts +6 -0
- data/templates/generator/spec/spec_helper.rb +18 -0
- data/templates/generator/spec/unit/puppet/provider/README.markdown +4 -0
- data/templates/generator/spec/unit/puppet/type/README.markdown +4 -0
- data/templates/generator/templates/README.markdown +23 -0
- data/templates/generator/tests/init.pp.erb +1 -0
- data/vendor/facets-2.8.2-partial/lib/facets/kernel/returning.rb +23 -0
- data/vendor/facets-2.8.2-partial/lib/facets/kernel/tap.rb +39 -0
- data/vendor/multipart-post-1.0/Manifest.txt +9 -0
- data/vendor/multipart-post-1.0/README.txt +61 -0
- data/vendor/multipart-post-1.0/Rakefile +21 -0
- data/vendor/multipart-post-1.0/lib/composite_io.rb +89 -0
- data/vendor/multipart-post-1.0/lib/multipartable.rb +13 -0
- data/vendor/multipart-post-1.0/lib/net/http/post/multipart.rb +27 -0
- data/vendor/multipart-post-1.0/lib/parts.rb +66 -0
- data/vendor/multipart-post-1.0/test/net/http/post/test_multipart.rb +55 -0
- data/vendor/multipart-post-1.0/test/test_composite_io.rb +50 -0
- data/vendor/thor-852190ae/CHANGELOG.rdoc +89 -0
- data/vendor/thor-852190ae/LICENSE +20 -0
- data/vendor/thor-852190ae/README.rdoc +297 -0
- data/vendor/thor-852190ae/REVISION +1 -0
- data/vendor/thor-852190ae/Thorfile +69 -0
- data/vendor/thor-852190ae/bin/rake2thor +86 -0
- data/vendor/thor-852190ae/bin/thor +6 -0
- data/vendor/thor-852190ae/lib/thor.rb +244 -0
- data/vendor/thor-852190ae/lib/thor/actions.rb +275 -0
- data/vendor/thor-852190ae/lib/thor/actions/create_file.rb +103 -0
- data/vendor/thor-852190ae/lib/thor/actions/directory.rb +91 -0
- data/vendor/thor-852190ae/lib/thor/actions/empty_directory.rb +134 -0
- data/vendor/thor-852190ae/lib/thor/actions/file_manipulation.rb +223 -0
- data/vendor/thor-852190ae/lib/thor/actions/inject_into_file.rb +104 -0
- data/vendor/thor-852190ae/lib/thor/base.rb +540 -0
- data/vendor/thor-852190ae/lib/thor/core_ext/file_binary_read.rb +9 -0
- data/vendor/thor-852190ae/lib/thor/core_ext/hash_with_indifferent_access.rb +75 -0
- data/vendor/thor-852190ae/lib/thor/core_ext/ordered_hash.rb +100 -0
- data/vendor/thor-852190ae/lib/thor/error.rb +30 -0
- data/vendor/thor-852190ae/lib/thor/group.rb +271 -0
- data/vendor/thor-852190ae/lib/thor/invocation.rb +180 -0
- data/vendor/thor-852190ae/lib/thor/parser.rb +4 -0
- data/vendor/thor-852190ae/lib/thor/parser/argument.rb +67 -0
- data/vendor/thor-852190ae/lib/thor/parser/arguments.rb +150 -0
- data/vendor/thor-852190ae/lib/thor/parser/option.rb +128 -0
- data/vendor/thor-852190ae/lib/thor/parser/options.rb +169 -0
- data/vendor/thor-852190ae/lib/thor/rake_compat.rb +66 -0
- data/vendor/thor-852190ae/lib/thor/runner.rb +314 -0
- data/vendor/thor-852190ae/lib/thor/shell.rb +83 -0
- data/vendor/thor-852190ae/lib/thor/shell/basic.rb +239 -0
- data/vendor/thor-852190ae/lib/thor/shell/color.rb +108 -0
- data/vendor/thor-852190ae/lib/thor/task.rb +102 -0
- data/vendor/thor-852190ae/lib/thor/util.rb +230 -0
- data/vendor/thor-852190ae/lib/thor/version.rb +3 -0
- data/vendor/thor-852190ae/spec/actions/create_file_spec.rb +170 -0
- data/vendor/thor-852190ae/spec/actions/directory_spec.rb +131 -0
- data/vendor/thor-852190ae/spec/actions/empty_directory_spec.rb +91 -0
- data/vendor/thor-852190ae/spec/actions/file_manipulation_spec.rb +271 -0
- data/vendor/thor-852190ae/spec/actions/inject_into_file_spec.rb +135 -0
- data/vendor/thor-852190ae/spec/actions_spec.rb +292 -0
- data/vendor/thor-852190ae/spec/base_spec.rb +263 -0
- data/vendor/thor-852190ae/spec/core_ext/hash_with_indifferent_access_spec.rb +43 -0
- data/vendor/thor-852190ae/spec/core_ext/ordered_hash_spec.rb +115 -0
- data/vendor/thor-852190ae/spec/fixtures/application.rb +2 -0
- data/vendor/thor-852190ae/spec/fixtures/bundle/execute.rb +6 -0
- data/vendor/thor-852190ae/spec/fixtures/bundle/main.thor +1 -0
- data/vendor/thor-852190ae/spec/fixtures/doc/%file_name%.rb.tt +1 -0
- data/vendor/thor-852190ae/spec/fixtures/doc/README +3 -0
- data/vendor/thor-852190ae/spec/fixtures/doc/config.rb +1 -0
- data/vendor/thor-852190ae/spec/fixtures/group.thor +83 -0
- data/vendor/thor-852190ae/spec/fixtures/invoke.thor +112 -0
- data/vendor/thor-852190ae/spec/fixtures/script.thor +140 -0
- data/vendor/thor-852190ae/spec/fixtures/task.thor +10 -0
- data/vendor/thor-852190ae/spec/group_spec.rb +171 -0
- data/vendor/thor-852190ae/spec/invocation_spec.rb +107 -0
- data/vendor/thor-852190ae/spec/parser/argument_spec.rb +47 -0
- data/vendor/thor-852190ae/spec/parser/arguments_spec.rb +64 -0
- data/vendor/thor-852190ae/spec/parser/option_spec.rb +202 -0
- data/vendor/thor-852190ae/spec/parser/options_spec.rb +292 -0
- data/vendor/thor-852190ae/spec/rake_compat_spec.rb +68 -0
- data/vendor/thor-852190ae/spec/runner_spec.rb +202 -0
- data/vendor/thor-852190ae/spec/shell/basic_spec.rb +205 -0
- data/vendor/thor-852190ae/spec/shell/color_spec.rb +41 -0
- data/vendor/thor-852190ae/spec/shell_spec.rb +34 -0
- data/vendor/thor-852190ae/spec/spec.opts +1 -0
- data/vendor/thor-852190ae/spec/spec_helper.rb +54 -0
- data/vendor/thor-852190ae/spec/task_spec.rb +69 -0
- data/vendor/thor-852190ae/spec/thor_spec.rb +237 -0
- data/vendor/thor-852190ae/spec/util_spec.rb +167 -0
- data/vendor/thor-852190ae/thor.gemspec +120 -0
- metadata +229 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
module Puppet::Module::Tool
|
2
|
+
|
3
|
+
# = ContentsDescription
|
4
|
+
#
|
5
|
+
# This class populates +Metadata+'s Puppet type information.
|
6
|
+
class ContentsDescription
|
7
|
+
|
8
|
+
# Instantiate object for string +module_path+.
|
9
|
+
def initialize(module_path)
|
10
|
+
@module_path = module_path
|
11
|
+
end
|
12
|
+
|
13
|
+
# Update +Metadata+'s Puppet type information.
|
14
|
+
def annotate(metadata)
|
15
|
+
metadata.types.replace data.clone
|
16
|
+
end
|
17
|
+
|
18
|
+
# Return types for this module. Result is an array of hashes, each of which
|
19
|
+
# describes a Puppet type. The type description hash structure is:
|
20
|
+
# * :name => Name of this Puppet type.
|
21
|
+
# * :doc => Documentation for this type.
|
22
|
+
# * :properties => Array of hashes representing the type's properties, each
|
23
|
+
# containing :name and :doc.
|
24
|
+
# * :parameters => Array of hashes representing the type's parameters, each
|
25
|
+
# containing :name and :doc.
|
26
|
+
# * :providers => Array of hashes representing the types providers, each
|
27
|
+
# containing :name and :doc.
|
28
|
+
# TODO Write a TypeDescription to encapsulate these structures and logic?
|
29
|
+
def data
|
30
|
+
unless @data
|
31
|
+
@data = []
|
32
|
+
type_names = []
|
33
|
+
for module_filename in Dir[File.join(@module_path, "lib/puppet/type/*.rb")]
|
34
|
+
require module_filename
|
35
|
+
type_name = File.basename(module_filename, ".rb")
|
36
|
+
type_names << type_name
|
37
|
+
|
38
|
+
for provider_filename in Dir[File.join(@module_path, "lib/puppet/provider/#{type_name}/*.rb")]
|
39
|
+
require provider_filename
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
type_names.each do |type_name|
|
44
|
+
if type = Puppet::Type.type(type_name.to_sym)
|
45
|
+
type_hash = {:name => type_name, :doc => type.doc}
|
46
|
+
type_hash[:properties] = attr_doc(type, :property)
|
47
|
+
type_hash[:parameters] = attr_doc(type, :param)
|
48
|
+
if type.providers.size > 0
|
49
|
+
type_hash[:providers] = provider_doc(type)
|
50
|
+
end
|
51
|
+
@data << type_hash
|
52
|
+
else
|
53
|
+
puts "Could not find/load type: #{type_name}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
@data
|
58
|
+
end
|
59
|
+
|
60
|
+
# Return an array of hashes representing this +type+'s attrs of +kind+
|
61
|
+
# (e.g. :param or :property), each containing :name and :doc.
|
62
|
+
def attr_doc(type, kind)
|
63
|
+
returning([]) do |attrs|
|
64
|
+
type.allattrs.each do |name|
|
65
|
+
if type.attrtype(name) == kind && name != :provider
|
66
|
+
attrs.push(:name => name, :doc => type.attrclass(name).doc)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Return an array of hashes representing this +type+'s providers, each
|
73
|
+
# containing :name and :doc.
|
74
|
+
def provider_doc(type)
|
75
|
+
returning([]) do |providers|
|
76
|
+
type.providers.sort_by{ |o| o.to_s }.each do |prov|
|
77
|
+
providers.push(:name => prov, :doc => type.provider(prov).doc)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Puppet::Module::Tool
|
2
|
+
|
3
|
+
class Dependency
|
4
|
+
|
5
|
+
# Instantiates a new module dependency with a +full_name+ (e.g.
|
6
|
+
# "myuser-mymodule"), and optional +version_requirement+ (e.g. "0.0.1") and
|
7
|
+
# optional repository (a URL string).
|
8
|
+
def initialize(full_name, version_requirement = nil, repository = nil)
|
9
|
+
@full_name = full_name
|
10
|
+
# TODO: add error checking, the next line raises ArgumentError when +full_name+ is invalid
|
11
|
+
@username, @name = Puppet::Module::Tool.username_and_modname_from(full_name)
|
12
|
+
@version_requirement = version_requirement
|
13
|
+
@repository = repository ? Repository.new(repository) : nil
|
14
|
+
end
|
15
|
+
|
16
|
+
# Return PSON representation of this data.
|
17
|
+
def to_pson(*args)
|
18
|
+
result = { :name => @full_name }
|
19
|
+
result[:version_requirement] = @version_requirement if @version_requirement && ! @version_requirement.nil?
|
20
|
+
result[:repository] = @repository.to_s if @repository && ! @repository.nil?
|
21
|
+
result.to_pson(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Puppet::Module::Tool
|
2
|
+
|
3
|
+
# = Metadata
|
4
|
+
#
|
5
|
+
# This class provides a data structure representing a module's metadata.
|
6
|
+
# It provides some basic parsing, but other data is injected into it using
|
7
|
+
# +annotate+ methods in other classes.
|
8
|
+
class Metadata
|
9
|
+
|
10
|
+
# The full name of the module, which is a dash-separated combination of the
|
11
|
+
# +username+ and module +name+.
|
12
|
+
attr_reader :full_name
|
13
|
+
|
14
|
+
# The name of the user that owns this module.
|
15
|
+
attr_reader :username
|
16
|
+
|
17
|
+
# The name of this module. See also +full_name+.
|
18
|
+
attr_reader :name
|
19
|
+
|
20
|
+
# The version of this module, a string like '0.1.0'.
|
21
|
+
attr_accessor :version
|
22
|
+
|
23
|
+
# Instantiate from a hash, whose keys are setters in this class.
|
24
|
+
def initialize(settings={})
|
25
|
+
settings.each do |key, value|
|
26
|
+
send("#{key}=", value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Set the full name of this module, and from it, the +username+ and
|
31
|
+
# module +name+.
|
32
|
+
def full_name=(full_name)
|
33
|
+
@full_name = full_name
|
34
|
+
@username, @name = Puppet::Module::Tool::username_and_modname_from(full_name)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Return an array of the module's Dependency objects.
|
38
|
+
def dependencies
|
39
|
+
return @dependencies ||= []
|
40
|
+
end
|
41
|
+
|
42
|
+
# Return an array of the module's Puppet types, each one is a hash
|
43
|
+
# containing :name and :doc.
|
44
|
+
# TODO Shouldn't this be it's own class?
|
45
|
+
def types
|
46
|
+
return @types ||= []
|
47
|
+
end
|
48
|
+
|
49
|
+
# Return module's file checksums.
|
50
|
+
def checksums
|
51
|
+
return @checksums ||= {}
|
52
|
+
end
|
53
|
+
|
54
|
+
# Return the dashed name of the module, which may either be the
|
55
|
+
# dash-separated combination of the +username+ and module +name+, or just
|
56
|
+
# the module +name+.
|
57
|
+
def dashed_name
|
58
|
+
return [@username, @name].compact.join('-')
|
59
|
+
end
|
60
|
+
|
61
|
+
# Return the release name, which is the combination of the +dashed_name+
|
62
|
+
# of the module and its +version+ number.
|
63
|
+
def release_name
|
64
|
+
return [dashed_name, @version].join('-')
|
65
|
+
end
|
66
|
+
|
67
|
+
# Return the PSON record representing this instance.
|
68
|
+
def to_pson(*args)
|
69
|
+
return {
|
70
|
+
:name => @full_name,
|
71
|
+
:version => @version,
|
72
|
+
:dependencies => dependencies,
|
73
|
+
:types => types,
|
74
|
+
:checksums => checksums
|
75
|
+
}.to_pson(*args)
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Puppet::Module::Tool
|
2
|
+
|
3
|
+
# = Modulefile
|
4
|
+
#
|
5
|
+
# This class provides the DSL used for evaluating the module's 'Modulefile'.
|
6
|
+
# These methods are used to concisely define this module's attributes, which
|
7
|
+
# are later rendered as PSON into a 'metadata.json' file.
|
8
|
+
class Modulefile
|
9
|
+
|
10
|
+
# Read the +filename+ and eval its Ruby code to set values in the Metadata
|
11
|
+
# +metadata+ instance.
|
12
|
+
def self.evaluate(metadata, filename)
|
13
|
+
returning(new(metadata)) do |builder|
|
14
|
+
if File.file?(filename)
|
15
|
+
builder.instance_eval(File.read(filename.to_s), filename.to_s, 1)
|
16
|
+
else
|
17
|
+
puts "No Modulefile: #{filename}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Instantiate with the Metadata +metadata+ instance.
|
23
|
+
def initialize(metadata)
|
24
|
+
@metadata = metadata
|
25
|
+
end
|
26
|
+
|
27
|
+
# Set the +full_name+ (e.g. "myuser-mymodule"), which will also set the
|
28
|
+
# +username+ and module +name+. Required.
|
29
|
+
def name(name)
|
30
|
+
@metadata.full_name = name
|
31
|
+
end
|
32
|
+
|
33
|
+
# Set the module +version+ (e.g., "0.0.1"). Required.
|
34
|
+
def version(version)
|
35
|
+
@metadata.version = version
|
36
|
+
end
|
37
|
+
|
38
|
+
# Add a dependency with the full_name +name+ (e.g. "myuser-mymodule"), an
|
39
|
+
# optional +version_requirement+ (e.g. "0.0.1") and +repository+ (a URL
|
40
|
+
# string). Optional. Can be called multiple times to add many dependencies.
|
41
|
+
def dependency(name, version_requirement = nil, repository = nil)
|
42
|
+
@metadata.dependencies << Dependency.new(name, version_requirement, repository)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'digest/sha1'
|
3
|
+
|
4
|
+
module Puppet::Module::Tool
|
5
|
+
|
6
|
+
# = Repository
|
7
|
+
#
|
8
|
+
# This class is a file for accessing remote repositories with modules.
|
9
|
+
class Repository
|
10
|
+
include Utils::URI
|
11
|
+
include Utils::Interrogation
|
12
|
+
|
13
|
+
attr_reader :uri, :cache
|
14
|
+
|
15
|
+
# Instantiate a new repository instance rooted at the optional string
|
16
|
+
# +url+, else an instance of the default Puppet modules repository.
|
17
|
+
def initialize(url=Puppet::Module::Tool::REPOSITORY_URL)
|
18
|
+
@uri = normalize(url)
|
19
|
+
@cache = Cache.new(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Return a Net::HTTPResponse read for this +request+.
|
23
|
+
#
|
24
|
+
# Options:
|
25
|
+
# * :authenticate => Request authentication on the terminal. Defaults to false.
|
26
|
+
def contact(request, options = {})
|
27
|
+
if options[:authenticate]
|
28
|
+
authenticate(request)
|
29
|
+
end
|
30
|
+
if ! @uri.user.nil? && ! @uri.password.nil?
|
31
|
+
request.basic_auth(@uri.user, @uri.password)
|
32
|
+
end
|
33
|
+
return read_contact(request)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Return a Net::HTTPResponse read from this HTTPRequest +request+.
|
37
|
+
def read_contact(request)
|
38
|
+
Net::HTTP.start(@uri.host, @uri.port) do |http|
|
39
|
+
http.request(request)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Set the HTTP Basic Authentication parameters for the Net::HTTPRequest
|
44
|
+
# +request+ by asking the user for input on the console.
|
45
|
+
def authenticate(request)
|
46
|
+
header "Authenticating for #{@uri}"
|
47
|
+
email = prompt('Email Address')
|
48
|
+
password = prompt('Password', true)
|
49
|
+
request.basic_auth(email, password)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Return the local file name containing the data downloaded from the
|
53
|
+
# repository at +release+ (e.g. "myuser-mymodule").
|
54
|
+
def retrieve(release)
|
55
|
+
return cache.retrieve(@uri + release)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Return the URI string for this repository.
|
59
|
+
def to_s
|
60
|
+
return @uri.to_s
|
61
|
+
end
|
62
|
+
|
63
|
+
# Return the cache key for this repository, this a hashed string based on
|
64
|
+
# the URI.
|
65
|
+
def cache_key
|
66
|
+
return @cache_key ||= [
|
67
|
+
@uri.to_s.gsub(/[^[:alnum:]]+/, '_').sub(/_$/, ''),
|
68
|
+
Digest::SHA1.hexdigest(@uri.to_s)
|
69
|
+
].join('-')
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Puppet::Module::Tool
|
2
|
+
|
3
|
+
# = Skeleton
|
4
|
+
#
|
5
|
+
# This class provides methods for finding templates for the 'generate' action.
|
6
|
+
class Skeleton
|
7
|
+
|
8
|
+
# TODO Review whether the 'freeze' feature should be fixed or deleted.
|
9
|
+
# def freeze!
|
10
|
+
# FileUtils.rm_fr custom_path rescue nil
|
11
|
+
# FileUtils.cp_r default_path, custom_path
|
12
|
+
# end
|
13
|
+
|
14
|
+
# Return Pathname with 'generate' templates.
|
15
|
+
def path
|
16
|
+
paths.detect { |path| path.directory? }
|
17
|
+
end
|
18
|
+
|
19
|
+
# Return Pathnames to look for 'generate' templates.
|
20
|
+
def paths
|
21
|
+
@paths ||= [
|
22
|
+
custom_path,
|
23
|
+
default_path
|
24
|
+
]
|
25
|
+
end
|
26
|
+
|
27
|
+
# Return Pathname of custom templates directory.
|
28
|
+
def custom_path
|
29
|
+
Puppet::Module::Tool.working_dir + 'skeleton'
|
30
|
+
end
|
31
|
+
|
32
|
+
# Return Pathname of default template directory.
|
33
|
+
def default_path
|
34
|
+
Puppet::Module::Tool.root + 'templates' + 'generator'
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Puppet::Module::Tool
|
2
|
+
module Utils
|
3
|
+
|
4
|
+
# = Interrogation
|
5
|
+
#
|
6
|
+
# This module contains methods to emit text to the console, such as headers.
|
7
|
+
module Interrogation
|
8
|
+
|
9
|
+
def header(text)
|
10
|
+
$stderr.puts('=' * text.size, text, "-" * text.size)
|
11
|
+
end
|
12
|
+
|
13
|
+
def say(*args)
|
14
|
+
$stderr.puts(*args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def subheader(line)
|
18
|
+
say line, ('-' * line.size)
|
19
|
+
end
|
20
|
+
|
21
|
+
def confirms?(question)
|
22
|
+
$stderr.print "#{question} [y/N]: "
|
23
|
+
$stdin.gets =~ /y/i
|
24
|
+
end
|
25
|
+
|
26
|
+
def prompt(question, quiet = false)
|
27
|
+
$stderr.print "#{question}: "
|
28
|
+
system 'stty -echo' if quiet
|
29
|
+
$stdin.gets.strip
|
30
|
+
ensure
|
31
|
+
if quiet
|
32
|
+
system 'stty echo'
|
33
|
+
say "\n---------"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Puppet::Module::Tool::Utils
|
2
|
+
|
3
|
+
# = Settings
|
4
|
+
#
|
5
|
+
# This module contains methods for interacting with Puppet's settings files.
|
6
|
+
module Settings
|
7
|
+
|
8
|
+
def prepare_settings(options = {})
|
9
|
+
return if @settings_prepared
|
10
|
+
|
11
|
+
if options[:config]
|
12
|
+
Puppet.settings.send(:set_value, :config, options[:config], :cli)
|
13
|
+
end
|
14
|
+
|
15
|
+
Puppet.setdefaults(:puppet_module,
|
16
|
+
:puppet_module_repository => [Puppet::Module::Tool::REPOSITORY_URL, "The module repository"],
|
17
|
+
:puppet_module_working_dir => ['$vardir/puppet-module', "The directory in which module tool data is stored"])
|
18
|
+
|
19
|
+
Puppet::Module::Tool.working_dir.mkpath
|
20
|
+
|
21
|
+
Puppet.settings.use(:puppet_module)
|
22
|
+
|
23
|
+
Puppet.settings.parse
|
24
|
+
|
25
|
+
[:puppet_module_repository].each do |key|
|
26
|
+
if options[key]
|
27
|
+
Puppet.settings.send(:set_value, key, options[key], :cli)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
@settings_prepared = true
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Puppet::Module::Tool
|
4
|
+
module Utils
|
5
|
+
module URI
|
6
|
+
|
7
|
+
# Return a URI instance for the +uri+, a a string or URI object.
|
8
|
+
def normalize(url)
|
9
|
+
return url.is_a?(::URI) ?
|
10
|
+
url :
|
11
|
+
::URI.parse(url)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|