# File lib/puppet/provider/nameservice/directoryservice.rb, line 146 146: def self.parse_dscl_url_data(dscl_output) 147: # we need to construct a Hash from the dscl -url output to match 148: # that returned by the dscl -plist output for 10.5+ clients. 149: # 150: # Nasty assumptions: 151: # a) no values *end* in a colon ':', only keys 152: # b) if a line ends in a colon and the next line does start with 153: # a space, then the second line is a value of the first. 154: # c) (implied by (b)) keys don't start with spaces. 155: 156: dscl_plist = {} 157: dscl_output.split("\n").inject([]) do |array, line| 158: if line =~ /^\s+/ # it's a value 159: array[-1] << line # add the value to the previous key 160: else 161: array << line 162: end 163: array 164: end.compact 165: 166: dscl_output.each do |line| 167: # This should be a 'normal' entry. key and value on one line. 168: # We split on ': ' to deal with keys/values with a colon in them. 169: split_array = line.split(/:\s+/) 170: key = split_array.first 171: value = CGI::unescape(split_array.last.strip.chomp) 172: # We need to treat GroupMembership separately as it is currently 173: # the only attribute we care about multiple values for, and 174: # the values can never contain spaces (shortnames) 175: # We also make every value an array to be consistent with the 176: # output of dscl -plist under 10.5 177: if key == "GroupMembership" 178: dscl_plist[key] = value.split(/\s/) 179: else 180: dscl_plist[key] = [value] 181: end 182: end 183: return dscl_plist 184: end