-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
76 lines (60 loc) · 1.22 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require 'sinatra'
require 'rack/ssl'
require 'librato-rack'
class Deploy
attr_reader :source
attr_reader :head
attr_reader :user
attr_reader :url
def initialize(source, params)
@source = source
@head = params.fetch('head_long')
@user = params.fetch('user')
@url = params.fetch('url')
@time = Time.now
end
def short_head
head.slice(0,7)
end
def label
"deployed v#{short_head}"
end
def description
"#{user} deployed #{short_head} to #{source}"
end
def start_time
@time.to_i
end
def end_time
@time.to_i
end
def report!
Librato::Metrics.annotate :deployments, label,
source: source,
description: description,
start_time: start_time,
end_time: end_time,
links: [
{rel: 'app', href: url }
]
end
end
# --
configure do
STDOUT.sync = true
Librato::Metrics.authenticate ENV['LIBRATO_USER'], ENV['LIBRATO_TOKEN']
end
configure :production do
use Rack::SSL
end
get '/ping' do
content_type :text
"PONG\n"
end
post '/:source' do |source|
halt(401, "Not authorized\n") unless params[:secret] == ENV['SECRET']
deploy = Deploy.new(source, params)
deploy.report!
content_type :text
'ok'
end