Sha256: 2ff517cc411f2426c4acdc05076bef1e060290dbf69be20d058801eceda3b306

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Motoko
  module Utils
    module PuppetDB
      def self.class_filter(klass)
        operator = '='

        if klass =~ %r{\A/.*/\z}
          klass = klass[1..-2]
          operator = '~'
        end

        "certname in resources[certname] { type = 'Class' and title #{operator} '#{klass.split('::').map(&:capitalize).join('::')}' }"
      end

      def self.fact_filter(fact)
        name, operator, value = fact.split(/([!<>]?=|[<>])/, 2)

        if operator == '=' && value =~ %r{\A/.*/\z}
          value = value[1..-2]
          operator = '~'
        end

        begin
          value = case value
                  when 'true' then true
                  when 'false' then false
                  else Integer(value)
                  end
        rescue ArgumentError
          value = "'#{value}'"
        end

        "certname in inventory[certname] { facts.#{name} #{operator} #{value} }"
      end

      def self.identity_filter(identity)
        operator = '='

        if identity =~ %r{\A/.*/\z}
          identity = identity[1..-2]
          operator = '~'
        end

        "certname #{operator} '#{identity}'"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
motoko-1.2.1 lib/motoko/utils/puppet_db.rb
motoko-1.2.0 lib/motoko/utils/puppet_db.rb
motoko-1.1.0 lib/motoko/utils/puppet_db.rb
motoko-1.0.0 lib/motoko/utils/puppet_db.rb