Class: Vines::Agent::Connection
- Inherits:
-
Object
- Object
- Vines::Agent::Connection
- Includes:
- Log
- Defined in:
- lib/vines/agent/connection.rb
Overview
Connects the agent process to the chat server and provides service discovery and command execution abilities. Users are authorized against an access control list before being allowed to run commands.
Constant Summary collapse
- NS =
'http://getvines.com/protocol'.freeze
- SYSTEMS =
'http://getvines.com/protocol/systems'.freeze
Instance Method Summary collapse
-
#initialize(options) ⇒ Connection
constructor
A new instance of Connection.
- #start ⇒ Object
Constructor Details
#initialize(options) ⇒ Connection
Returns a new instance of Connection.
15 16 17 18 19 20 21 22 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 |
# File 'lib/vines/agent/connection.rb', line 15 def initialize() domain, password, host, port, download, conf = *.values_at(:domain, :password, :host, :port, :download, :conf) certs = File.('certs', conf) , @services, @sessions, @component = {}, {}, {}, nil @ready = false jid = Blather::JID.new(fqdn, domain, 'vines') @stream = Blather::Client.setup(jid, password, host, port, certs) @stream.register_handler(:stream_error) do |e| log.error(e.) true # prevent EM.stop end @stream.register_handler(:disconnected) do log.info("Stream disconnected, reconnecting . . .") EM::Timer.new(rand(16) + 5) do self.class.new().start end true # prevent EM.stop end @stream.register_handler(:ready) do # prevent handler called twice unless @ready log.info("Connected #{@stream.jid} agent to #{host}:#{port}") log.warn("Agent must run as root user to allow user switching") unless root? @ready = true startup end end @stream.register_handler(:subscription, :request?) do |node| # ignore, rather than refuse, requests from users lacking # permissions, so agents are invisible to them @stream.write(node.approve!) if valid_user?(node.from) end @stream.register_handler(:file_transfer) do |iq| transfer_file(iq) end @stream.register_handler(:disco_info, :get?) do |node| disco_info(node) end @stream.register_handler(:iq, '/iq[@type="set"]/ns:query', :ns => SYSTEMS) do |node| (node) end @stream.register_handler(:iq, '/iq[@type="get"]/ns:query', :ns => 'jabber:iq:version') do |node| version(node) end @stream.register_handler(:message, :chat?, :body) do |msg| (msg) end end |
Instance Method Details
#start ⇒ Object
76 77 78 |
# File 'lib/vines/agent/connection.rb', line 76 def start @stream.run end |