summaryrefslogtreecommitdiff
path: root/certs/app/models
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-12-17 12:33:15 +0100
committerAzul <azul@leap.se>2012-12-17 12:33:15 +0100
commit251400a1bf4497fd1f26beb89302187d465a5faa (patch)
tree680760fd67d25ab3c4e09ab0a16de1d3996720c6 /certs/app/models
parentd64ab283b7bce0d296bb743f030c5361af663456 (diff)
parenta8f5a1ec486d5ee378f7b820c9f2c046e5c03672 (diff)
Merge branch 'feature/certs-from-ca-deamon' into develop
Conflicts: certs/app/models/leap_ca/cert.rb
Diffstat (limited to 'certs/app/models')
-rw-r--r--certs/app/models/leap_ca/cert.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/certs/app/models/leap_ca/cert.rb b/certs/app/models/leap_ca/cert.rb
index 0c32721..9d4f15e 100644
--- a/certs/app/models/leap_ca/cert.rb
+++ b/certs/app/models/leap_ca/cert.rb
@@ -17,14 +17,21 @@ 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}
+ validates :random, :presence => true
+ validates :random, :numericality => {:greater_than => 0, :less_than => 1}
design do
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 +47,9 @@ module LeapCA
raise RECORD_NOT_FOUND
end
+ def valid_attributes_hash
+ {:key => "ABCD", :cert => "A123"}
+ end
end
end