File: parsed.rb

package info (click to toggle)
puppet-agent 8.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 27,392 kB
  • sloc: ruby: 286,820; sh: 492; xml: 116; makefile: 88; cs: 68
file content (58 lines) | stat: -rw-r--r-- 1,761 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'puppet/provider/parsedfile'

Puppet::Type.type(:sshkey).provide(
  :parsed,
  parent: Puppet::Provider::ParsedFile,
  filetype: :flat,
) do
  desc 'Parse and generate host-wide known hosts files for SSH.'

  text_line :comment, match: %r{^#}
  text_line :blank, match: %r{^\s*$}

  record_line :parsed, fields: ['name', 'type', 'key'],
                       post_parse: proc { |hash|
                                     names = hash[:name].split(',', -1)
                                     hash[:name] = names.shift
                                     hash[:host_aliases] = names
                                   },
                       pre_gen: proc { |hash|
                                  if hash[:host_aliases]
                                    hash[:name] = [hash[:name], hash[:host_aliases]].flatten.join(',')
                                    hash.delete(:host_aliases)
                                  end
                                }

  # Make sure to use mode 644 if ssh_known_hosts is newly created
  def self.default_mode
    0o644
  end

  def title
    "#{property_hash[:name]}@#{property_hash[:type]}"
  end

  def self.default_target
    case Facter.value('os.name')
    when 'Darwin'
      # Versions 10.11 and up use /etc/ssh/ssh_known_hosts
      version = Facter.value('os.macosx.version.major')
      if version
        if Puppet::Util::Package.versioncmp(version, '10.11') >= 0
          '/etc/ssh/ssh_known_hosts'
        else
          '/etc/ssh_known_hosts'
        end
      else
        '/etc/ssh_known_hosts'
      end
    else
      '/etc/ssh/ssh_known_hosts'
    end
  end

  def self.resource_for_record(record, resources)
    name = "#{record[:name]}@#{record[:type]}"
    resources[name]
  end
end