diff options
Diffstat (limited to 'lib/leap_ca/cert.rb')
-rw-r--r-- | lib/leap_ca/cert.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/leap_ca/cert.rb b/lib/leap_ca/cert.rb index 0587a54..8f1c9e9 100644 --- a/lib/leap_ca/cert.rb +++ b/lib/leap_ca/cert.rb @@ -32,6 +32,22 @@ module LeapCA view :by_random end + class << self + def sample + self.by_random.startkey(rand).first || self.by_random.first + end + + def pick_from_pool + cert = self.sample + raise RECORD_NOT_FOUND unless cert + cert.destroy + return cert + rescue RESOURCE_NOT_FOUND + retry if self.by_random.count > 0 + raise RECORD_NOT_FOUND + end + end + # # generate the private key and client certificate # |