@@ -97,48 +97,30 @@ def exists?
9797 end
9898
9999 def create
100- t = Tempfile . new ( 'openldap_access' )
101- t << "dn: #{ getDn ( resource [ :suffix ] ) } \n "
102- t << "add: olcAccess\n "
103- t << if resource [ :position ]
104- "olcAccess: {#{ resource [ :position ] } }to #{ resource [ :what ] } \n "
105- else
106- "olcAccess: to #{ resource [ :what ] } \n "
107- end
108- resource [ :access ] . flatten . each do |a |
109- t << " #{ a } \n "
110- end
111- t . close
112- Puppet . debug ( File . read ( t . path ) )
113- begin
114- ldapmodify ( t . path )
115- rescue StandardError => e
116- raise Puppet ::Error , "LDIF content:\n #{ File . read t . path } \n Error message: #{ e . message } "
100+ @property_flush << 'add: olcAccess'
101+
102+ @property_flush << if resource [ :position ]
103+ "olcAccess: {#{ resource [ :position ] } }to #{ resource [ :what ] } "
104+ else
105+ "olcAccess: to #{ resource [ :what ] } "
106+ end
107+
108+ @property_flush << resource [ :access ] . flatten . map do |a |
109+ " #{ a } "
117110 end
118111 end
119112
120113 def destroy
121- t = Tempfile . new ( 'openldap_access' )
122- t << "dn: #{ getDn ( @property_hash [ :suffix ] ) } \n "
123- t << "changetype: modify\n "
124- t << "delete: olcAccess\n "
125- t << "olcAccess: {#{ @property_hash [ :position ] } }\n "
126- t . close
127- Puppet . debug ( File . read ( t . path ) )
128- begin
129- ldapmodify ( t . path )
130- rescue StandardError => e
131- raise Puppet ::Error , "LDIF content:\n #{ File . read t . path } \n Error message: #{ e . message } "
132- end
114+ @property_flush << [
115+ 'changetype: modify' ,
116+ 'delete: olcAccess' ,
117+ "olcAccess: {#{ @property_hash [ :position ] } }" ,
118+ ]
133119 end
134120
135121 def initialize ( value = { } )
136122 super ( value )
137- @property_flush = { }
138- end
139-
140- def access = ( value )
141- @property_flush [ :access ] = value . flatten
123+ @property_flush = [ ]
142124 end
143125
144126 def self . getCountOfOlcAccess ( suffix )
@@ -172,30 +154,32 @@ def getCurrentOlcAccess(suffix)
172154 end
173155
174156 def flush
175- unless @property_flush . empty?
157+ if @property_flush . empty?
176158 current_olcAccess = getCurrentOlcAccess ( resource [ :suffix ] )
177- t = Tempfile . new ( 'openldap_access' )
178- t << "dn: #{ getDn ( resource [ :suffix ] ) } \n "
179- t << "changetype: modify \n "
180- t << "replace: olcAccess \n "
159+ @property_flush << [
160+ 'changetype: modify' ,
161+ 'replace: olcAccess' ,
162+ ]
181163 position = resource [ :position ] || @property_hash [ :position ]
182164 current_olcAccess . each do |olc_access |
183165 if olc_access [ :position ] . to_i == position . to_i
184- t << "olcAccess: {#{ position } }to #{ resource [ :what ] } \n "
166+ @property_flush << "olcAccess: {#{ position } }to #{ resource [ :what ] } "
185167 resource [ :access ] . flatten . each do |a |
186- t << " #{ a } \n "
168+ @property_flush << " #{ a } "
187169 end
188170 else
189- t << "olcAccess: {#{ olc_access [ :position ] } }#{ olc_access [ :content ] } \n "
171+ @property_flush << "olcAccess: {#{ olc_access [ :position ] } }#{ olc_access [ :content ] } "
190172 end
191173 end
192- self . class . getCountOfOlcAccess ( resource [ :suffix ] )
193- t . close
194- Puppet . debug ( File . read ( t . path ) )
174+ end
175+ @property_flush . prepend ( "dn: #{ getDn ( resource [ :suffix ] ) } " )
176+ Tempfile . create ( 'openldap_access' ) do |t |
177+ t . puts ( @property_flush )
178+ Puppet . debug ( t . read )
195179 begin
196180 ldapmodify ( t . path )
197181 rescue StandardError => e
198- raise Puppet ::Error , "LDIF content:\n #{ File . read t . path } \n Error message: #{ e . message } "
182+ raise Puppet ::Error , "LDIF content:\n #{ t . read } \n Error message: #{ e . message } "
199183 end
200184 end
201185 @property_hash = resource . to_hash
0 commit comments