summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2015-03-17 15:06:54 -0700
committerelijah <elijah@riseup.net>2015-03-17 15:06:54 -0700
commit74a8f39a0d91f7f992c41cced01f80f24001e173 (patch)
tree2c459d89ed9d1e284098dc43715db813eab97f27
parent2d42b4a39eaa346b94fa4aa2bb90bebb5621112e (diff)
parent25b34acce7612f58c5d40819de79734b08cdfb8f (diff)
Merge branch 'develop' into version/0.6.1version/0.6.1
Conflicts: Gemfile.lock
-rw-r--r--.ruby-version1
-rw-r--r--Gemfile.lock19
-rw-r--r--README.md18
-rw-r--r--config/default.yaml6
-rw-r--r--lib/tapicero/loop.rb19
-rw-r--r--lib/tapicero_daemon.rb20
-rw-r--r--tapicero.gemspec2
-rw-r--r--test/badconfig.yaml4
-rw-r--r--test/config.yaml7
-rw-r--r--test/integration/tmp_user_test.rb37
-rw-r--r--test/support/integration_test.rb16
-rw-r--r--test/test_helper.rb9
12 files changed, 115 insertions, 43 deletions
diff --git a/.ruby-version b/.ruby-version
new file mode 100644
index 0000000..f3a9c9a
--- /dev/null
+++ b/.ruby-version
@@ -0,0 +1 @@
+1.9.3-p194
diff --git a/Gemfile.lock b/Gemfile.lock
index 4625690..5b033ed 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,19 +1,9 @@
-GIT
- remote: https://github.com/leapcode/couchrest_changes
- revision: 25bd12efbff7be971cc76939a230e82c62b966ef
- branch: master
- specs:
- couchrest_changes (0.1.1)
- couchrest (~> 1.1.3)
- syslog_logger (~> 2.0.0)
- yajl-ruby
-
PATH
remote: .
specs:
- tapicero (0.6)
+ tapicero (0.6.1)
couchrest (~> 1.1.3)
- couchrest_changes (~> 0.1.1)
+ couchrest_changes (= 0.2.0)
daemons
syslog_logger (~> 2.0.0)
yajl-ruby (~> 1.1.0)
@@ -25,6 +15,10 @@ GEM
mime-types (~> 1.15)
multi_json (~> 1.0)
rest-client (~> 1.6.1)
+ couchrest_changes (0.2.0)
+ couchrest (~> 1.1.3)
+ syslog_logger (~> 2.0.0)
+ yajl-ruby
daemons (1.1.9)
highline (1.6.19)
json (1.8.1)
@@ -47,7 +41,6 @@ PLATFORMS
ruby
DEPENDENCIES
- couchrest_changes!
highline
minitest (~> 5.4.0)
mocha
diff --git a/README.md b/README.md
index 665efa4..bf7fb27 100644
--- a/README.md
+++ b/README.md
@@ -101,6 +101,24 @@ the deamon wrapper. You can do this like this:
ruby -I lib lib/tapicero.rb
+Changes
+--------------------
+
+0.6.1
+
+UPGRADING: the config option 'seq_file' is no long used, now 'seq_dir' is used
+(defaults to "/var/run/tapicero").
+
+* prevent username and password from leaking in processlist
+* support for tmp_users database
+
+0.6.0
+
+* do not log error if the db or design doc already exists
+ (since another tapicero instance probably created it)
+* pid now created successfully on server boot
+* don't die when couchdb is restarted
+
License
--------------------
diff --git a/config/default.yaml b/config/default.yaml
index 9ab4e5c..cbf9b54 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -13,9 +13,9 @@ connection:
suffix: ""
# netrc: "/etc/couchdb/couchdb.netrc"
-# file to store the last processed user record in so we can resume after
-# a restart:
-seq_file: "/var/log/leap/tapicero.seq"
+# directory to store the sequence file, which contains the last processed record sequence
+# allow us to resume after a restart
+seq_dir: "/var/run/tapicero"
# Configure log_file like this if you want to log to a file instead of syslog:
# log_file: "/var/log/leap/tapicero.log"
diff --git a/lib/tapicero/loop.rb b/lib/tapicero/loop.rb
new file mode 100644
index 0000000..9c06e52
--- /dev/null
+++ b/lib/tapicero/loop.rb
@@ -0,0 +1,19 @@
+module Tapicero
+ class Loop
+ def listen(db_name)
+ loop do
+ begin
+ users = CouchRest::Changes.new(db_name)
+ UserEventHandler.new(users)
+ users.listen
+ Tapicero.logger.info('Lost contact with couchdb, will try again in 10 seconds')
+ sleep 10
+ rescue SystemCallError => exc
+ Tapicero.logger.info('Problem connecting to couchdb (#{exc}). Will try again in 10 seconds.')
+ sleep 10
+ retry
+ end
+ end
+ end
+ end
+end
diff --git a/lib/tapicero_daemon.rb b/lib/tapicero_daemon.rb
index 86f924e..26f8e00 100644
--- a/lib/tapicero_daemon.rb
+++ b/lib/tapicero_daemon.rb
@@ -5,23 +5,19 @@
# Daemons.run('tapicero_daemon.rb')
#
require 'tapicero'
+require 'tapicero/loop'
require 'extends/couchrest'
require 'tapicero/user_event_handler'
module Tapicero
module Daemon
- while true
- begin
- users = CouchRest::Changes.new('users')
- UserEventHandler.new(users)
- users.listen
- Tapicero.logger.info('Lost contact with couchdb, will try again in 10 seconds')
- sleep 10
- rescue SystemCallError => exc
- Tapicero.logger.info('Problem connecting to couchdb (#{exc}). Will try again in 10 seconds.')
- sleep 10
- retry
- end
+ users_thread = Thread.new do
+ Tapicero::Loop.new.listen('users')
end
+ tmp_users_thread = Thread.new do
+ Tapicero::Loop.new.listen('tmp_users')
+ end
+ users_thread.join
+ tmp_users_thread.join
end
end
diff --git a/tapicero.gemspec b/tapicero.gemspec
index eae60d8..a709ef5 100644
--- a/tapicero.gemspec
+++ b/tapicero.gemspec
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.executables << 'tapicero'
s.add_dependency "couchrest", "~> 1.1.3"
- s.add_dependency "couchrest_changes", "~> 0.1.1"
+ s.add_dependency "couchrest_changes", "= 0.2.0"
s.add_dependency "daemons"
s.add_dependency "yajl-ruby", "~> 1.1.0"
s.add_dependency "syslog_logger", "~> 2.0.0"
diff --git a/test/badconfig.yaml b/test/badconfig.yaml
index 4941806..263185a 100644
--- a/test/badconfig.yaml
+++ b/test/badconfig.yaml
@@ -13,8 +13,6 @@ connection:
prefix: "tapicero_test"
suffix: ""
-# file to store the last processed user record in so we can resume after
-# a restart:
-seq_file: "/tmp/tapicero_test.seq"
+seq_dir: "/tmp/tapicero_test"
log_file: "/tmp/tapicero_test.log"
log_level: debug
diff --git a/test/config.yaml b/test/config.yaml
index 601c104..28da68c 100644
--- a/test/config.yaml
+++ b/test/config.yaml
@@ -12,8 +12,9 @@ connection:
prefix: "tapicero_test"
suffix: ""
-# file to store the last processed user record in so we can resume after
-# a restart:
-seq_file: "/tmp/tapicero_test.seq"
log_file: "/tmp/tapicero_test.log"
log_level: debug
+
+# the directory to store the last processed user record in so
+# we can resume after a restart:
+seq_dir: "/tmp/tapicero"
diff --git a/test/integration/tmp_user_test.rb b/test/integration/tmp_user_test.rb
new file mode 100644
index 0000000..dff8f4e
--- /dev/null
+++ b/test/integration/tmp_user_test.rb
@@ -0,0 +1,37 @@
+require_relative '../test_helper.rb'
+
+class TmpUserTest < Tapicero::IntegrationTest
+
+ def setup
+ TapiceroProcess.run_with_config("test/config.yaml")
+ create_user(false, 'tmp_users')
+ sleep 0.1
+ end
+
+ def teardown
+ delete_user(true, 'tmp_users')
+ end
+
+ def test_creates_user_db
+ assert_database_exists user_database
+ end
+
+ def test_configures_security
+ assert_equal config.options[:security], user_database.get('_security')
+ end
+
+ def test_stores_design_docs
+ assert_equal ['_design/docs', '_design/syncs', '_design/transactions'],
+ design_docs(user_database).map{|doc| doc["id"]}.sort
+ end
+
+ def test_deletes_user_db
+ assert_database_exists user_database
+ delete_user(false, 'tmp_users')
+ assert !host.databases.include?(user_database.name), 'user db must not exist'
+ end
+
+ def design_docs(db)
+ db.documents(startkey: '_design', endkey: '_design'.succ)["rows"]
+ end
+end
diff --git a/test/support/integration_test.rb b/test/support/integration_test.rb
index 552b0a1..86553c2 100644
--- a/test/support/integration_test.rb
+++ b/test/support/integration_test.rb
@@ -5,16 +5,16 @@ module Tapicero
# create a dummy record for the user
# so that tapicero will get a new user event
#
- def create_user(fast = false)
- result = database.save_doc :some => :content
+ def create_user(fast = false, db_name = 'users')
+ result = database(db_name).save_doc :some => :content
raise RuntimeError.new(result.inspect) unless result['ok']
sleep 1 unless fast # allow tapicero to do its job
@user = {'_id' => result["id"], '_rev' => result["rev"]}
end
- def delete_user(fast = false)
+ def delete_user(fast = false, db_name = 'users')
return if @user.nil? or @user['_deleted']
- result = database.delete_doc @user
+ result = database(db_name).delete_doc @user
raise RuntimeError.new(result.inspect) unless result['ok']
@user['_deleted'] = true
sleep 1 unless fast # allow tapicero to do its job
@@ -26,12 +26,12 @@ module Tapicero
puts 'failed to find per user db'
end
- def database
- @database ||= host.database!(database_name)
+ def database(db_name='users')
+ @database ||= host.database!(database_name_with_prefix(db_name))
end
- def database_name
- config.complete_db_name('users')
+ def database_name_with_prefix(db_name)
+ config.complete_db_name(db_name)
end
def host
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 31eaa2b..1442148 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -33,6 +33,15 @@ MiniTest.after_run {
TapiceroProcess.kill!
}
+# delete prior user dbs so they don't fill up the local couchdb.
+CouchRest::Server.new.tap do |server|
+ server.databases.each do |db_name|
+ if db_name =~ /^user-[a-f0-9]{32}$/
+ server.database(db_name).delete!
+ end
+ end
+end
+
puts
puts " REMINDER: check /tmp/tapicero.log for errors"
puts \ No newline at end of file