require 'openssl'
require 'sinatra'
+configure do
+ git_dir = File.join(File.dirname(__FILE__), ".git")
+ if File.directory?(git_dir)
+ head = File.read("#{git_dir}/HEAD").strip.split[-1]
+ @@git_rev = File.read(File.join(git_dir, head))
+ end
+end
+
get '/' do
- content_type 'text/plain; charset=us-ascii'
+ content_type "application/json"
- "Hello from your friendly MSVA."
+ result = { :available => true, :protoversion => 1, :server => "MSVA-Ruby 0.00001" }
+ result[:git_revision] = @@git_rev if @@git_rev
+ result.to_json
end
post '/reviewcert' do
begin
params = JSON.parse(request.body.string)
rescue JSON::ParserError
- halt({ :valid => false, :message => "couldn't parse JSON query"})
+ halt({ :valid => false, :message => "couldn't parse JSON query"}.to_json)
end
unless (params["pkc"] && params["pkc"]["type"] == "x509der")
{ :valid => false, :message => "Just testing!!" }.to_json
end
-get '/noop' do
- { :available => true, :protoversion => 1, :server => "MSVA-Ruby 0.00001" }.to_json
-end
+# TODO: fill in if we need to do so
+# post '/extracerts' do
+# end
+
+not_found do
+ content_type "application/json"
-post '/extracerts' do
- # TODO: fill in if we need to do so
- not_found
+ { :status => 404, :message => "not found" }.to_json
end