Skip to content

Commit 910b13e

Browse files
committed
Instrument Net::LDAP#add, #modify, #delete, #rename
1 parent 5e9b735 commit 910b13e

File tree

1 file changed

+69
-61
lines changed

1 file changed

+69
-61
lines changed

lib/net/ldap.rb

Lines changed: 69 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -849,24 +849,26 @@ def bind_as(args = {})
849849
# ldap.add(:dn => dn, :attributes => attr)
850850
# end
851851
def add(args)
852-
if @open_connection
853-
@result = @open_connection.add(args)
854-
else
855-
@result = 0
856-
begin
857-
conn = Connection.new \
858-
:host => @host,
859-
:port => @port,
860-
:encryption => @encryption,
861-
:instrumentation_service => @instrumentation_service
862-
if (@result = conn.bind(args[:auth] || @auth)).result_code == 0
863-
@result = conn.add(args)
852+
instrument "add.net_ldap", args do |payload|
853+
if @open_connection
854+
@result = @open_connection.add(args)
855+
else
856+
@result = 0
857+
begin
858+
conn = Connection.new \
859+
:host => @host,
860+
:port => @port,
861+
:encryption => @encryption,
862+
:instrumentation_service => @instrumentation_service
863+
if (@result = conn.bind(args[:auth] || @auth)).result_code == 0
864+
@result = conn.add(args)
865+
end
866+
ensure
867+
conn.close if conn
864868
end
865-
ensure
866-
conn.close if conn
867869
end
870+
@result.success?
868871
end
869-
@result.success?
870872
end
871873

872874
# Modifies the attribute values of a particular entry on the LDAP
@@ -950,25 +952,27 @@ def add(args)
950952
# simultaneously by the server. It bears repeating that this concurrency
951953
# does _not_ imply transactional atomicity, which LDAP does not provide.
952954
def modify(args)
953-
if @open_connection
954-
@result = @open_connection.modify(args)
955-
else
956-
@result = 0
957-
begin
958-
conn = Connection.new \
959-
:host => @host,
960-
:port => @port,
961-
:encryption => @encryption,
962-
:instrumentation_service => @instrumentation_service
963-
if (@result = conn.bind(args[:auth] || @auth)).result_code == 0
964-
@result = conn.modify(args)
955+
instrument "modify.net_ldap", args do |payload|
956+
if @open_connection
957+
@result = @open_connection.modify(args)
958+
else
959+
@result = 0
960+
begin
961+
conn = Connection.new \
962+
:host => @host,
963+
:port => @port,
964+
:encryption => @encryption,
965+
:instrumentation_service => @instrumentation_service
966+
if (@result = conn.bind(args[:auth] || @auth)).result_code == 0
967+
@result = conn.modify(args)
968+
end
969+
ensure
970+
conn.close if conn
965971
end
966-
ensure
967-
conn.close if conn
968972
end
969-
end
970973

971-
@result.success?
974+
@result.success?
975+
end
972976
end
973977

974978
# Add a value to an attribute. Takes the full DN of the entry to modify,
@@ -1025,24 +1029,26 @@ def delete_attribute(dn, attribute)
10251029
#
10261030
# _Documentation_ _stub_
10271031
def rename(args)
1028-
if @open_connection
1029-
@result = @open_connection.rename(args)
1030-
else
1031-
@result = 0
1032-
begin
1033-
conn = Connection.new \
1034-
:host => @host,
1035-
:port => @port,
1036-
:encryption => @encryption,
1037-
:instrumentation_service => @instrumentation_service
1038-
if (@result = conn.bind(args[:auth] || @auth)).result_code == 0
1039-
@result = conn.rename(args)
1032+
instrument "rename.net_ldap", args do |payload|
1033+
if @open_connection
1034+
@result = @open_connection.rename(args)
1035+
else
1036+
@result = 0
1037+
begin
1038+
conn = Connection.new \
1039+
:host => @host,
1040+
:port => @port,
1041+
:encryption => @encryption,
1042+
:instrumentation_service => @instrumentation_service
1043+
if (@result = conn.bind(args[:auth] || @auth)).result_code == 0
1044+
@result = conn.rename(args)
1045+
end
1046+
ensure
1047+
conn.close if conn
10401048
end
1041-
ensure
1042-
conn.close if conn
10431049
end
1050+
@result.success?
10441051
end
1045-
@result.success?
10461052
end
10471053
alias_method :modify_rdn, :rename
10481054

@@ -1056,24 +1062,26 @@ def rename(args)
10561062
# dn = "[email protected], ou=people, dc=example, dc=com"
10571063
# ldap.delete :dn => dn
10581064
def delete(args)
1059-
if @open_connection
1060-
@result = @open_connection.delete(args)
1061-
else
1062-
@result = 0
1063-
begin
1064-
conn = Connection.new \
1065-
:host => @host,
1066-
:port => @port,
1067-
:encryption => @encryption,
1068-
:instrumentation_service => @instrumentation_service
1069-
if (@result = conn.bind(args[:auth] || @auth)).result_code == 0
1070-
@result = conn.delete(args)
1065+
instrument "delete.net_ldap", args do |payload|
1066+
if @open_connection
1067+
@result = @open_connection.delete(args)
1068+
else
1069+
@result = 0
1070+
begin
1071+
conn = Connection.new \
1072+
:host => @host,
1073+
:port => @port,
1074+
:encryption => @encryption,
1075+
:instrumentation_service => @instrumentation_service
1076+
if (@result = conn.bind(args[:auth] || @auth)).result_code == 0
1077+
@result = conn.delete(args)
1078+
end
1079+
ensure
1080+
conn.close
10711081
end
1072-
ensure
1073-
conn.close
10741082
end
1083+
@result.success?
10751084
end
1076-
@result.success?
10771085
end
10781086

10791087
# Delete an entry from the LDAP directory along with all subordinate entries.

0 commit comments

Comments
 (0)