def primary_group_for(user)
       # Force a reload in case any users were created earlier in the run.
      Etc.endpwent
      Etc.endgrent
      user = if user.is_a?(Integer)
        Etc.getpwuid(user)
      else
        Etc.getpwnam(user.to_s)
      end
      Etc.getgrgid(user.gid).name
    rescue ArgumentError
      # One of the get* calls exploded. ¯\_(ツ)_/¯
      user.to_s
    end
def primary_group_for(user)
       # Force a reload in case any users were created earlier in the run.
      Etc.endpwent
      Etc.endgrent
      user = if user.is_a?(Integer)
        Etc.getpwuid(user)
      else
        Etc.getpwnam(user.to_s)
      end
      Etc.getgrgid(user.gid).name
    rescue ArgumentError
      # One of the get* calls exploded. ¯\_(ツ)_/¯
      user.to_s
    end
Try to find the primary group name for a given user.

 @param user [String, Integer] User to check, if given as an integer this
   is used as a UID, otherwise it is the username.
 @return [String]
 @example
   attribute(:group, kind_of: [String, Integer], default: lazy { PoiseApplication::Utils.primary_group_for(user) })