Skip to content
Browse files

deprecate "s3_key" and "s3_secret" keys in the config file

  • Loading branch information...
1 parent 5143dda commit 2552eacf415317b5ec72705a8ad3737000840e8f @laurilehmijoki committed Jul 6, 2012
Showing with 73 additions and 4 deletions.
  1. +2 −2 README.md
  2. +17 −2 bin/cf-s3-inv
  3. +13 −0 features/cloudfront-s3-invalidator-no-credentials.feature
  4. +41 −0 features/configuration-file.feature
View
4 README.md
@@ -21,8 +21,8 @@ You can specify the configuration as CLI parameters:
Or you can store them into the file *_cf_s3_invalidator.yml*:
- s3_key: YOUR_AWS_S3_ACCESS_KEY_ID
- s3_secret: YOUR_AWS_S3_SECRET_ACCESS_KEY
+ aws_key: YOUR_AWS_ACCESS_KEY_ID
+ aws_secret: YOUR_AWS_SECRET_ACCESS_KEY
cloudfront_distribution_id: YOUR_CLOUDFRONT_DISTRIBUTION_ID
Then you can just run:
View
19 bin/cf-s3-inv
@@ -46,13 +46,28 @@ class UI
class FileOptionParser
def parse
yml = YAML.load_file(get_conf_file_path)
+ validate_keys(yml)
{
- :key => yml['s3_key'],
- :secret => yml['s3_secret'],
+ # For backward compatibility, support s3_key and s3_secret
+ :key => yml['s3_key'] ? yml['s3_key'] : yml['aws_key'],
+ :secret => yml['s3_secret'] ? yml['s3_secret'] : yml['aws_secret'],
:distribution => yml['cloudfront_distribution_id']
}
end
+ def validate_keys(config)
+ def test_keys(alternative_config_keys, error_message, config)
+ valid = config.keys.any? { |key| alternative_config_keys.include? key }
+ raise error_message.red unless valid
+ end
+ test_keys(["s3_key", "aws_key"],
+ "AWS key missing in the configuration file", config)
+ test_keys(["s3_secret", "aws_secret"],
+ "AWS secret missing in the configuration file", config)
+ test_keys(["cloudfront_distribution_id"],
+ "Cloudfront distribution id missing in the configuration file", config)
+ end
+
def print_help
puts "Add the rows below into file '#{get_conf_file_name}' and then run the program without arguments"
puts ""
View
13 features/cloudfront-s3-invalidator-no-credentials.feature
@@ -7,6 +7,19 @@ Feature: cloudfront-s3-invalidator without AWS credentials
Scenario: Run cf-s3-inv with the configuration file that has invalid AWS access key
Given a file named "_cf_s3_invalidator.yml" with:
"""
+ aws_key: YOUR_AWS_ACCESS_KEY_ID
+ aws_secret: YOUR_AWS_SECRET_ACCESS_KEY
+ cloudfront_distribution_id: CF_ID
+ """
+ When I run `cf-s3-inv`
+ Then the output should contain:
+ """
+ The security token included in the request is invalid
+ """
+
+ Scenario: Run cf-s3-inv with the configuration file that has invalid S3 access key
+ Given a file named "_cf_s3_invalidator.yml" with:
+ """
s3_key: YOUR_AWS_S3_ACCESS_KEY_ID
s3_secret: YOUR_AWS_S3_SECRET_ACCESS_KEY
cloudfront_distribution_id: CF_ID
View
41 features/configuration-file.feature
@@ -0,0 +1,41 @@
+Feature: configuration file
+ In order to easily specify AWS credentials and Cloudfront distribution name
+ As a geek
+ I want to use a configuration file
+
+ Scenario: Missing key
+ Given a file named "_cf_s3_invalidator.yml" with:
+ """
+ s3_secret: YOUR_AWS_S3_SECRET_ACCESS_KEY
+ cloudfront_distribution_id: CF_ID
+ """
+ When I run `cf-s3-inv`
+ Then the output should contain:
+ """
+ AWS key missing in the configuration file
+ """
+
+ Scenario: Missing secret
+ Given a file named "_cf_s3_invalidator.yml" with:
+ """
+ aws_key: AWS_KEY
+ cloudfront_distribution_id: CF_ID
+ """
+ When I run `cf-s3-inv`
+ Then the output should contain:
+ """
+ AWS secret missing in the configuration file
+ """
+
+ Scenario: Missing Cloudfront distribution id
+ Given a file named "_cf_s3_invalidator.yml" with:
+ """
+ aws_key: AWS_KEY
+ aws_secret: AWS_SECRET
+ """
+ When I run `cf-s3-inv`
+ Then the output should contain:
+ """
+ Cloudfront distribution id missing in the configuration file
+ """
+

0 comments on commit 2552eac

Please sign in to comment.
Something went wrong with that request. Please try again.