summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2012-09-11 15:47:00 +0200
committerAzul <azul@riseup.net>2012-09-11 15:47:00 +0200
commit2d124b74538f19681c619e4a807f60176ab2d869 (patch)
tree59fb7bcfb85f255fe2be7363ef331bc3cb9ef390
parentc0fc5ac5b5d955b1789a58153952e43bb7052b07 (diff)
Filling the pool with up to 10 certs
-rw-r--r--config/pool.yml1
-rw-r--r--leap_ca.rb6
-rw-r--r--lib/cert.rb3
-rw-r--r--lib/pool.rb19
4 files changed, 29 insertions, 0 deletions
diff --git a/config/pool.yml b/config/pool.yml
new file mode 100644
index 0000000..29ccbbf
--- /dev/null
+++ b/config/pool.yml
@@ -0,0 +1 @@
+size: 10
diff --git a/leap_ca.rb b/leap_ca.rb
index f961a3c..57bf067 100644
--- a/leap_ca.rb
+++ b/leap_ca.rb
@@ -5,14 +5,20 @@ require 'yajl/http_stream'
require 'lib/cert'
require 'lib/couch_stream'
require 'lib/couch_changes'
+require 'lib/pool'
def main
puts "Tracking #{Cert.database.root}"
couch = CouchStream.new(Cert.database.root)
changes = CouchChanges.new(couch)
+ pool = LeapCA::Pool.new(File.expand_path("../config/pool.yml", __FILE__))
+ pool.fill
changes.follow do |hash|
p hash
+ if hash[:deleted]
+ pool.fill
+ end
end
end
diff --git a/lib/cert.rb b/lib/cert.rb
index c937fb8..80adfbb 100644
--- a/lib/cert.rb
+++ b/lib/cert.rb
@@ -15,6 +15,9 @@ class Cert < CouchRest::Model::Base
validates :zipped, :presence => true
+ design do
+ end
+
def set_random
self.random = rand
end
diff --git a/lib/pool.rb b/lib/pool.rb
new file mode 100644
index 0000000..76c1963
--- /dev/null
+++ b/lib/pool.rb
@@ -0,0 +1,19 @@
+require 'yaml'
+
+module LeapCA
+ class Pool
+ def initialize(filename)
+ @config = YAML.load(File.open(filename, 'r'))
+ end
+
+ def fill
+ while Cert.count < self.size do
+ Cert.create!
+ end
+ end
+
+ def size
+ @config[:size] ||= 10
+ end
+ end
+end