From 1bac88549fc3bfda81e04b2811443a301aa9e781 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 20 Sep 2012 13:15:33 +0200 Subject: moved files into own dir and added main leap_ca.rb Also updated the couchdb.yml.example with more meaningful content --- bin/leap_ca | 10 ++++------ config/couchdb.yml.example | 12 +++++------- lib/cert.rb | 37 ------------------------------------- lib/couch_changes.rb | 17 ----------------- lib/couch_stream.rb | 21 --------------------- lib/leap_ca.rb | 4 ++++ lib/leap_ca/cert.rb | 37 +++++++++++++++++++++++++++++++++++++ lib/leap_ca/couch_changes.rb | 17 +++++++++++++++++ lib/leap_ca/couch_stream.rb | 21 +++++++++++++++++++++ lib/leap_ca/pool.rb | 19 +++++++++++++++++++ lib/pool.rb | 19 ------------------- 11 files changed, 107 insertions(+), 107 deletions(-) delete mode 100644 lib/cert.rb delete mode 100644 lib/couch_changes.rb delete mode 100644 lib/couch_stream.rb create mode 100644 lib/leap_ca.rb create mode 100644 lib/leap_ca/cert.rb create mode 100644 lib/leap_ca/couch_changes.rb create mode 100644 lib/leap_ca/couch_stream.rb create mode 100644 lib/leap_ca/pool.rb delete mode 100644 lib/pool.rb diff --git a/bin/leap_ca b/bin/leap_ca index baefff2..f999238 100755 --- a/bin/leap_ca +++ b/bin/leap_ca @@ -1,19 +1,17 @@ #!/usr/bin/ruby +LEAP_CA_ROOT = File.expand_path('../..', __FILE__) +$:.unshift File.expand_path('lib', LEAP_CA_ROOT) require 'rubygems' require 'daemons' require 'yajl/http_stream' -require 'lib/cert' -require 'lib/couch_stream' -require 'lib/couch_changes' -require 'lib/pool' - +require 'leap_ca' 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 = LeapCA::Pool.new(File.expand_path("config/pool.yml", LEAP_CA_ROOT)) pool.fill Daemons.run_proc('leap_ca.rb') do changes.follow do |hash| diff --git a/config/couchdb.yml.example b/config/couchdb.yml.example index 1dd5fef..64058da 100644 --- a/config/couchdb.yml.example +++ b/config/couchdb.yml.example @@ -1,8 +1,6 @@ development: - protocol: 'https' - host: sample.cloudant.com - port: 443 - prefix: project - suffix: test - username: test - password: user + protocol: 'http' + host: 'localhost' + port: 5984 + prefix: leap_web_demo + suffix: '' diff --git a/lib/cert.rb b/lib/cert.rb deleted file mode 100644 index 80adfbb..0000000 --- a/lib/cert.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'couchrest_model' - -class Cert < CouchRest::Model::Base - - use_database 'certs' - - timestamps! - - property :random, Float, :accessible => false - - before_validation :set_random, :attach_zip, :on => :create - - validates :random, :presence => true, - :numericality => {:greater_than => 0, :less_than => 1} - - validates :zipped, :presence => true - - design do - end - - def set_random - self.random = rand - end - - def attach_zip - self.create_attachment :file => StringIO.new("dummy cert"), :name => zipname - end - - def zipname - 'cert.zip' - end - - def zipped - attachments[zipname] - end - -end diff --git a/lib/couch_changes.rb b/lib/couch_changes.rb deleted file mode 100644 index 59209a4..0000000 --- a/lib/couch_changes.rb +++ /dev/null @@ -1,17 +0,0 @@ -class CouchChanges - def initialize(stream) - @stream = stream - end - - def last_seq - @stream.get "_changes", :limit => 1, :descending => true do |hash| - return hash[:last_seq] - end - end - - def follow - @stream.get "_changes", :feed => :continuous, :since => last_seq do |hash| - yield(hash) - end - end -end diff --git a/lib/couch_stream.rb b/lib/couch_stream.rb deleted file mode 100644 index ed56db2..0000000 --- a/lib/couch_stream.rb +++ /dev/null @@ -1,21 +0,0 @@ -class CouchStream - def initialize(database_url) - @database_url = database_url - end - - def get(path, options) - url = url_for(path, options) - # puts url - Yajl::HttpStream.get(url, :symbolize_keys => true) do |hash| - yield(hash) - end - end - - protected - - def url_for(path, options = {}) - url = [@database_url, path].join('/') - url += '?' if options.any? - url += options.map {|k,v| "#{k}=#{v}"}.join('&') - end -end diff --git a/lib/leap_ca.rb b/lib/leap_ca.rb new file mode 100644 index 0000000..9720c81 --- /dev/null +++ b/lib/leap_ca.rb @@ -0,0 +1,4 @@ +require 'leap_ca/cert' +require 'leap_ca/couch_stream' +require 'leap_ca/couch_changes' +require 'leap_ca/pool' diff --git a/lib/leap_ca/cert.rb b/lib/leap_ca/cert.rb new file mode 100644 index 0000000..80adfbb --- /dev/null +++ b/lib/leap_ca/cert.rb @@ -0,0 +1,37 @@ +require 'couchrest_model' + +class Cert < CouchRest::Model::Base + + use_database 'certs' + + timestamps! + + property :random, Float, :accessible => false + + before_validation :set_random, :attach_zip, :on => :create + + validates :random, :presence => true, + :numericality => {:greater_than => 0, :less_than => 1} + + validates :zipped, :presence => true + + design do + end + + def set_random + self.random = rand + end + + def attach_zip + self.create_attachment :file => StringIO.new("dummy cert"), :name => zipname + end + + def zipname + 'cert.zip' + end + + def zipped + attachments[zipname] + end + +end diff --git a/lib/leap_ca/couch_changes.rb b/lib/leap_ca/couch_changes.rb new file mode 100644 index 0000000..59209a4 --- /dev/null +++ b/lib/leap_ca/couch_changes.rb @@ -0,0 +1,17 @@ +class CouchChanges + def initialize(stream) + @stream = stream + end + + def last_seq + @stream.get "_changes", :limit => 1, :descending => true do |hash| + return hash[:last_seq] + end + end + + def follow + @stream.get "_changes", :feed => :continuous, :since => last_seq do |hash| + yield(hash) + end + end +end diff --git a/lib/leap_ca/couch_stream.rb b/lib/leap_ca/couch_stream.rb new file mode 100644 index 0000000..ed56db2 --- /dev/null +++ b/lib/leap_ca/couch_stream.rb @@ -0,0 +1,21 @@ +class CouchStream + def initialize(database_url) + @database_url = database_url + end + + def get(path, options) + url = url_for(path, options) + # puts url + Yajl::HttpStream.get(url, :symbolize_keys => true) do |hash| + yield(hash) + end + end + + protected + + def url_for(path, options = {}) + url = [@database_url, path].join('/') + url += '?' if options.any? + url += options.map {|k,v| "#{k}=#{v}"}.join('&') + end +end diff --git a/lib/leap_ca/pool.rb b/lib/leap_ca/pool.rb new file mode 100644 index 0000000..76c1963 --- /dev/null +++ b/lib/leap_ca/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 diff --git a/lib/pool.rb b/lib/pool.rb deleted file mode 100644 index 76c1963..0000000 --- a/lib/pool.rb +++ /dev/null @@ -1,19 +0,0 @@ -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 -- cgit v1.2.3