Class: Puppet::Util::Settings::FileSetting
- Defined in:
- lib/vendor/puppet/util/settings/file_setting.rb
Overview
A file.
Defined Under Namespace
Classes: SettingError
Constant Summary collapse
- AllowedOwners =
%w{root service}
- AllowedGroups =
%w{root service}
Instance Attribute Summary collapse
-
#create ⇒ Object
Returns the value of attribute create.
-
#mode ⇒ Object
Returns the value of attribute mode.
Attributes inherited from Setting
#call_on_define, #default, #desc, #name, #section, #setbycli, #short
Instance Method Summary collapse
-
#create_files? ⇒ Boolean
Should we create files, rather than just directories?.
- #group ⇒ Object
- #group=(value) ⇒ Object
-
#munge(value) ⇒ Object
Set the type appropriately.
- #owner ⇒ Object
- #owner=(value) ⇒ Object
-
#to_resource ⇒ Object
Turn our setting thing into a Puppet::Resource instance.
-
#type ⇒ Object
Return the appropriate type.
- #use_service_user? ⇒ Boolean
-
#validate(value) ⇒ Object
Make sure any provided variables look up to something.
Methods inherited from Setting
#getopt_args, #hook=, #initialize, #iscreated, #iscreated?, #optparse_args, #set?, #to_config, #value
Constructor Details
This class inherits a constructor from Puppet::Util::Settings::Setting
Instance Attribute Details
#create ⇒ Object
Returns the value of attribute create.
10 11 12 |
# File 'lib/vendor/puppet/util/settings/file_setting.rb', line 10 def create @create end |
#mode ⇒ Object
Returns the value of attribute mode.
10 11 12 |
# File 'lib/vendor/puppet/util/settings/file_setting.rb', line 10 def mode @mode end |
Instance Method Details
#create_files? ⇒ Boolean
Should we create files, rather than just directories?
13 14 15 |
# File 'lib/vendor/puppet/util/settings/file_setting.rb', line 13 def create_files? create end |
#group ⇒ Object
25 26 27 28 |
# File 'lib/vendor/puppet/util/settings/file_setting.rb', line 25 def group return unless @group @settings[:group] end |
#group=(value) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/vendor/puppet/util/settings/file_setting.rb', line 17 def group=(value) unless AllowedGroups.include?(value) = [desc,name,default].compact.join(': ') raise SettingError, "Internal error: The :group setting for #{} must be 'service', not '#{value}'" end @group = value end |
#munge(value) ⇒ Object
Set the type appropriately. Yep, a hack. This supports either naming the variable ‘dir’, or adding a slash at the end.
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/vendor/puppet/util/settings/file_setting.rb', line 50 def munge(value) # If it's not a fully qualified path... if value.is_a?(String) and value !~ /^\$/ and value != 'false' # Preserve trailing slash (stripped by expand_path) isdir = value =~ /\/$/ value = File.(value) value += '/' if isdir end value end |
#owner ⇒ Object
38 39 40 41 42 |
# File 'lib/vendor/puppet/util/settings/file_setting.rb', line 38 def owner return unless @owner return "root" if @owner == "root" or ! use_service_user? @settings[:user] end |
#owner=(value) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/vendor/puppet/util/settings/file_setting.rb', line 30 def owner=(value) unless AllowedOwners.include?(value) = [desc,name,default].compact.join(': ') raise SettingError, "Internal error: The :owner setting for #{} must be either 'root' or 'service', not '#{value}'" end @owner = value end |
#to_resource ⇒ Object
Turn our setting thing into a Puppet::Resource instance.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/vendor/puppet/util/settings/file_setting.rb', line 76 def to_resource return nil unless type = self.type path = self.value return nil unless path.is_a?(String) # Make sure the paths are fully qualified. path = File.(path) return nil unless type == :directory or create_files? or File.exist?(path) return nil if path =~ /^\/dev/ or path =~ /^[A-Z]:\/dev/i resource = Puppet::Resource.new(:file, path) if Puppet[:manage_internal_file_permissions] if self.mode # This ends up mimicking the munge method of the mode # parameter to make sure that we're always passing the string # version of the octal number. If we were setting the # 'should' value for mode rather than the 'is', then the munge # method would be called for us automatically. Normally, one # wouldn't need to call the munge method manually, since # 'should' gets set by the provider and it should be able to # provide the data in the appropriate format. mode = self.mode mode = mode.to_i(8) if mode.is_a?(String) mode = mode.to_s(8) resource[:mode] = mode end # REMIND fails on Windows because chown/chgrp functionality not supported yet if Puppet.features.root? and !Puppet.features.microsoft_windows? resource[:owner] = self.owner if self.owner resource[:group] = self.group if self.group end end resource[:ensure] = type resource[:loglevel] = :debug resource[:links] = :follow resource[:backup] = false resource.tag(self.section, self.name, "settings") resource end |
#type ⇒ Object
Return the appropriate type.
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/vendor/puppet/util/settings/file_setting.rb', line 62 def type value = @settings.value(self.name) if @name.to_s =~ /dir/ return :directory elsif value.to_s =~ /\/$/ return :directory elsif value.is_a? String return :file else return nil end end |
#use_service_user? ⇒ Boolean
44 45 46 |
# File 'lib/vendor/puppet/util/settings/file_setting.rb', line 44 def use_service_user? @settings[:mkusers] or @settings.service_user_available? end |
#validate(value) ⇒ Object
Make sure any provided variables look up to something.
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/vendor/puppet/util/settings/file_setting.rb', line 125 def validate(value) return true unless value.is_a? String value.scan(/\$(\w+)/) { |name| name = $1 unless @settings.include?(name) raise ArgumentError, "Settings parameter '#{name}' is undefined" end } end |