Class: YDIM::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/ydim/server.rb,
lib/ydim/server_config.rb

Constant Summary collapse

SECONDS_IN_DAY =
24*60*60
CONFIG =
RCLConf::RCLConf.new(ARGV, defaults)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, logger) ⇒ Server



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ydim/server.rb', line 23

def initialize(config, logger)
  @serv = Needle::Registry.new
  @serv.register(:auth_server) { 
    auth = RRBA::Server.new
    root = RootUser.new(:root)
    root.name = config.root_name
    root.email = config.root_email
    root_key = config.root_key
    path = File.expand_path(root_key, config.conf_dir)
    path_or_key = File.exist?(path) ? path : root_key
    root.public_key = Util.load_key(path_or_key)
    auth.root = root
    auth
  }
  @serv.register(:clients) {
    ClientHandler.new(@serv)
  }
  @serv.register(:config) {
    config
  }
  @serv.register(:currency_converter) {
    ODBA.cache.fetch_named('currency_converter', self) { 
      CurrencyConverter.new  
    }
  }
  @serv.register(:factory) {
    Factory.new(@serv)
  }
  @serv.register(:id_server) { 
    ODBA.cache.fetch_named('id_server', self) {
      ODBA::IdServer.new
    }
  }
  @serv.register(:logger) {
    logger
  }
  if(hour = config.autoinvoice_hour)
    @autoinvoicer = repeat_at(hour, 'AutoInvoicer') {
      AutoInvoicer.new(@serv).run
    }
  end
  if(hour = config.currency_update_hour)
    if(@serv.currency_converter.known_currencies \
       < @serv.config.currencies.size)
      CurrencyUpdater.new(@serv).run
    end
    @currency_updater = repeat_at(hour, 'CurrencyUpdater') {
      CurrencyUpdater.new(@serv).run
    }
  end
    @status_updater = repeat_at(1, 'StatusUpdater') {
      Invoice.all { |inv| inv.save }
    }
  @sessions = []
end

Class Method Details

.configObject



53
54
55
# File 'lib/ydim/server_config.rb', line 53

def Server.config
  CONFIG
end

Instance Method Details

#login(client, name = nil, &block) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ydim/server.rb', line 78

def (client, name=nil, &block)
  @serv.logger.debug(client.__drburi) { "attempting login" }
  session = @serv.auth_server.authenticate(name, &block)
  session.serv = @serv
  session.client = client
  @serv.logger.info(session.whoami) { 'login' }
  @sessions.push(session)
  session
rescue Exception => error
  @serv.logger.error('unknown user') { 
    [error.class, error.message].join(' - ') }
  raise
end

#logout(session) ⇒ Object



91
92
93
94
95
# File 'lib/ydim/server.rb', line 91

def logout(session)
  @serv.logger.info(session.whoami) { 'logout' }
  @sessions.delete(session)
  nil
end

#pingObject



96
97
98
# File 'lib/ydim/server.rb', line 96

def ping
  true
end