File: config.rb

package info (click to toggle)
ruby-puppetserver-ca-cli 2.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 696 kB
  • sloc: ruby: 6,970; sh: 4; makefile: 3
file content (69 lines) | stat: -rw-r--r-- 2,169 bytes parent folder | download | duplicates (2)
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
59
60
61
62
63
64
65
66
67
68
69
require 'puppetserver/ca/utils/file_system'

module Puppetserver
  module Ca
    module Utils
      module Config

        def self.running_as_root?
          !Gem.win_platform? && Process::UID.eid == 0
        end

        def self.munge_alt_names(names)
          raw_names = names.split(/\s*,\s*/).map(&:strip)
          munged_names = raw_names.map do |name|
            # Prepend the DNS tag if no tag was specified
            if !name.start_with?("IP:") && !name.start_with?("DNS:")
              "DNS:#{name}"
            else
              name
            end
          end.sort.uniq.join(", ")
        end

        def self.puppet_confdir
          if running_as_root?
            '/etc/puppet'
          else
            "#{ENV['HOME']}/.puppet"
          end
        end

        def self.puppetserver_confdir(puppet_confdir)
          File.join(puppet_confdir, 'puppetserver')
        end

        def self.default_ssldir(confdir = puppet_confdir)
          system_ssldir = '/var/lib/puppet/ssl'
          user_ssldir = File.join(confdir, 'ssl')
          if running_as_root? or File.owned?(system_ssldir)
            system_ssldir
          else
            user_ssldir
          end
        end

        def self.old_default_cadir(confdir = puppet_confdir)
          File.join(default_ssldir(confdir), 'ca')
        end

        def self.new_default_cadir(confdir = puppet_confdir)
          File.join(puppetserver_confdir(confdir), 'ca')
        end

        def self.symlink_to_old_cadir(current_cadir, puppet_confdir)
          old_cadir = old_default_cadir(puppet_confdir)
          new_cadir = new_default_cadir(puppet_confdir)
          return if current_cadir != new_cadir
          # skip if the parent directory of old_cadir doesn't exist
          return if !File.exist?(File.expand_path('..', old_cadir))
          # This is only run on setup/import, so there should be no files in the
          # old cadir, so it should be safe to forcibly remove it (which we need
          # to do in order to create a symlink).
          Puppetserver::Ca::Utils::FileSystem.forcibly_symlink(new_cadir, old_cadir)
        end

      end
    end
  end
end