Sha256: 8665c47ace3d8a60c4c809cb1f788c8333c80ec2811c6200ebdd90bbc3abedbb
Contents?: true
Size: 1.21 KB
Versions: 11
Compression:
Stored size: 1.21 KB
Contents
require 'sinatra' require 'webrick' require 'webrick/https' require 'webrick/ssl' require 'openssl' require 'json' class KL::Api < Sinatra::Base before do halt 503 if !KL.server_registered pass if ['ping'].include? request.path_info.split('/')[1] if env['HTTP_AUTHORIZATION'] && env['HTTP_AUTHORIZATION'].split(':').length == 2 auth_header = env['HTTP_AUTHORIZATION'].split(':') else halt 401 end public_key = auth_header[0] signature = auth_header[1] registry = KL.getRegistryData halt 403 if public_key != registry['server'] data = request.path data = "#{data}?#{request.query_string}" if request.query_string != "" if ['POST', 'PUT', 'PATCH'].include? request.request_method request.body.rewind data += request.body.read end computed_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), registry['agent'], data) if computed_signature == signature KL.logger.info "[api] #{request.request_method} #{request.path}" pass else halt 403 end end get '/ping' do KL.logger.info "[api] Pong! to #{request.ip}" 'Pong: ' + `date` end get '/api/v1/applications' do KL.publish_json(KL.Request_getDockerListAllApplications) end end
Version data entries
11 entries across 11 versions & 1 rubygems