From b74e4480b31b1276375a1f63ad5fcd5ca4edeb67 Mon Sep 17 00:00:00 2001 From: Alexy Mikhailichenko Date: Thu, 17 Oct 2019 14:13:32 -0400 Subject: [PATCH 1/2] Check for user input in cloudfront_client.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When deploying using `s3_website` as part of a BitBucket pipeline, the following error was observed: ```Do you want to deliver your website via CloudFront, Amazon’s CDN service? [y/N] undefined method `chomp' for nil:NilClass (NoMethodError)``` Adding a nil check with a meaningful hint to add `--headless`. --- lib/configure-s3-website/cloudfront_client.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/configure-s3-website/cloudfront_client.rb b/lib/configure-s3-website/cloudfront_client.rb index f8dbd7f..3714959 100644 --- a/lib/configure-s3-website/cloudfront_client.rb +++ b/lib/configure-s3-website/cloudfront_client.rb @@ -40,6 +40,8 @@ def self.create_distribution_if_user_agrees(options, standard_input) # Do nothing else puts 'Do you want to deliver your website via CloudFront, Amazon’s CDN service? [y/N]' + user_answer = standard_input.gets + print_headless_hint_and_exit if user_answer.nil? case standard_input.gets.chomp when /(y|Y)/ then create_distribution options end @@ -71,6 +73,11 @@ def self.create_distribution(options) end end + def self.print_headless_hint_and_exit + puts 'No response detected. If you are running the command in a non-interactive session, you can use s3_website cfg apply --headless' + exit 1 + end + def self.print_report_on_custom_distribution_config(custom_distribution_config, left_padding = 4) puts ' Applied custom distribution settings:' puts custom_distribution_config. From b66750c050fa8182956e11d474ae56aa00f55800 Mon Sep 17 00:00:00 2001 From: Alexy Mikhailichenko Date: Thu, 17 Oct 2019 14:30:03 -0400 Subject: [PATCH 2/2] Fix existing usage of user input --- lib/configure-s3-website/cloudfront_client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/configure-s3-website/cloudfront_client.rb b/lib/configure-s3-website/cloudfront_client.rb index 3714959..315f7d8 100644 --- a/lib/configure-s3-website/cloudfront_client.rb +++ b/lib/configure-s3-website/cloudfront_client.rb @@ -42,7 +42,7 @@ def self.create_distribution_if_user_agrees(options, standard_input) puts 'Do you want to deliver your website via CloudFront, Amazon’s CDN service? [y/N]' user_answer = standard_input.gets print_headless_hint_and_exit if user_answer.nil? - case standard_input.gets.chomp + case user_answer.chomp when /(y|Y)/ then create_distribution options end end