module OpenDirectoryUtils::CleanCheck
developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/dscl.1.html superuser.com/questions/592921/mac-osx-users-vs-dscl-command-to-list-user/621055?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
Public Instance Methods
assert(&block)
click to toggle source
# File lib/open_directory_utils/clean_check.rb, line 7 def assert(&block) raise ArgumentError unless block.call end
check_critical_attribute(attrib, key, value=nil)
click to toggle source
# File lib/open_directory_utils/clean_check.rb, line 11 def check_critical_attribute(attrib, key, value=nil) assert{not attrib[key].nil?} attrib[key] = attrib[key].to_s.strip assert{not attrib[key].eql? ''} assert{not attrib[key].eql? '[]'} assert{not attrib[key].eql? '{}'} assert{not attrib[key].include? ' '} if key.eql? :scope assert{not attrib[key].include? ' '} if [:uid, :username, :record_name].include? key rescue NoMethodError, ArgumentError # => error message = "#{key}: '#{attrib[key].inspect}' invalid" message += ", value_name: :#{value}" unless value.nil? raise ArgumentError, message end
group_record_name_alternatives(attribs)
click to toggle source
# File lib/open_directory_utils/clean_check.rb, line 41 def group_record_name_alternatives(attribs) attribs[:record_name] = nil attribs[:record_name] = attribs[:group_membership] attribs[:record_name] = attribs[:record_name] || attribs[:groupmembership] attribs[:record_name] = attribs[:record_name] || attribs[:group_name] attribs[:record_name] = attribs[:record_name] || attribs[:groupname] attribs[:record_name] = attribs[:record_name] || attribs[:gid] return attribs end
tidy_attribs(attribs)
click to toggle source
# File lib/open_directory_utils/clean_check.rb, line 25 def tidy_attribs(attribs) user_attribs = {} attribs.each{ |k,v| user_attribs[k] = v.to_s.strip } return user_attribs end
user_record_name_alternatives(attribs)
click to toggle source
# File lib/open_directory_utils/clean_check.rb, line 31 def user_record_name_alternatives(attribs) attribs[:record_name] = nil attribs[:record_name] = attribs[:user_name] attribs[:record_name] = attribs[:record_name] || attribs[:short_name] attribs[:record_name] = attribs[:record_name] || attribs[:shortname] attribs[:record_name] = attribs[:record_name] || attribs[:username] attribs[:record_name] = attribs[:record_name] || attribs[:uid] return attribs end