diff options
author | elijah <elijah@riseup.net> | 2015-09-24 16:56:11 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2015-09-24 16:56:11 -0700 |
commit | c577e3ec23de2ff8b8f8272b687351f62cfcf5ca (patch) | |
tree | e1cc474571922a9e3a60319583d988bf68773661 /lib | |
parent | 26b54adadf7be2a60ecccde57519653fe769efa4 (diff) |
added script destroy-user-db
Diffstat (limited to 'lib')
-rw-r--r-- | lib/leap.rb | 2 | ||||
-rw-r--r-- | lib/leap/server.rb | 11 | ||||
-rw-r--r-- | lib/leap/users.rb | 36 |
3 files changed, 49 insertions, 0 deletions
diff --git a/lib/leap.rb b/lib/leap.rb new file mode 100644 index 0000000..39d2004 --- /dev/null +++ b/lib/leap.rb @@ -0,0 +1,2 @@ +require_relative('leap/server.rb') +require_relative('leap/users.rb')
\ No newline at end of file diff --git a/lib/leap/server.rb b/lib/leap/server.rb new file mode 100644 index 0000000..bc60455 --- /dev/null +++ b/lib/leap/server.rb @@ -0,0 +1,11 @@ +require 'couchrest' + +module LEAP + class Server < CouchRest::Server + def initialize + netrc = File.read('/root/.netrc').split(' ') + auth = "%{username}:%{password}@" % {username: netrc[3], password: netrc[5]} + super("http://#{auth}localhost:5984") + end + end +end
\ No newline at end of file diff --git a/lib/leap/users.rb b/lib/leap/users.rb new file mode 100644 index 0000000..14c9c4e --- /dev/null +++ b/lib/leap/users.rb @@ -0,0 +1,36 @@ +require 'couchrest' + +module LEAP + class Users < CouchRest::Database + + def initialize(server) + super(server, 'users') + end + + def find_by_login(login) + record = self.view('User/by_login', + :reduce => false, + :startkey => login, + :endkey => login + )['rows'].first + if record + return self.get(record['id']) + end + end + + def all_logins + self.view('User/by_login', + :reduce => false + )['rows'].map {|row| + row['key'] + } + end + + def all_active_ids + end + + def all_ids + end + + end +end |