Method: Puppet::Util::Ldap::Manager#update
- Defined in:
- lib/puppet/util/ldap/manager.rb
#update(name, is, should) ⇒ Object
Update the ldap entry with the desired state.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/puppet/util/ldap/manager.rb', line 220 def update(name, is, should) if should[:ensure] == :absent Puppet.info _("Removing %{name} from ldap") % { name: dn(name) } delete(name) return end # We're creating a new entry if is.empty? or is[:ensure] == :absent Puppet.info _("Creating %{name} in ldap") % { name: dn(name) } # Remove any :absent params and :ensure, then convert the names to ldap names. attrs = ldap_convert(should) create(name, attrs) return end # We're modifying an existing entry. Yuck. mods = [] # For each attribute we're deleting that is present, create a # modify instance for deletion. [is.keys, should.keys].flatten.uniq.each do |property| # They're equal, so do nothing. next if is[property] == should[property] attributes = ldap_convert(should) prop_name = ldap_name(property).to_s # We're creating it. if is[property] == :absent or is[property].nil? mods << LDAP::Mod.new(LDAP::LDAP_MOD_ADD, prop_name, attributes[prop_name]) next end # We're deleting it if should[property] == :absent or should[property].nil? mods << LDAP::Mod.new(LDAP::LDAP_MOD_DELETE, prop_name, []) next end # We're replacing an existing value mods << LDAP::Mod.new(LDAP::LDAP_MOD_REPLACE, prop_name, attributes[prop_name]) end modify(name, mods) end |