class RakeCloudspin::Tasks::StackTestTask
Public Instance Methods
assume_role_profile(args)
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 89 def assume_role_profile(args) "assume-spin_account_manager-#{stack_config(args).component}" end
aws_configuration_contents(args)
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 81 def aws_configuration_contents(args) <<~END_AWS_CONFIG [profile #{assume_role_profile(args)}] role_arn = #{stack_config(args).vars['assume_role_arn']} source_profile = #{stack_config(args).vars['aws_profile']} END_AWS_CONFIG end
aws_configuration_file_path()
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 77 def aws_configuration_file_path "#{aws_configuration_folder}/config" end
aws_configuration_folder()
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 73 def aws_configuration_folder "work/#{stack_type}/#{stack_name}/aws" end
build_user_configuration_hash(api_user_hash = {})
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 53 def build_user_configuration_hash(api_user_hash = {}) { 'configured_api_users' => api_user_hash } end
configured_api_users(args)
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 49 def configured_api_users(args) build_user_configuration_hash(stack_config(args).api_users) end
create_inspec_attributes()
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 30 def create_inspec_attributes lambda do |args| mkpath "work/tests/inspec" attributes_file_path = "work/tests/inspec/attributes-#{stack_type}-#{stack_name}.yml" puts "INFO: Writing inspec attributes to file: #{attributes_file_path}" File.open(attributes_file_path, 'w') {|f| f.write(test_attributes(args).to_yaml) } end end
define()
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 9 def define define_inspec_task define_aws_configuration_task end
define_aws_configuration_task()
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 57 def define_aws_configuration_task task :aws_configuration do |t, args| make_aws_configuration_file.call(args) end end
define_inspec_task()
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 14 def define_inspec_task desc 'Run inspec tests' task :test do |t, args| if has_inspec_tests? create_inspec_attributes.call(args) run_inspec_profile.call(args) else puts "NO TESTS FOR STACK ('#{stack_name}')" end end end
has_inspec_tests?()
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 26 def has_inspec_tests? Dir.exist? ("#{stack_type}/#{stack_name}/tests/inspec") end
inspec_cmd(inspec_profile:, inspec_profile_name:, aws_profile:, aws_region:)
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 122 def inspec_cmd(inspec_profile:, inspec_profile_name:, aws_profile:, aws_region:) "inspec exec " \ "#{stack_type}/#{stack_name}/tests/inspec/#{inspec_profile} " \ "-t aws://#{aws_region}/#{aws_profile} " \ "--reporter json-rspec:work/tests/inspec/results-#{stack_type}-#{stack_name}-#{inspec_profile_name}.json " \ "cli " \ "--attrs work/tests/inspec/attributes-#{stack_type}-#{stack_name}.yml" end
make_aws_configuration_file()
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 63 def make_aws_configuration_file lambda do |args| mkpath aws_configuration_folder puts "INFO: Writing AWS configuration file: #{aws_configuration_file_path}" File.open(aws_configuration_file_path, 'w') {|f| f.write(aws_configuration_contents(args)) } end end
make_inspec_profile_name(inspec_profile)
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 118 def make_inspec_profile_name(inspec_profile) inspec_profile != '.' ? inspec_profile : '__root__' end
run_inspec_profile()
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 93 def run_inspec_profile lambda do |args| inspec_profiles = Dir.entries("#{stack_type}/#{stack_name}/tests/inspec").select { |inspec_profile| inspec_profile != '..' && File.exists?("#{stack_type}/#{stack_name}/tests/inspec/#{inspec_profile}/inspec.yml") }.each { |inspec_profile| inspec_profile_name = make_inspec_profile_name(inspec_profile) puts "INSPEC (inspec_profile '#{inspec_profile_name}'): #{inspec_cmd( inspec_profile: inspec_profile, inspec_profile_name: inspec_profile_name, aws_profile: assume_role_profile(args), aws_region: stack_config(args).region )}" system( inspec_cmd( inspec_profile: inspec_profile, inspec_profile_name: inspec_profile_name, aws_profile: assume_role_profile(args), aws_region: stack_config(args).region ) ) } end end
test_attributes(args)
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 41 def test_attributes(args) stack_config(args).vars.merge(test_vars(args)).merge(configured_api_users(args)) end
test_vars(args)
click to toggle source
# File lib/rake_cloudspin/tasks/stack_test_task.rb, line 45 def test_vars(args) stack_config(args).test_vars || {} end