entitlements-app 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18a0176e1783a420da17eee12174e9cc6f17224f980e991149743bd2366a1dbc
4
- data.tar.gz: 2acf3be9e885ade8181e3fb47adfc87fbfca609bb9978ca84c9d3b6816ae0ad5
3
+ metadata.gz: 1d78c3e43bb1a892e7d45aa8c1a9c608c26db75f36a8adda13646b5ae9a756dc
4
+ data.tar.gz: afd0505ea8106dbaaa3486e1c2dfab168c6209b97d99322cc6f560a6526f8aab
5
5
  SHA512:
6
- metadata.gz: 73162232f10dca6c007c7ca5025a385d10ff06b809b1a0daace0fcc3dbcba877337b5a191963d173eeb64ff6635a4dd05f05857fb9ed37201f6cb5dfdd541ef9
7
- data.tar.gz: ef9e75e2916d78607a4f963f9661c1b36c48055b97d34f0f6286c2f6ba22324f8241d7775a15f37df4bc2a9ed1d823cba5b6553fd9db6e5c9e5050e1cc1fc0a0
6
+ metadata.gz: 0b1279f7726543ffcaf95228c7b0f831f462bcb05431db9acd195afa01f6f40c00561dd0cb81c3c097c9d75291d87db1c2eb16a237e2ced1b22ac3d00b8967b4
7
+ data.tar.gz: b0f8f91d63df0e79a77bf8e00d39a2403a2281a71dc533f7d45bb0ba476c30f45953f828011006a9533ec2f3f77796859a16d5bd832a2e1d4272f8a598894bb8
@@ -17,9 +17,9 @@ module Entitlements
17
17
  # This keeps the schema happy.
18
18
  attr_reader :binddn, :person_dn_format
19
19
 
20
- # Constructor-like object that ensures only one LDAP object (and hence connection)
21
- # is made for a given LDAP server, for efficiency sake. Takes the same parameters as
22
- # the constructor and returns the same object type.
20
+ # Constructor-like object that ensures only one LDAP service object is made for a
21
+ # given LDAP server. Takes the same parameters as the constructor and returns the
22
+ # same object type.
23
23
  #
24
24
  # addr - URL of LDAP server e.g. ldaps://ldap.example.net:636
25
25
  # binddn - DN to bind with
@@ -80,6 +80,8 @@ module Entitlements
80
80
  @ca_file = ca_file
81
81
  @disable_ssl_verification = disable_ssl_verification
82
82
  @person_dn_format = person_dn_format
83
+ @known_existing_dns = {}
84
+ @known_existing_dns_mutex = Mutex.new
83
85
  end
84
86
 
85
87
  # Read a single entry identified by its DN and return the value. Returns nil if
@@ -119,7 +121,13 @@ module Entitlements
119
121
  downcased_attrs = attrs == "*" ? "*" : attrs.map { |a| a.downcase }
120
122
 
121
123
  result = {}
122
- ldap.search(base: base, filter: filter, attributes: downcased_attrs, scope: scope, return_result: false) do |entry|
124
+ search_succeeded = ldap.search(
125
+ base: base,
126
+ filter: filter,
127
+ attributes: downcased_attrs,
128
+ scope: scope,
129
+ return_result: false
130
+ ) do |entry|
123
131
  result_key = index == :dn ? entry.dn : entry[index]
124
132
  unless result_key
125
133
  raise EntryError, "#{entry.dn} has no value for #{index.inspect}"
@@ -132,6 +140,7 @@ module Entitlements
132
140
 
133
141
  result[result_key] = entry
134
142
  end
143
+ remember_existing_dn(base) if search_succeeded
135
144
 
136
145
  Entitlements.logger.debug "Completed search: #{result.keys.size} result(s)"
137
146
 
@@ -145,6 +154,7 @@ module Entitlements
145
154
  # Returns true if the entry exists, false otherwise.
146
155
  Contract String => C::Bool
147
156
  def exists?(dn)
157
+ return true if known_existing_dn?(dn)
148
158
  read(dn).is_a?(Net::LDAP::Entry)
149
159
  end
150
160
 
@@ -180,7 +190,10 @@ module Entitlements
180
190
 
181
191
  ldap.delete(dn: dn)
182
192
  operation_result = ldap.get_operation_result
183
- return true if operation_result["code"] == 0
193
+ if operation_result["code"] == 0
194
+ forget_dn(dn)
195
+ return true
196
+ end
184
197
  Entitlements.logger.error "Error deleting #{dn}: #{operation_result['message']}"
185
198
  false
186
199
  end
@@ -215,11 +228,24 @@ module Entitlements
215
228
 
216
229
  attr_reader :addr, :bindpw
217
230
 
218
- # The LDAP object is initialized and bound on demand the first time it's called.
231
+ def known_existing_dn?(dn)
232
+ @known_existing_dns_mutex.synchronize { @known_existing_dns.key?(dn) }
233
+ end
234
+
235
+ def remember_existing_dn(dn)
236
+ @known_existing_dns_mutex.synchronize { @known_existing_dns[dn] = true }
237
+ end
238
+
239
+ def forget_dn(dn)
240
+ @known_existing_dns_mutex.synchronize { @known_existing_dns.delete(dn) }
241
+ @dn_cache&.delete(dn)
242
+ end
243
+
244
+ # The LDAP object is initialized and its credentials are validated on demand.
219
245
  #
220
246
  # Takes no arguments.
221
247
  #
222
- # Returns a Net::LDAP object that is connected and bound.
248
+ # Returns a Net::LDAP object configured to connect and bind for each operation.
223
249
  Contract C::None => Net::LDAP
224
250
  def ldap
225
251
  @ldap ||= begin
data/lib/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Entitlements
4
4
  module Version
5
- VERSION = "1.2.2"
5
+ VERSION = "1.2.3"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entitlements-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub, Inc. Security Ops
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-09-08 00:00:00.000000000 Z
11
+ date: 2026-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby