ruboty-cloudfront 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +33 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ruboty/cloudfront.rb +2 -0
- data/lib/ruboty/cloudfront/version.rb +5 -0
- data/lib/ruboty/handlers/cloudfront.rb +115 -0
- data/ruboty-cloudfront.gemspec +31 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1e34a928d5cdf6bc461f2fc3b1bd4d0c920e6045
|
4
|
+
data.tar.gz: b62e564be519a9d49115649447bca2eb2a52bf91
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c50863df5a3622df4e05aace96f2a5fbe6a3c8ca12fa4a1c019e68f61aa2193777d1e4bdabbf5b5b0a24124f2c102a2f1da764158859c693b1a7e00ebecddd26
|
7
|
+
data.tar.gz: ad11764709c87a394457935ea2d7be80afbe6da97eacd4667d9cd2eec11be3aa9b12df8cb3ea821ed3ddb2837e0b5d65e9853cfc5e86e67aa1f54a91d2e04a59
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Sho Kusano
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Ruboty::Cloudfront
|
2
|
+
|
3
|
+
Provides cloud front operations to ruboty.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ruboty-cloudfront'
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
```
|
16
|
+
ruboty /cf (?:inval(?:idate)?|purge) (?<url>.+?)\z/m - Purge path
|
17
|
+
ruboty /cf list distributions?/m - List distributions
|
18
|
+
ruboty /cf list invalidations?/m - List invalidations
|
19
|
+
```
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
24
|
+
|
25
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/zeny-io/ruboty-cloudfront.
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
MIT License
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'ruboty/cloudfront'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'uri'
|
3
|
+
require 'aws-sdk'
|
4
|
+
|
5
|
+
module Ruboty
|
6
|
+
module Handlers
|
7
|
+
class Cloudfront < Base
|
8
|
+
on(
|
9
|
+
/cf list distributions?/m,
|
10
|
+
description: 'List distributions',
|
11
|
+
name: 'list_distributuions'
|
12
|
+
)
|
13
|
+
|
14
|
+
on(
|
15
|
+
/cf list invalidations?/m,
|
16
|
+
description: 'List invalidations',
|
17
|
+
name: 'list_invalidations'
|
18
|
+
)
|
19
|
+
|
20
|
+
on(
|
21
|
+
/cf (?:inval(?:idate)?|purge) (?<url>.+?)\z/m,
|
22
|
+
description: 'Purge path',
|
23
|
+
name: 'purge_url'
|
24
|
+
)
|
25
|
+
|
26
|
+
def list_distributuions(message)
|
27
|
+
maximum_domain_length = prefixes.map(&:first).sort_by(&:size).last.size
|
28
|
+
maximum_id_length = prefixes.map { |p| p[1] }.sort_by(&:size).last.size
|
29
|
+
|
30
|
+
lines = prefixes.map do |prefix|
|
31
|
+
[
|
32
|
+
prefix[0].ljust(maximum_domain_length),
|
33
|
+
prefix[1].ljust(maximum_id_length),
|
34
|
+
prefix[2]
|
35
|
+
].join(' ')
|
36
|
+
end
|
37
|
+
|
38
|
+
message.reply(
|
39
|
+
"We have #{prefixes.count} distributions\n" + lines.join("\n"),
|
40
|
+
code: true
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def list_invalidations(message)
|
45
|
+
invalidations = []
|
46
|
+
prefixes.map { |p| p[1] }.uniq.each do |prefix|
|
47
|
+
resp = cloudfront.list_invalidations(distribution_id: prefix)
|
48
|
+
resp.invalidation_list.items.each do |invalidation|
|
49
|
+
next unless invalidation.status != 'Completed'
|
50
|
+
iresp = cloudfront.get_invalidation(distribution_id: prefix, id: invalidation.id)
|
51
|
+
iresp.invalidation.invalidation_batch.paths.items.each do |path|
|
52
|
+
invalidations << "#{path} : #{invalidation.status} / #{domains_by(prefix).join(', ')}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
message.reply(
|
58
|
+
"We have #{invalidations.count} invalidations\n" + invalidations.join("\n"),
|
59
|
+
code: true
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
def purge_url(message)
|
64
|
+
uri = URI.parse(message[:url])
|
65
|
+
|
66
|
+
dist = prefixes.bsearch { |p| p[0] == uri.host }
|
67
|
+
|
68
|
+
unless dist
|
69
|
+
message.reply('Distribution not found')
|
70
|
+
return
|
71
|
+
end
|
72
|
+
|
73
|
+
cloudfront.create_invalidation(distribution_id: dist[1],
|
74
|
+
invalidation_batch: {
|
75
|
+
paths: {
|
76
|
+
quantity: 1,
|
77
|
+
items: [uri.path]
|
78
|
+
},
|
79
|
+
caller_reference: SecureRandom.uuid
|
80
|
+
})
|
81
|
+
|
82
|
+
message.reply("Started #{uri.path} invalidation of #{dist[1]} / #{dist[0]}")
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def cloudfront
|
88
|
+
@cloudfront ||= Aws::CloudFront::Client.new(region: 'us-east-1')
|
89
|
+
end
|
90
|
+
|
91
|
+
def distributions
|
92
|
+
cloudfront.list_distributions.distribution_list
|
93
|
+
rescue Aws::Errors::ServiceError
|
94
|
+
nil
|
95
|
+
end
|
96
|
+
|
97
|
+
def prefixes
|
98
|
+
return @prefixes if @prefixes
|
99
|
+
|
100
|
+
@prefixes = []
|
101
|
+
distributions.items.each do |dist|
|
102
|
+
@prefixes << [dist.domain_name, dist.id, dist.status]
|
103
|
+
dist.aliases.items.each do |domain|
|
104
|
+
@prefixes << [domain, dist.id, dist.status]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
@prefixes
|
108
|
+
end
|
109
|
+
|
110
|
+
def domains_by(id)
|
111
|
+
prefixes.select { |p| p[1] == id }.map(&:first)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruboty/cloudfront/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'ruboty-cloudfront'
|
8
|
+
spec.version = Ruboty::Cloudfront::VERSION
|
9
|
+
spec.authors = ['Sho Kusano']
|
10
|
+
spec.email = ['sho-kusano@zeny.io']
|
11
|
+
|
12
|
+
spec.summary = 'Provides cloud front operation to ruboty'
|
13
|
+
spec.description = 'Provides cloud front operation to ruboty'
|
14
|
+
spec.homepage = 'https://github.com/zeny-io/ruboty-cloudfront'
|
15
|
+
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
|
29
|
+
spec.add_dependency 'ruboty'
|
30
|
+
spec.add_dependency 'aws-sdk', '~> 2.0'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-cloudfront
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sho Kusano
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruboty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: aws-sdk
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
description: Provides cloud front operation to ruboty
|
84
|
+
email:
|
85
|
+
- sho-kusano@zeny.io
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/ruboty/cloudfront.rb
|
100
|
+
- lib/ruboty/cloudfront/version.rb
|
101
|
+
- lib/ruboty/handlers/cloudfront.rb
|
102
|
+
- ruboty-cloudfront.gemspec
|
103
|
+
homepage: https://github.com/zeny-io/ruboty-cloudfront
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.5.1
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Provides cloud front operation to ruboty
|
127
|
+
test_files: []
|