Skip to content

Commit 21ebd26

Browse files
committed
refactor required ENV variables check
1 parent d5032d4 commit 21ebd26

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/tasks/eb_fast_deploy.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ def do_cmd(cmd)
8383
print "#{result}\n"
8484
end
8585

86+
def check_required_variables!(variables_array)
87+
variables_array.each do |opt|
88+
raise "(Error) #{opt} not defined" if ENV[opt].nil?
89+
end
90+
end
91+
8692
def set_vars
8793
return if @is_config_loaded
8894
puts "-------------------------------------------------------------"
@@ -194,6 +200,7 @@ def print_env
194200
print "\n"
195201

196202
set_vars
203+
check_required_variables! ['AWS_DEPLOY_BUCKET', 'AWS_REGION', 'AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY']
197204

198205
do_cmd "mkdir #{@deploy_tmp_dir}"
199206
do_cmd "rm #{@deploy_zip_file_path}"
@@ -271,13 +278,7 @@ def print_env
271278
desc "create application on Elastic Beanstalk"
272279
task :create_eb_application do
273280
set_vars
274-
275-
['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'AWS_REGION', 'APP_NAME'].each do |opt|
276-
if ENV[opt].nil?
277-
puts "(Error) #{opt} not defined"
278-
exit
279-
end
280-
end
281+
check_required_variables! ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'AWS_REGION', 'APP_NAME']
281282

282283
unless app_exists?
283284
opts = {}

0 commit comments

Comments
 (0)