cf-s3-invalidator 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +17 -2
  2. data/bin/cf-s3-inv +92 -79
  3. data/cf-s3-invalidator.gemspec +1 -2
  4. 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
- ## Usage
9
+ ## Install
10
10
 
11
11
  `gem install cf-s3-invalidator`
12
12
 
13
- `cf-s3-inv <AWS-KEY> <AWS-SECRET> <S3-BUCKET-NAME> <CLOUDFRONT-DISTRIBUTION-ID>`
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 CLIOptParser
7
+ class UI
8
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
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
- opts.on("-d", "--distribution CLOUDFRONT ID",
29
- "Cloudfront distribution id") do |val|
30
- options[:distribution] = val
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
- @options = options
25
+ options
33
26
  end
34
27
  end
35
28
 
36
- def parse
37
- @optparse.parse!
38
- @options
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
- def print_help
42
- puts @optparse.help
43
- end
44
- end
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
- 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
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
- def get_conf_file_name
58
- "_cf_s3_invalidator.yml"
59
- end
56
+ def get_conf_file_name
57
+ "_cf_s3_invalidator.yml"
58
+ end
60
59
 
61
- def get_conf_file_path
62
- Dir.pwd + "/#{get_conf_file_name}"
63
- end
60
+ def get_conf_file_path
61
+ Dir.pwd + "/#{get_conf_file_name}"
62
+ end
64
63
 
65
- def conf_file_exists
66
- File.exists?(get_conf_file_path)
67
- end
64
+ def conf_file_exists
65
+ File.exists?(get_conf_file_path)
66
+ end
68
67
 
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
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 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
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
- 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
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 = OptionParser.parse
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])
@@ -1,7 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'cf-s3-invalidator'
3
- s.version = '0.3.0'
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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
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-03 00:00:00 Z
18
+ date: 2012-07-04 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: aws-sdk