class Puppet::Settings::FileSetting

A file.

Attributes

create[RW]
mode[RW]

Public Class Methods

new(args) click to toggle source
Calls superclass method Puppet::Settings::BaseSetting.new
# File lib/puppet/settings/file_setting.rb, line 60
def initialize(args)
  @group = Unspecified.new
  @owner = Unspecified.new
  super(args)
end

Public Instance Methods

create_files?() click to toggle source

Should we create files, rather than just directories?

# File lib/puppet/settings/file_setting.rb, line 67
def create_files?
  create
end
group() click to toggle source

@return [String, nil] the name of the group to use for the file or nil if the group should not be managed @api public

# File lib/puppet/settings/file_setting.rb, line 101
def group
  @group.value
end
group=(value) click to toggle source

@param value [String] the group to use on the created file (can only be “root” or “service”) @api public

# File lib/puppet/settings/file_setting.rb, line 73
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) click to toggle source
# File lib/puppet/settings/file_setting.rb, line 111
def munge(value)
  if value.is_a?(String)
    value = File.expand_path(value)
  end
  value
end
owner() click to toggle source

@return [String, nil] the name of the user to use for the file or nil if the user should not be managed @api public

# File lib/puppet/settings/file_setting.rb, line 107
def owner
  @owner.value
end
owner=(value) click to toggle source

@param value [String] the owner to use on the created file (can only be “root” or “service”) @api public

# File lib/puppet/settings/file_setting.rb, line 88
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() click to toggle source

Turn our setting thing into a Puppet::Resource instance.

# File lib/puppet/settings/file_setting.rb, line 123
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.expand_path(path)

  return nil unless type == :directory or create_files? or File.exist?(path)
  return nil if path =~ /^\/dev/ or path =~ /^[A-Z]:\/dev/

  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() click to toggle source
# File lib/puppet/settings/file_setting.rb, line 118
def type
  :file
end
validate(value) click to toggle source

Make sure any provided variables look up to something.

# File lib/puppet/settings/file_setting.rb, line 172
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