Class: Cuboid::Rest::Server

Inherits:
Sinatra::Base
  • Object
show all
Extended by:
UI::Output
Defined in:
lib/cuboid/rest/server.rb,
lib/cuboid/rest/server/routes/grid.rb,
lib/cuboid/rest/server/routes/agent.rb,
lib/cuboid/rest/server/instance_helpers.rb,
lib/cuboid/rest/server/routes/instances.rb,
lib/cuboid/rest/server/routes/scheduler.rb

Defined Under Namespace

Modules: InstanceHelpers, Routes

Constant Summary collapse

VALID_REPORT_FORMATS =
%w(json xml yaml html.zip)

Class Method Summary collapse

Methods included from UI::Output

error_buffer, initialize, log_error, output_provider_file, print_bad, print_debug, print_error, print_info, print_line, print_ok, print_status, print_verbose, reroute_to_file, reroute_to_file?

Methods included from UI::OutputInterface

initialize

Methods included from UI::OutputInterface::Personalization

#included

Methods included from UI::OutputInterface::Controls

#debug?, #debug_level, #debug_level_1?, #debug_level_2?, #debug_level_3?, #debug_level_4?, #debug_off, #debug_on, initialize, #verbose?, #verbose_off, #verbose_on

Methods included from UI::OutputInterface::ErrorLogging

#error_logfile, #has_error_log?, initialize, #set_error_logfile

Methods included from UI::OutputInterface::Implemented

#print_debug_backtrace, #print_debug_exception, #print_debug_level_1, #print_debug_level_2, #print_debug_level_3, #print_debug_level_4, #print_error_backtrace, #print_exception

Methods included from UI::OutputInterface::Abstract

#output_provider_file, #print_bad, #print_debug, #print_error, #print_info, #print_line, #print_ok, #print_status, #print_verbose

Class Method Details

.resetObject



115
116
117
118
# File 'lib/cuboid/rest/server.rb', line 115

def reset
    @@instances.clear
    @@agents.clear
end

.run!(options) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/cuboid/rest/server.rb', line 120

def run!( options )
    set :username, options[:username]
    set :password, options[:password]

    server = Puma::Server.new( self )

    ssl = false
    if options[:ssl_key] && options[:ssl_certificate]
        ctx = Puma::MiniSSL::Context.new

        ctx.key  = options[:ssl_key]
        ctx.cert = options[:ssl_certificate]

        if options[:ssl_ca]
            puts 'CA provided, peer verification has been enabled.'

            ctx.ca          = options[:ssl_ca]
            ctx.verify_mode = Puma::MiniSSL::VERIFY_PEER |
                Puma::MiniSSL::VERIFY_FAIL_IF_NO_PEER_CERT
        else
            puts 'CA missing, peer verification has been disabled.'
        end

        ssl = true
        server.binder.add_ssl_listener( options[:bind], options[:port], ctx )
    else
        ssl = false
        server.add_tcp_listener( options[:bind], options[:port] )
    end

    puts "Listening on http#{'s' if ssl}://#{options[:bind]}:#{options[:port]}"

    begin
        server.run.join
    rescue Interrupt
        server.stop( true )
    end
end