self._validate

in cookbooks/fb_users/libraries/default.rb [21:135]


    def self._validate(node)
      
      
      if node['fb_users']['users'].empty? && node['fb_users']['groups'].empty?
        return
      end

      uids = {}
      UID_MAP.each do |user, info|
        if uids[info['uid']]
          fail "fb_users[user]: User #{user} in UID map has a UID conflict"
        end

        if defined?(RESERVED_UID_RANGES)
          RESERVED_UID_RANGES.each do |identifier, range|
            if range.include?(info['uid'])
              fail "fb_users[user]: User #{user} in UID map is in the " +
                "reserved range for '#{identifier}'"
            end
          end
        end
        uids[info['uid']] = nil
      end

      gids = {}
      GID_MAP.each do |group, info|
        if gids[info['gid']]
          fail "fb_users[group]: group #{group} in GID map has a GID conflict"
        end

        if defined?(RESERVED_GID_RANGES)
          RESERVED_GID_RANGES.each do |identifier, range|
            if range.include?(info['gid'])
              fail "fb_users[group]: Group #{group} in GID map is in the " +
                "reserved range for '#{identifier}'"
            end
          end
        end
        uids[info['gid']] = nil
      end

      if node['fb_users']['user_defaults']['gid']
        gid = node['fb_users']['user_defaults']['gid']
        unless GID_MAP[gid]
          fail "fb_users[user]: Default group #{gid} has no GID in the " +
            'GID_MAP - update, or unset it.'
        end
      end

      node['fb_users']['users'].each do |user, info|
        unless [nil, :add, :delete].include?(info['action'])
          fail "fb_users[users]: User #{user} has unknown action #{action}"
        end

        if info['action'] == :delete
          
          
          allowed_remove_properties = %w{manage_home action}
          extra_keys = info.keys - allowed_remove_properties
          unless extra_keys.empty?
            fail "fb_users[user]: User #{user} has action :delete with " +
              "invalid keys: #{extra_keys}. Allowed keys are " +
              allowed_remove_properties.to_s
          end
          next
        end

        unless UID_MAP[user]
          fail "fb_users[user]: User #{user} has no UID in the UID_MAP"
        end

        if info['gid']
          gid = info['gid']
          unless GID_MAP[gid]
            fail "fb_users[user]: User #{user} has a group of #{gid} which " +
              'is not in the GID_MAP'
          end
          gid_int = false
          
          
          begin
            gid_int = !!Integer(gid)
          rescue ArgumentError
            
          end
          
          

          if gid_int
            fail "fb_users[user]: User #{user} has an integer for primary" +
              ' group. Please specify a name.'
          end
        elsif !node['fb_users']['user_defaults']['gid']
          fail "fb_users[user]: User #{user} has no primary group (gid) " +
            'and there is no default set.'
        end
      end
      node['fb_users']['groups'].each do |group, info|
        unless [nil, :add, :delete].include?(info['action'])
          fail "fb_users[group]: Group #{group} has unknown action #{action}"
        end

        if info['action'] == :delete
          if info.keys.count > 1
            fail "fb_users[group]: Group #{group} has action :delete, but " +
              "also other keys: #{info}"
          end
          next
        end
        unless GID_MAP[group]
          fail "fb_users[group]: Group #{group} has no GID in the GID_MAP"
        end
      end
    end