Class: Vines::Agent::Config::Domain

Inherits:
Object
  • Object
show all
Defined in:
lib/vines/agent/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Domain

Returns a new instance of Domain.



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/vines/agent/config.rb', line 51

def initialize(name, &block)
  @name, @password, @upstream = name, nil, []
  @conf = File.expand_path('conf')
  instance_eval(&block) if block
  validate_domain(@name)
  raise "password required" unless @password && !@password.strip.empty?
  raise "duplicate upstream connections not allowed" if @upstream.uniq!
  unless @download
    @download = File.expand_path('data')
    FileUtils.mkdir_p(@download)
  end
end

Instance Method Details

#download(dir) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/vines/agent/config.rb', line 72

def download(dir)
  @download = File.expand_path(dir)
  begin
    FileUtils.mkdir_p(@download)
  rescue
    raise "can't create #{@download}"
  end
end

#password(password = nil) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/vines/agent/config.rb', line 64

def password(password=nil)
  if password
    @password = password
  else
    @password
  end
end

#startObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/vines/agent/config.rb', line 86

def start
  base = {
    password: @password,
    domain:   @name,
    download: @download,
    conf:     @conf
  }
  options = @upstream.map do |info|
    base.clone.tap do |opts|
      opts[:host] = info[:host]
      opts[:port] = info[:port]
    end
  end
  # no upstream so use DNS SRV discovery for host and port
  options << base if options.empty?
  options.each do |args|
    Vines::Agent::Connection.new(args).start
  end
end

#upstream(host, port) ⇒ Object



81
82
83
84
# File 'lib/vines/agent/config.rb', line 81

def upstream(host, port)
  raise 'host and port required for upstream connections' unless host && port
  @upstream << {host: host, port: port}
end