Class: Harbor::HostAgent::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/harbor/host_agent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:, bearer_token:, bind: DEFAULT_BIND, port: DEFAULT_PORT, logger: nil) ⇒ Server

Returns a new instance of Server.

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
43
44
45
# File 'lib/harbor/host_agent.rb', line 36

def initialize(config:, bearer_token:, bind: DEFAULT_BIND, port: DEFAULT_PORT, logger: nil)
  raise ArgumentError, "bearer_token is required" if bearer_token.nil? || bearer_token.empty?

  @config = config
  @bearer_token = bearer_token
  @bind = bind
  @port = port
  @logger = logger || WEBrick::Log.new($stderr, WEBrick::Log::INFO)
  @tools = Harbor::Tools.new(config)
end

Instance Attribute Details

#bindObject (readonly)

Returns the value of attribute bind.



34
35
36
# File 'lib/harbor/host_agent.rb', line 34

def bind
  @bind
end

#portObject (readonly)

Returns the value of attribute port.



34
35
36
# File 'lib/harbor/host_agent.rb', line 34

def port
  @port
end

Instance Method Details

#runObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/harbor/host_agent.rb', line 47

def run
  @webrick = WEBrick::HTTPServer.new(
    BindAddress: @bind,
    Port: @port,
    Logger: @logger,
    AccessLog: []
  )
  mount_routes
  trap_signals
  @webrick.start
end

#stopObject



59
60
61
# File 'lib/harbor/host_agent.rb', line 59

def stop
  @webrick&.shutdown
end