Puppet Function: ora_cis::validate_versions

Defined in:
lib/puppet/functions/ora_cis/validate_versions.rb
Function type:
Ruby 4.x API

Overview

ora_cis::validate_versions(String $db_version, String $doc_version)Any

See the file “LICENSE” for the full license governing this code.

Validate if the specified db_version and doc_version is an existing combination. If not give a readable error message that shows available versions

Parameters:

  • db_version (String)
  • doc_version (String)

Returns:

  • (Any)


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
# File 'lib/puppet/functions/ora_cis/validate_versions.rb', line 9

Puppet::Functions.create_function('ora_cis::validate_versions') do
  dispatch :validate_versions do
    param 'String', :db_version
    param 'String', :doc_version
  end

  def validate_versions(db_version, doc_version)
    valid_doc_versions = valid_combinations[db_version]
    raise Puppet::Error.new("db_version '#{db_version}' is not known and/or supported.\n Valid versions are #{valid_db_versions}") if valid_doc_versions.nil?
    raise Puppet::Error.new("doc_version '#{doc_version}' is not known and/or supported for  db_version '#{db_version}'.\n Valid versions for db_version '#{db_version}' are #{valid_doc_versions.join(',')}") unless valid_doc_versions.include?(doc_version)
  end

  def valid_db_versions
    valid_combinations.keys.join(',')
  end

  def valid_combinations
    @valid_combinations ||= call_function('lookup', 'ora_cis::valid_combinations', data_type('Hash'), 'first', nil)
  end

  def data_type(string)
    parser = Puppet::Pops::Types::TypeParser.singleton
    parser.parse(string)
  end

end