diff options
Diffstat (limited to 'certs/app/models/leap_ca')
-rw-r--r-- | certs/app/models/leap_ca/cert.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/certs/app/models/leap_ca/cert.rb b/certs/app/models/leap_ca/cert.rb index 0c32721..7e4b49a 100644 --- a/certs/app/models/leap_ca/cert.rb +++ b/certs/app/models/leap_ca/cert.rb @@ -17,6 +17,8 @@ module LeapCA property :valid_until, Time # expiration time of the client certificate property :random, Float, :accessible => false # used to help pick a random cert by the webapp + before_validation :set_random, :on => :create + validates :key, :presence => true validates :cert, :presence => true validates :random, :presence => true, :numericality => {:greater_than_or_equal_to => 0, :less_than => 1} @@ -25,6 +27,10 @@ module LeapCA view :by_random end + def set_random + self.random = rand + end + class << self def sample self.by_random.startkey(rand).first || self.by_random.first @@ -40,6 +46,9 @@ module LeapCA raise RECORD_NOT_FOUND end + def valid_attributes_hash + {:key => "ABCD", :cert => "A123"} + end end end |