This repository has been archived on 2020-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
ildus/lib/ildus/server/backend.rb
paul 7b7b4c6631 Added support for a commit hook:
* Transformed the config a bit.
  * Added Backend::Basic#commit, call commit when one or more updates are
    performed by the backend.
  * Implemented commit for the LDAPv3 backend updating the serial and
    calling an optional hook.
  * Style fixes.


git-svn-id: svn+ssh://svn.luon.net/svn/ildus/trunk@11 65a33f86-aa00-0410-91be-cd1bf5efb309
2005-11-01 15:12:51 +00:00

124 lines
2.6 KiB
Ruby

# = ildus/server/backend - generic server backend library
#
# Copyright (C) 2005 Paul van Tilburg <paul@luon.net>
#
# Ildus is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
require 'singleton'
module Ildus
class Server
module Backend
BackendClasses = Hash.new
class << self
def load
path = File.dirname(__FILE__)
Dir["#{path}/backends/**/*.rb"].each { |file| require file }
end
def get(type)
BackendClasses[type.to_sym]
end
alias_method :[], :get
def register(type, backend_class)
if BackendClasses.include? type
raise "type #{type} already registered"
end
BackendClasses[type] = backend_class
end
end # self
class Basic
attr_reader :config, :user, :pass
def self.inherited(subclass)
diff = subclass.to_s.split('::') - self.to_s.split('::')
type = diff.to_s.split('::').last.downcase.to_sym
Backend.register(type, subclass)
end
def initialize(backend_config)
@config = backend_config
@auth = false
@user = user
@pass = pass
end
#################
# Account methods
def user=(username)
@user = username
end
def pass=(password)
@pass = password
authenticate
end
def authenticated?
@auth
end
#################
# Backend methods
def commit
raise Handler::NotImplementedError
end
def authenticate
raise Handler::NotImplementedError
end
def register_account
raise Handler::NotImplementedError
end
def unregister_account
raise Handler::NotImplementedError
end
def hosts
raise Handler::NotImplementedError
end
def add_host(host)
raise Handler::NotImplementedError
end
def remove_host(host)
raise Handler::NotImplementedError
end
def update_host(host, addr)
raise Handler::NotImplementedError
end
def add_alias(new_alias, host)
raise Handler::NotImplementedError
end
def remove_alias(old_alias, host)
raise Handler::NotImplementedError
end
end # class Basic
end # module Backend
end # class Server
end # module Ildus