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.
Files changed (3) hide show
  1. data/bin/cf-s3-inv +96 -27
  2. data/cf-s3-invalidator.gemspec +1 -1
  3. 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
- options = {}
7
- optparse = OptionParser.new do |opts|
8
- opts.banner = "Usage: #{File.basename(__FILE__)} [options]"
9
- opts.separator ""
10
- opts.separator "Invalidate an S3-based Cloudfront distribution"
11
- opts.separator ""
12
- opts.separator "Options:"
13
- opts.on("-k", "--key AWS KEY",
14
- "Amazon Web Services API key that has access to your S3 and Cloudfront") do |val|
15
- options[:key] = val
16
- end
17
- opts.on("-s", "--secret AWS SECRET",
18
- "Amazon Web Services API secret key") do |val|
19
- options[:secret] = val
20
- end
21
- opts.on("-b", "--bucket BUCKET NAME",
22
- "S3 bucket name") do |val|
23
- options[:bucket] = val
24
- end
25
- opts.on("-d", "--distribution CLOUDFRONT ID",
26
- "Cloudfront distribution id") do |val|
27
- options[:distribution] = val
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
- ARGV_ORIGINAL = ARGV.dup
32
- optparse.parse!
33
- if ARGV_ORIGINAL.length == 0
34
- puts optparse.help
35
- exit
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
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'cf-s3-invalidator'
3
- s.version = '0.2.0'
3
+ s.version = '0.3.0'
4
4
  s.date = '2012-07-03'
5
5
  s.summary = 'A tool for invalidating AWS S3-based Cloudfront distributions'
6
6
  s.description =
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: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lauri Lehmijoki