Class: Puppet::Settings::FileSetting
- Inherits:
-
StringSetting
- Object
- BaseSetting
- StringSetting
- Puppet::Settings::FileSetting
- Defined in:
- lib/puppet/settings/file_setting.rb
Overview
A file.
Direct Known Subclasses
Defined Under Namespace
Classes: Root, Service, SettingError, Unspecified
Instance Attribute Summary collapse
Attributes inherited from BaseSetting
#call_hook, #call_on_define, #default, #desc, #name, #section, #short
Instance Method Summary collapse
-
#create_files? ⇒ Boolean
Should we create files, rather than just directories?.
- #exclusive_open(option = 'r', &block) ⇒ Object private
-
#group ⇒ String?
The name of the group to use for the file or nil if the group should not be managed.
- #group=(value) ⇒ Object
-
#initialize(args) ⇒ FileSetting
constructor
A new instance of FileSetting.
- #munge(value) ⇒ Object
- #open(option = 'r', &block) ⇒ Object private
-
#owner ⇒ String?
The name of the user to use for the file or nil if the user should not be managed.
- #owner=(value) ⇒ Object
-
#to_resource ⇒ Object
Turn our setting thing into a Puppet::Resource instance.
- #type ⇒ Object
-
#validate(value) ⇒ Object
Make sure any provided variables look up to something.
Methods inherited from BaseSetting
available_call_hook_values, #call_hook_on_define?, #call_hook_on_initialize?, #getopt_args, #has_hook?, #hook=, #iscreated, #iscreated?, #optparse_args, #setbycli, #setbycli=, #to_config, #value
Constructor Details
#initialize(args) ⇒ FileSetting
Returns a new instance of FileSetting.
58 59 60 61 62 |
# File 'lib/puppet/settings/file_setting.rb', line 58 def initialize(args) @group = Unspecified.new @owner = Unspecified.new super(args) end |
Instance Attribute Details
#create ⇒ Object
56 57 58 |
# File 'lib/puppet/settings/file_setting.rb', line 56 def create @create end |
Instance Method Details
#create_files? ⇒ Boolean
Should we create files, rather than just directories?
65 66 67 |
# File 'lib/puppet/settings/file_setting.rb', line 65 def create_files? create end |
#exclusive_open(option = 'r', &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
182 183 184 185 186 |
# File 'lib/puppet/settings/file_setting.rb', line 182 def exclusive_open(option = 'r', &block) controlled_access do |mode| file.exclusive_open(mode, option, &block) end end |
#group ⇒ String?
Returns the name of the group to use for the file or nil if the group should not be managed.
99 100 101 |
# File 'lib/puppet/settings/file_setting.rb', line 99 def group @group.value end |
#group=(value) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/puppet/settings/file_setting.rb', line 71 def group=(value) @group = case value when "root" Root.new when "service" # Group falls back to `nil` because we cannot assume that a "root" group exists. # Some systems have root group, others have wheel, others have something else. Service.new(:group, nil, @settings, :service_group_available?) else unknown_value(':group', value) end end |
#munge(value) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/puppet/settings/file_setting.rb', line 109 def munge(value) if value.is_a?(String) and value != ':memory:' # for sqlite3 in-memory tests value = File.(value) end value end |
#open(option = 'r', &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
189 190 191 192 193 |
# File 'lib/puppet/settings/file_setting.rb', line 189 def open(option = 'r', &block) controlled_access do |mode| file.open(mode, option, &block) end end |
#owner ⇒ String?
Returns the name of the user to use for the file or nil if the user should not be managed.
105 106 107 |
# File 'lib/puppet/settings/file_setting.rb', line 105 def owner @owner.value end |
#owner=(value) ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/puppet/settings/file_setting.rb', line 86 def owner=(value) @owner = case value when "root" Root.new when "service" Service.new(:user, "root", @settings, :service_user_available?) else unknown_value(':owner', value) end end |
#to_resource ⇒ Object
Turn our setting thing into a Puppet::Resource instance.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/puppet/settings/file_setting.rb', line 121 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 Puppet::FileSystem::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
116 117 118 |
# File 'lib/puppet/settings/file_setting.rb', line 116 def type :file end |
#validate(value) ⇒ Object
Make sure any provided variables look up to something.
170 171 172 173 174 175 176 177 178 179 |
# File 'lib/puppet/settings/file_setting.rb', line 170 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 |