<commit_before># TODO: better unify with code in model/attribute special processing
module DTK
  class Node
    class NodeAttribute
      def initialize(node)
        @node = node
      end

      def root_device_size()
        ret_value?(:root_device_size)
      end

      def cardinality(opts={})
        ret = ret_value?(:cardinality)
        (opts[:no_default] ? ret : ret||CardinalityDefault)
      end
      CardinalityDefault = 1

      def puppet_version(opts={})
        puppet_version = ret_value?(:puppet_version)
        if opts[:raise_error_if_invalid]
          raise_error_if_invalid_puppet_version(puppet_version)
        end
        puppet_version||R8::Config[:puppet][:version]
      end

      def raise_error_if_invalid_puppet_version(puppet_version)
        unless puppet_version.nil? or puppet_version.empty?
          unless RubyGemsChecker.gem_exists?('puppet', puppet_version)
            raise ErrorUsage.new("Invalid Puppet version (#{puppet_version})")
          end
        end
      end

     def clear_host_addresses()
       if attr = @node.get_node_attribute?('host_addresses_ipv4',:cols=>[:id,:group_id,:value_derived])
         if host_addresses = attr[:value_derived]
           if host_addresses.find{|a|!a.nil?}
             cleared_vals = host_addresses.map{|a|nil}
             attr.merge!(:value_derived => cleared_vals)
             Attribute.update_and_propagate_attributes(attr.model_handle(),[attr])
           end
         end
       end
     end

      def self.target_ref_attributes_filter()
        TargetRefAttributeFilter
      end
      def self.assembly_template_attribute_filter()
        AssemblyTemplateAttributeFilter
      end
      TargetRefAttributes = ['host_addresses_ipv4','fqdn','node_components','puppet_version','root_device_size']
      TargetRefAttributeFilter = [:oneof,:display_name,TargetRefAttributes]
      NodeTemplateAttributes = ['host_addresses_ipv4','node_components','fqdn']
      AssemblyTemplateAttributeFilter = [:and] + NodeTemplateAttributes.map{|a|[:neq,:display_name,a]}
<commit_msg>RubyGemsChecker.gem_exists?('puppet', puppet_version) commented out because giving lase posative on 2.7.25<commit_after># TODO: better unify with code in model/attribute special processing
module DTK
  class Node
    class NodeAttribute
      def initialize(node)
        @node = node
      end

      def root_device_size()
        ret_value?(:root_device_size)
      end

      def cardinality(opts={})
        ret = ret_value?(:cardinality)
        (opts[:no_default] ? ret : ret||CardinalityDefault)
      end
      CardinalityDefault = 1

      def puppet_version(opts={})
        puppet_version = ret_value?(:puppet_version)
        if opts[:raise_error_if_invalid]
          raise_error_if_invalid_puppet_version(puppet_version)
        end
        puppet_version||R8::Config[:puppet][:version]
      end

      def raise_error_if_invalid_puppet_version(puppet_version)
        unless puppet_version.nil? or puppet_version.empty?
          unless RubyGemsChecker.gem_exists?('puppet', puppet_version)
           # TODO: took out because this is giving false posatives 
           # raise ErrorUsage.new("Invalid Puppet version (#{puppet_version})")
            Log.error("RubyGemsChecker.gem_exists? test fails with Puppet version (#{puppet_version})")
          end
        end
      end

     def clear_host_addresses()
       if attr = @node.get_node_attribute?('host_addresses_ipv4',:cols=>[:id,:group_id,:value_derived])
         if host_addresses = attr[:value_derived]
           if host_addresses.find{|a|!a.nil?}
             cleared_vals = host_addresses.map{|a|nil}
             attr.merge!(:value_derived => cleared_vals)
             Attribute.update_and_propagate_attributes(attr.model_handle(),[attr])
           end
         end
       end
     end

      def self.target_ref_attributes_filter()
        TargetRefAttributeFilter
      end
      def self.assembly_template_attribute_filter()
        AssemblyTemplateAttributeFilter
      end
      TargetRefAttributes = ['host_addresses_ipv4','fqdn','node_components','puppet_version','root_device_size']
      TargetRefAttributeFilter = [:oneof,:display_name,TargetRefAttributes]
      NodeTemplateAttributes = ['host_addresses_ipv4','node_components','fqdn']
      AssemblyTemplateAttributeFilter = [:and] + NodeTemplateAttributes.map{|a|[:neq,:display_name,a]}

{'fraction_non_alphanumeric': 0.09441670449387199, 'fraction_numerical': 0.0031774852473899226, 'mean_word_length': 3.213193116634799, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3812605', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1307, 'n_words': 221}