cf-s3-invalidator 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cf-s3-inv +96 -27
- data/cf-s3-invalidator.gemspec +1 -1
- metadata +3 -3
data/bin/cf-s3-inv
CHANGED
@@ -1,40 +1,109 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'optparse'
|
3
|
+
require 'yaml'
|
3
4
|
require File.dirname(__FILE__)+'/../lib/cloudfront_invalidator'
|
4
5
|
require File.dirname(__FILE__)+'/../lib/s3_loader'
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
7
|
+
class CLIOptParser
|
8
|
+
def initialize
|
9
|
+
@optparse = OptionParser.new do |opts|
|
10
|
+
options = {}
|
11
|
+
opts.banner = "Usage: #{File.basename(__FILE__)} [options]"
|
12
|
+
opts.separator ""
|
13
|
+
opts.separator "Invalidate an S3-based Cloudfront distribution"
|
14
|
+
opts.separator ""
|
15
|
+
opts.separator "Options:"
|
16
|
+
opts.on("-k", "--key AWS KEY",
|
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
|
27
|
+
end
|
28
|
+
opts.on("-d", "--distribution CLOUDFRONT ID",
|
29
|
+
"Cloudfront distribution id") do |val|
|
30
|
+
options[:distribution] = val
|
31
|
+
end
|
32
|
+
@options = options
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def parse
|
37
|
+
@optparse.parse!
|
38
|
+
@options
|
39
|
+
end
|
40
|
+
|
41
|
+
def print_help
|
42
|
+
puts @optparse.help
|
28
43
|
end
|
29
44
|
end
|
30
45
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
46
|
+
class FileOptionParser
|
47
|
+
def parse
|
48
|
+
yml = YAML.load_file(get_conf_file_path)
|
49
|
+
{
|
50
|
+
:key => yml['s3_key'],
|
51
|
+
:secret => yml['s3_secret'],
|
52
|
+
:bucket => yml['s3_bucket'],
|
53
|
+
:distribution => yml['cloudfront_distribution_id']
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_conf_file_name
|
58
|
+
"_cf_s3_invalidator.yml"
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_conf_file_path
|
62
|
+
Dir.pwd + "/#{get_conf_file_name}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def conf_file_exists
|
66
|
+
File.exists?(get_conf_file_path)
|
67
|
+
end
|
68
|
+
|
69
|
+
def sample_conf_file
|
70
|
+
sample = <<-EOF
|
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
|
+
EOF
|
76
|
+
end
|
36
77
|
end
|
37
78
|
|
79
|
+
class OptionParser
|
80
|
+
def self.parse
|
81
|
+
if ARGV.length == 0
|
82
|
+
file_parser = FileOptionParser.new
|
83
|
+
unless file_parser.conf_file_exists
|
84
|
+
puts "The configuration file '#{file_parser.get_conf_file_name}' is missing"
|
85
|
+
puts "Here is a sample:"
|
86
|
+
puts ""
|
87
|
+
puts file_parser.sample_conf_file
|
88
|
+
puts ""
|
89
|
+
exit
|
90
|
+
end
|
91
|
+
file_parser.parse
|
92
|
+
else
|
93
|
+
args_original = ARGV.dup
|
94
|
+
cli_parser = CLIOptParser.new
|
95
|
+
options = cli_parser.parse
|
96
|
+
if args_original.length == 0
|
97
|
+
cli_parser.print_help
|
98
|
+
exit
|
99
|
+
end
|
100
|
+
options
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
options = OptionParser.parse
|
106
|
+
|
38
107
|
s3_object_keys = S3Loader.new(
|
39
108
|
options[:key], options[:secret]).list_keys(options[:bucket])
|
40
109
|
|
data/cf-s3-invalidator.gemspec
CHANGED
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: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lauri Lehmijoki
|