backstop-deploys 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +31 -0
- data/Rakefile +7 -0
- data/backstop-deploys.gemspec +23 -0
- data/lib/backstop-deploys/config.rb +19 -0
- data/lib/backstop-deploys/version.rb +5 -0
- data/lib/backstop-deploys/web.rb +46 -0
- data/lib/backstop-deploys.rb +9 -0
- data/spec/backstop-deploys/web_spec.rb +75 -0
- data/spec/spec_helper.rb +9 -0
- metadata +127 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Michael Gorsuch
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Backstop::Deploys
|
2
|
+
|
3
|
+
An extension to backstop to allow submission to Librato Metrics
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'backstop-deploys'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install backstop-deploys
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Run `Backstop::Deploys::Web` in your rack application.
|
22
|
+
|
23
|
+
Assumes the pressence of `LIBRATO_EMAIL` and `LIBRATO_KEY` in `ENV`.
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/backstop-deploys/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Michael Gorsuch"]
|
6
|
+
gem.email = ["michael.gorsuch@gmail.com"]
|
7
|
+
gem.description = %q{An extension to backstop to allow submission to Librato Metrics}
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.homepage = 'https://github.com/gorsuch/backstop-deploys'
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = 'backstop-deploys'
|
15
|
+
gem.require_paths = ['lib']
|
16
|
+
gem.version = Backstop::Deploys::VERSION
|
17
|
+
gem.add_development_dependency('rack-test')
|
18
|
+
gem.add_development_dependency('rake')
|
19
|
+
gem.add_development_dependency('rspec')
|
20
|
+
gem.add_development_dependency('webmock')
|
21
|
+
gem.add_dependency('rest-client')
|
22
|
+
gem.add_dependency('sinatra')
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Backstop
|
2
|
+
module Deploys
|
3
|
+
module Config
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def env!(key)
|
7
|
+
ENV(key) || raise("#{key} not found in ENV")
|
8
|
+
end
|
9
|
+
|
10
|
+
def librato_email
|
11
|
+
env!('LIBRATO_EMAIL')
|
12
|
+
end
|
13
|
+
|
14
|
+
def librato_key
|
15
|
+
env!('LIBRATO_KEY')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Backstop
|
2
|
+
module Deploys
|
3
|
+
class Web < Sinatra::Base
|
4
|
+
helpers do
|
5
|
+
def api_user
|
6
|
+
CGI.escape(Config.librato_email)
|
7
|
+
end
|
8
|
+
|
9
|
+
def api_pass
|
10
|
+
Config.librato_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def api_endpoint
|
14
|
+
"https://#{api_user}:#{api_pass}@metrics-api.librato.com/v1"
|
15
|
+
end
|
16
|
+
|
17
|
+
def parse_id(id)
|
18
|
+
id.split('.')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
put '/deploys/:id' do |id|
|
23
|
+
app, version, start_time = parse_id(id)
|
24
|
+
halt [400, {:message => ':id should be in the format of app.version.epoch'}.to_json] if app.nil? or version.nil? or start_time.nil?
|
25
|
+
end_time = params[:end_time]
|
26
|
+
halt [400, {:message => ':source is a required param'}.to_json] unless source = params[:source]
|
27
|
+
json = RestClient.get "#{api_endpoint}/annotations/deploys", :params => {'sources[0]' => source, :start_time => start_time}
|
28
|
+
data = JSON.parse(json)
|
29
|
+
|
30
|
+
if events = data['events'].first
|
31
|
+
# events already exists, we just need to update
|
32
|
+
event = events[source].first
|
33
|
+
event_id = event['id']
|
34
|
+
payload = { :title => "#{app}.#{version}" }
|
35
|
+
payload[:end_time] = params[:end_time] if params[:end_time]
|
36
|
+
RestClient.put "#{api_endpoint}/annotations/deploys/#{event_id}", payload
|
37
|
+
else
|
38
|
+
# new event needs to be created
|
39
|
+
payload = { :start_time => start_time, :title => "#{app}.#{version}" }
|
40
|
+
payload[:end_time] = end_time if end_time
|
41
|
+
RestClient.put "#{api_endpoint}/annotations/deploys", "title=#{app}.#{version}&start_time=#{start_time}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rack/test'
|
3
|
+
|
4
|
+
describe Backstop::Deploys::Web do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
def app
|
8
|
+
Backstop::Deploys::Web
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:librato_email) { 'foo@foo.com' }
|
12
|
+
let(:librato_key) { '12345' }
|
13
|
+
let(:api_endpoint) { "https://#{CGI.escape(librato_email)}:#{librato_key}@metrics-api.librato.com/v1" }
|
14
|
+
let(:app_name) { 'foo' }
|
15
|
+
let(:version) { 'v75' }
|
16
|
+
let(:t) { Time.now }
|
17
|
+
let(:id) { "#{app_name}.#{version}.#{t.to_i}" }
|
18
|
+
let(:title) { "#{app_name}.#{version}" }
|
19
|
+
let(:source) { 'test' }
|
20
|
+
let(:params) { {:source => source} }
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
Backstop::Deploys::Config.stub(:librato_email) { librato_email }
|
24
|
+
Backstop::Deploys::Config.stub(:librato_key) { librato_key }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'PUT /deploys/:id' do
|
28
|
+
context 'with proper id' do
|
29
|
+
context 'with source' do
|
30
|
+
|
31
|
+
context 'existing annotation' do
|
32
|
+
let(:event_id) { 12345 }
|
33
|
+
let(:stub_events) { [{:title => title, :source => source, :start_time => t.to_i, :id => event_id}] }
|
34
|
+
let(:stub_get_existing_body) { {:name => 'deploys', :events => [{source => stub_events}]} }
|
35
|
+
let(:stub_get_existing_request) { stub_request(:get, "#{api_endpoint}/annotations/deploys").with(:query => { :sources => [source], :start_time => t.to_i }).to_return(:body => stub_get_existing_body.to_json)}
|
36
|
+
let(:stub_update_request) { stub_request(:put, "#{api_endpoint}/annotations/deploys/#{event_id}").with(:body => {:title => title}) }
|
37
|
+
before(:each) do
|
38
|
+
stub_get_existing_request
|
39
|
+
stub_update_request
|
40
|
+
put "/deploys/#{id}", params
|
41
|
+
end
|
42
|
+
it('should ask Librato for the proper annotation') { stub_get_existing_request.should have_been_made.once }
|
43
|
+
it('should update the existing annotation') { stub_update_request.should have_been_made.once }
|
44
|
+
it('should return a 200') { last_response.status.should eq(200) }
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'non-existent annotation' do
|
48
|
+
let(:stub_get_missing_body) { {:name => 'deploys', :events => []} }
|
49
|
+
let(:stub_get_missing_request) { stub_request(:get, "#{api_endpoint}/annotations/deploys").with(:query => { :sources => [source], :start_time => t.to_i }).to_return(:body => stub_get_missing_body.to_json)}
|
50
|
+
let(:stub_new_request) { stub_request(:put, "#{api_endpoint}/annotations/deploys").with(:body => "title=#{title}&start_time=#{t.to_i}") }
|
51
|
+
before(:each) do
|
52
|
+
stub_get_missing_request
|
53
|
+
stub_new_request
|
54
|
+
put "/deploys/#{id}", params
|
55
|
+
end
|
56
|
+
it('should ask Librato for the proper annotation') { stub_get_missing_request.should have_been_made.once }
|
57
|
+
it('should create a new annotation') { stub_new_request.should have_been_made.once }
|
58
|
+
it('should be 200') { last_response.status.should eq(200) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'without source' do
|
63
|
+
before(:each) { put "/deploys/#{id}", { :foo => :bar } }
|
64
|
+
it('should return a 400') { last_response.status.should eq(400) }
|
65
|
+
it('should return a proper error message') { JSON.parse(last_response.body).has_key?('message') }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'with improperly formatted id' do
|
70
|
+
before(:each) { put "/deploys/foo.bar", params }
|
71
|
+
it('should return a 400') { last_response.status.should eq(400) }
|
72
|
+
it('should return a proper error message') { JSON.parse(last_response.body).has_key?('message') }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: backstop-deploys
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael Gorsuch
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack-test
|
16
|
+
requirement: &70107264443520 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70107264443520
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &70107264442900 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70107264442900
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70107264442340 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70107264442340
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: webmock
|
49
|
+
requirement: &70107264441740 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70107264441740
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rest-client
|
60
|
+
requirement: &70107264441120 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70107264441120
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sinatra
|
71
|
+
requirement: &70107264440700 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70107264440700
|
80
|
+
description: An extension to backstop to allow submission to Librato Metrics
|
81
|
+
email:
|
82
|
+
- michael.gorsuch@gmail.com
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files: []
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- .rspec
|
89
|
+
- Gemfile
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- backstop-deploys.gemspec
|
94
|
+
- lib/backstop-deploys.rb
|
95
|
+
- lib/backstop-deploys/config.rb
|
96
|
+
- lib/backstop-deploys/version.rb
|
97
|
+
- lib/backstop-deploys/web.rb
|
98
|
+
- spec/backstop-deploys/web_spec.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
homepage: https://github.com/gorsuch/backstop-deploys
|
101
|
+
licenses: []
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.8.10
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: An extension to backstop to allow submission to Librato Metrics
|
124
|
+
test_files:
|
125
|
+
- spec/backstop-deploys/web_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
has_rdoc:
|