capistrano-fastly 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-fastly.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec'
7
+ gem 'vcr'
8
+ gem 'webmock', '< 1.10'
9
+ gem 'rake'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dave Konopka
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,42 @@
1
+ # Capistrano::Fastly [![Build Status](https://travis-ci.org/articulate/capistrano-fastly.png?branch=master)](https://travis-ci.org/articulate/capistrano-fastly)
2
+
3
+ Capistrano tasks for interacting with [Fastly](http://www.fastly.com/), a CDN/caching service.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano-fastly'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano-fastly
18
+
19
+ ## Usage
20
+
21
+ The only task at the moment is `purge_all` which flushes the entire cache for a single site.
22
+
23
+ Add this to your deploy.rb file with your real service id and api key:
24
+
25
+ require 'capistrano/fastly'
26
+
27
+ set :fastly_config, {
28
+ :service_id => '----',
29
+ :api_key => '----'
30
+ }
31
+
32
+ Then you'll be able to call this task directly:
33
+
34
+ cap fastly:purge_all
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/fastly/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "capistrano-fastly"
8
+ gem.version = Capistrano::Fastly::VERSION
9
+ gem.authors = ["Dave Konopka"]
10
+ gem.email = ["dkonopka@articulate.com"]
11
+ gem.description = %q{Capistrano extensions for Fastly CDN service.}
12
+ gem.summary = %q{Execute Fastly api calls as part of your Capistrano deploys.}
13
+ gem.homepage = "https://github.com/articulate/capistrano-fastly"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'capistrano', '>= 2.0'
21
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Fastly
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+ require 'capistrano'
2
+ require 'capistrano/fastly/version'
3
+ require 'net/https'
4
+
5
+ module Capistrano
6
+ module Fastly
7
+ def self.load_into(configuration)
8
+ configuration.load do
9
+
10
+ namespace :fastly do
11
+ desc 'Purge entire Fastly cache'
12
+ task :purge_all do
13
+ raise(Capistrano::Error, 'Fastly configuration is not set') unless fetch(:fastly_config).kind_of?(Hash)
14
+
15
+ uri = URI.parse("https://api.fastly.com")
16
+ http = Net::HTTP.new(uri.host, uri.port)
17
+ http.use_ssl = true
18
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
19
+ request = Net::HTTP::Post.new("/service/#{fastly_config[:service_id]}/purge_all")
20
+ request.add_field('Content-Type', 'application/json')
21
+ request.add_field('X-Fastly-Key', fastly_config[:api_key])
22
+ request.body = ""
23
+ response = http.request(request)
24
+
25
+ if response.kind_of? Net::HTTPSuccess
26
+ logger.info('Fastly cache purge all complete.')
27
+ else
28
+ logger.info("Fastly cache purge failed: #{response.body}")
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ if Capistrano::Configuration.instance
38
+ Capistrano::Fastly.load_into(Capistrano::Configuration.instance)
39
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capistrano::Fastly do
4
+ before do
5
+ @capistrano = Capistrano::Configuration.new
6
+ Capistrano::Fastly.load_into(@capistrano)
7
+ @fastly_config = {
8
+ :service_id => 'XXXXXXXXXXXXXXXXXXXXX',
9
+ :api_key => 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
10
+ }
11
+ end
12
+
13
+ context 'purge_all' do
14
+ it 'is present' do
15
+ @capistrano.find_task('fastly:purge_all').should_not == nil
16
+ end
17
+
18
+ it 'fails without Fastly configuration values' do
19
+ @capistrano.set(:fastly_config, nil)
20
+ expect { @capistrano.find_and_execute_task('fastly:purge_all') }.to raise_error(Capistrano::Error, 'Fastly configuration is not set')
21
+ end
22
+
23
+ it 'completes with Fastly configuration values' do
24
+ @capistrano.set(:fastly_config, @fastly_config)
25
+ VCR.use_cassette('fastly_purge_all') do
26
+ expect { @capistrano.find_and_execute_task('fastly:purge_all') }.to_not raise_error
27
+ end
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.fastly.com/service/XXXXXXXXXXXXXXXXXXXXX/purge_all
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*'
12
+ User-Agent:
13
+ - Ruby
14
+ Content-Type:
15
+ - application/json
16
+ X-Fastly-Key:
17
+ - YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Wed, 24 Apr 2013 17:17:05 GMT
25
+ Status:
26
+ - 200 OK
27
+ X-Frame-Options:
28
+ - sameorigin
29
+ Content-Type:
30
+ - application/json;charset=utf-8
31
+ X-Xss-Protection:
32
+ - 1; mode=block
33
+ Content-Length:
34
+ - '15'
35
+ Accept-Ranges:
36
+ - bytes
37
+ Via:
38
+ - 1.1 varnish
39
+ Age:
40
+ - '0'
41
+ X-Served-By:
42
+ - cache-v37-ASH
43
+ X-Cache:
44
+ - MISS
45
+ X-Cache-Hits:
46
+ - '0'
47
+ Vary:
48
+ - Accept-Encoding
49
+ Cache-Control:
50
+ - max-age=0;s-maxage=0;private
51
+ body:
52
+ encoding: US-ASCII
53
+ string: ! '{"status":"ok"}'
54
+ http_version:
55
+ recorded_at: Wed, 24 Apr 2013 17:17:05 GMT
56
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'vcr_setup'
4
+ require 'capistrano/fastly'
5
+
6
+ RSpec.configure do |config|
7
+ end
data/spec/vcr_setup.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |c|
4
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
5
+ c.hook_into :webmock
6
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-fastly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dave Konopka
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ description: Capistrano extensions for Fastly CDN service.
31
+ email:
32
+ - dkonopka@articulate.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .rspec
39
+ - .travis.yml
40
+ - Gemfile
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - capistrano-fastly.gemspec
45
+ - lib/capistrano/fastly.rb
46
+ - lib/capistrano/fastly/version.rb
47
+ - spec/capistrano_fastly_spec.rb
48
+ - spec/fixtures/vcr_cassettes/fastly_purge_all.yml
49
+ - spec/spec_helper.rb
50
+ - spec/vcr_setup.rb
51
+ homepage: https://github.com/articulate/capistrano-fastly
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.23
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Execute Fastly api calls as part of your Capistrano deploys.
75
+ test_files:
76
+ - spec/capistrano_fastly_spec.rb
77
+ - spec/fixtures/vcr_cassettes/fastly_purge_all.yml
78
+ - spec/spec_helper.rb
79
+ - spec/vcr_setup.rb