cf-s3-invalidator 0.3.0 → 0.3.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/README.md +17 -2
- data/bin/cf-s3-inv +92 -79
- data/cf-s3-invalidator.gemspec +1 -2
- metadata +4 -4
data/README.md
CHANGED
@@ -6,8 +6,23 @@ this library may be useful to you.
|
|
6
6
|
This library fetches all the object keys of a particular S3 bucket and then
|
7
7
|
calls on them the invalidation REST API of Cloudfront.
|
8
8
|
|
9
|
-
##
|
9
|
+
## Install
|
10
10
|
|
11
11
|
`gem install cf-s3-invalidator`
|
12
12
|
|
13
|
-
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
You can specify the configuration as CLI parameters:
|
16
|
+
|
17
|
+
`cf-s3-inv --key <AWS-KEY> --secret <AWS-SECRET> --bucket <S3-BUCKET-NAME> --distribution <CLOUDFRONT-DISTRIBUTION-ID>`
|
18
|
+
|
19
|
+
Or you can store them into the file *_cf_s3_invalidator.yml*:
|
20
|
+
|
21
|
+
s3_key: YOUR_AWS_S3_ACCESS_KEY_ID
|
22
|
+
s3_secret: YOUR_AWS_S3_SECRET_ACCESS_KEY
|
23
|
+
s3_bucket: your.blog.bucket.com
|
24
|
+
cloudfront_distribution_id: YOUR_CLOUDFRONT_DISTRIBUTION_ID
|
25
|
+
|
26
|
+
Then you can just run:
|
27
|
+
|
28
|
+
`cf-s3-inv`
|
data/bin/cf-s3-inv
CHANGED
@@ -4,105 +4,118 @@ require 'yaml'
|
|
4
4
|
require File.dirname(__FILE__)+'/../lib/cloudfront_invalidator'
|
5
5
|
require File.dirname(__FILE__)+'/../lib/s3_loader'
|
6
6
|
|
7
|
-
class
|
7
|
+
class UI
|
8
8
|
def initialize
|
9
|
-
@
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
"Amazon Web Services API key that has access to your S3 and Cloudfront") do |val|
|
18
|
-
options[:key] = val
|
19
|
-
end
|
20
|
-
opts.on("-s", "--secret AWS SECRET",
|
21
|
-
"Amazon Web Services API secret key") do |val|
|
22
|
-
options[:secret] = val
|
23
|
-
end
|
24
|
-
opts.on("-b", "--bucket BUCKET NAME",
|
25
|
-
"S3 bucket name") do |val|
|
26
|
-
options[:bucket] = val
|
9
|
+
@file_parser = FileOptionParser.new
|
10
|
+
@cli_parser = CLIOptParser.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse_or_print_help
|
14
|
+
if ARGV.length == 0
|
15
|
+
unless @file_parser.conf_file_exists
|
16
|
+
print_help_and_exit
|
27
17
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
18
|
+
@file_parser.parse
|
19
|
+
else
|
20
|
+
args_original = ARGV.dup # Optparse removes the valid arguments from ARGV
|
21
|
+
options = @cli_parser.parse
|
22
|
+
if args_original.length == 0
|
23
|
+
print_help_and_exit
|
31
24
|
end
|
32
|
-
|
25
|
+
options
|
33
26
|
end
|
34
27
|
end
|
35
28
|
|
36
|
-
def
|
37
|
-
@
|
38
|
-
|
29
|
+
def print_help_and_exit
|
30
|
+
@cli_parser.print_help
|
31
|
+
puts ""
|
32
|
+
puts "ALTERNATIVELY, you can use a configuration file:"
|
33
|
+
puts ""
|
34
|
+
@file_parser.print_help
|
35
|
+
exit
|
39
36
|
end
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
class FileOptionParser
|
39
|
+
def parse
|
40
|
+
yml = YAML.load_file(get_conf_file_path)
|
41
|
+
{
|
42
|
+
:key => yml['s3_key'],
|
43
|
+
:secret => yml['s3_secret'],
|
44
|
+
:bucket => yml['s3_bucket'],
|
45
|
+
:distribution => yml['cloudfront_distribution_id']
|
46
|
+
}
|
47
|
+
end
|
45
48
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
:bucket => yml['s3_bucket'],
|
53
|
-
:distribution => yml['cloudfront_distribution_id']
|
54
|
-
}
|
55
|
-
end
|
49
|
+
def print_help
|
50
|
+
puts "Add the rows below into file '#{get_conf_file_name}' and then run the program without arguments"
|
51
|
+
puts ""
|
52
|
+
puts sample_conf_file
|
53
|
+
puts ""
|
54
|
+
end
|
56
55
|
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
def get_conf_file_name
|
57
|
+
"_cf_s3_invalidator.yml"
|
58
|
+
end
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
def get_conf_file_path
|
61
|
+
Dir.pwd + "/#{get_conf_file_name}"
|
62
|
+
end
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
def conf_file_exists
|
65
|
+
File.exists?(get_conf_file_path)
|
66
|
+
end
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
s3_key: YOUR_AWS_S3_ACCESS_KEY_ID
|
72
|
-
s3_secret: YOUR_AWS_S3_SECRET_ACCESS_KEY
|
73
|
-
s3_bucket: your.blog.bucket.com
|
74
|
-
cloudfront_distribution_id: YOUR_CLOUDFRONT_DISTRIBUTION_ID
|
75
|
-
|
68
|
+
def sample_conf_file
|
69
|
+
sample = <<-EOF
|
70
|
+
s3_key: YOUR_AWS_S3_ACCESS_KEY_ID
|
71
|
+
s3_secret: YOUR_AWS_S3_SECRET_ACCESS_KEY
|
72
|
+
s3_bucket: your.blog.bucket.com
|
73
|
+
cloudfront_distribution_id: YOUR_CLOUDFRONT_DISTRIBUTION_ID
|
74
|
+
EOF
|
75
|
+
end
|
76
76
|
end
|
77
|
-
end
|
78
77
|
|
79
|
-
class
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
78
|
+
class CLIOptParser
|
79
|
+
def initialize
|
80
|
+
@optparse = OptionParser.new do |opts|
|
81
|
+
options = {}
|
82
|
+
opts.banner = "Usage: #{File.basename(__FILE__)} [options]"
|
83
|
+
opts.separator ""
|
84
|
+
opts.separator "Invalidate an S3-based Cloudfront distribution"
|
85
|
+
opts.separator ""
|
86
|
+
opts.separator "Options:"
|
87
|
+
opts.on("-k", "--key AWS KEY",
|
88
|
+
"Amazon Web Services API key that has access to your S3 and Cloudfront") do |val|
|
89
|
+
options[:key] = val
|
90
|
+
end
|
91
|
+
opts.on("-s", "--secret AWS SECRET",
|
92
|
+
"Amazon Web Services API secret key") do |val|
|
93
|
+
options[:secret] = val
|
94
|
+
end
|
95
|
+
opts.on("-b", "--bucket BUCKET NAME",
|
96
|
+
"S3 bucket name") do |val|
|
97
|
+
options[:bucket] = val
|
98
|
+
end
|
99
|
+
opts.on("-d", "--distribution CLOUDFRONT ID",
|
100
|
+
"Cloudfront distribution id") do |val|
|
101
|
+
options[:distribution] = val
|
102
|
+
end
|
103
|
+
@options = options
|
90
104
|
end
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
options
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
options
|
105
|
+
end
|
106
|
+
|
107
|
+
def parse
|
108
|
+
@optparse.parse!
|
109
|
+
@options
|
110
|
+
end
|
111
|
+
|
112
|
+
def print_help
|
113
|
+
puts @optparse.help
|
101
114
|
end
|
102
115
|
end
|
103
116
|
end
|
104
117
|
|
105
|
-
options =
|
118
|
+
options = UI.new.parse_or_print_help
|
106
119
|
|
107
120
|
s3_object_keys = S3Loader.new(
|
108
121
|
options[:key], options[:secret]).list_keys(options[:bucket])
|
data/cf-s3-invalidator.gemspec
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'cf-s3-invalidator'
|
3
|
-
s.version = '0.3.
|
4
|
-
s.date = '2012-07-03'
|
3
|
+
s.version = '0.3.1'
|
5
4
|
s.summary = 'A tool for invalidating AWS S3-based Cloudfront distributions'
|
6
5
|
s.description =
|
7
6
|
'This lib fetches the names of all objects on an Amazon Web
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cf-s3-invalidator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lauri Lehmijoki
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-07-
|
18
|
+
date: 2012-07-04 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: aws-sdk
|