Class: Inspec::Resources::Postgres

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/postgres.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePostgres



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
# File 'lib/resources/postgres.rb', line 11

def initialize
  if inspec.os.debian?
    #
    # https://wiki.debian.org/PostgreSql
    #
    # Debian allows multiple versions of postgresql to be
    # installed as well as multiple "clusters" to be configured.
    #
    @version = version_from_psql || version_from_dir('/etc/postgresql')
    @cluster = cluster_from_dir("/etc/postgresql/#{@version}")
    @conf_dir = "/etc/postgresql/#{@version}/#{@cluster}"
    @data_dir = "/var/lib/postgresql/#{@version}/#{@cluster}"
  else
    @version = version_from_psql
    if @version.nil?
      if inspec.directory('/var/lib/pgsql/data').exist?
        warn 'Unable to determine PostgreSQL version: psql did not return
         a version number and unversioned data directories were found.'
        nil
      else
        @version = version_from_dir('/var/lib/pgsql')
      end
    end
    @data_dir = locate_data_dir_location_by_version(@version)
  end

  @service = 'postgresql'
  @service += "-#{@version}" if @version.to_f >= 9.4
  @conf_dir ||= @data_dir

  verify_dirs
  if !@version.nil? && !@conf_dir.empty?
    @conf_path = File.join @conf_dir, 'postgresql.conf'
  else
    @conf_path = nil
    return skip_resource 'Seems like PostgreSQL is not installed on your system'
  end
end

Instance Attribute Details

#clusterObject (readonly)

Returns the value of attribute cluster.



10
11
12
# File 'lib/resources/postgres.rb', line 10

def cluster
  @cluster
end

#conf_dirObject (readonly)

Returns the value of attribute conf_dir.



10
11
12
# File 'lib/resources/postgres.rb', line 10

def conf_dir
  @conf_dir
end

#conf_pathObject (readonly)

Returns the value of attribute conf_path.



10
11
12
# File 'lib/resources/postgres.rb', line 10

def conf_path
  @conf_path
end

#data_dirObject (readonly)

Returns the value of attribute data_dir.



10
11
12
# File 'lib/resources/postgres.rb', line 10

def data_dir
  @data_dir
end

#serviceObject (readonly)

Returns the value of attribute service.



10
11
12
# File 'lib/resources/postgres.rb', line 10

def service
  @service
end

#versionObject (readonly)

Returns the value of attribute version.



10
11
12
# File 'lib/resources/postgres.rb', line 10

def version
  @version
end

Instance Method Details

#to_sObject



50
51
52
# File 'lib/resources/postgres.rb', line 50

def to_s
  'PostgreSQL'
end