From 9976e767d003b00fd9d88bca2f0e1bd25f3da306 Mon Sep 17 00:00:00 2001 From: Michael Bailey Date: Sat, 29 Jul 2017 01:23:07 -0400 Subject: [PATCH 1/7] add ec2 instance enumeration --- slack-aws/commands/ec2.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 slack-aws/commands/ec2.rb diff --git a/slack-aws/commands/ec2.rb b/slack-aws/commands/ec2.rb new file mode 100644 index 0000000..b843b66 --- /dev/null +++ b/slack-aws/commands/ec2.rb @@ -0,0 +1,35 @@ +module SlackAws + module Commands + class EC2 < SlackRubyBot::Commands::Base + extend SlackAws::Util::AwsClientResponse + + command 'ec2' do |client, data, match| + arguments = match['expression'].split.reject(&:blank?) if match.names.include?('expression') + case arguments && arguments.shift + when 'instances' then + reap = Aws::EC2::Client.new.describe_instances() + reap = Aws::EC2::Client.new + instances = reap.describe_instances() + reservationdescrip = "" + instanceprofile = "\n*Summary*:\n" + + instances.reservations.each do |reservation| + reservation.instances.each do |instance| + if instance.state.name != "running" + next + end + instanceprofile = + "\n#{instanceprofile}\n + *Instance Identifier:* #{instance.instance_id }\n + *IP Address:* #{instance.public_ip_address }\n + *Image Identifier:* #{instance.image_id }\n + *Instance Type:* #{instance.instance_type }\n" + end + end + else + client.say(text: 'Syntax: aws s3 [command], need `aws help`? Message @awsbot help.', channel: data.channel) + end + end + end + end +end From 27ddb824887f5e6704e66f0647a906ccf77d30fb Mon Sep 17 00:00:00 2001 From: Michael Bailey Date: Sat, 29 Jul 2017 01:23:30 -0400 Subject: [PATCH 2/7] add it as a valid command' --- slack-aws/commands.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/slack-aws/commands.rb b/slack-aws/commands.rb index bf4b475..d877ff3 100644 --- a/slack-aws/commands.rb +++ b/slack-aws/commands.rb @@ -4,4 +4,5 @@ require 'aws-sdk' require 'slack-aws/util/aws_client_response' require 'slack-aws/commands/s3' +require 'slack-aws/commands/ec2' require 'slack-aws/commands/ops_works' From 23c4312046a37bde44cb2b78ab8c5032e26f910b Mon Sep 17 00:00:00 2001 From: Michael Bailey Date: Sat, 29 Jul 2017 01:24:36 -0400 Subject: [PATCH 3/7] add proper prefix --- slack-aws/commands/ec2.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slack-aws/commands/ec2.rb b/slack-aws/commands/ec2.rb index b843b66..ad9ec36 100644 --- a/slack-aws/commands/ec2.rb +++ b/slack-aws/commands/ec2.rb @@ -27,7 +27,7 @@ class EC2 < SlackRubyBot::Commands::Base end end else - client.say(text: 'Syntax: aws s3 [command], need `aws help`? Message @awsbot help.', channel: data.channel) + client.say(text: 'Syntax: aws ec2 [command], need `aws help`? Message @awsbot help.', channel: data.channel) end end end From 790d9f015aaf00b1c9868b2d0c2fcd7820f545a4 Mon Sep 17 00:00:00 2001 From: Michael Bailey Date: Sat, 29 Jul 2017 01:39:11 -0400 Subject: [PATCH 4/7] fix test cases --- slack-aws/commands/ec2.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/slack-aws/commands/ec2.rb b/slack-aws/commands/ec2.rb index ad9ec36..1884c19 100644 --- a/slack-aws/commands/ec2.rb +++ b/slack-aws/commands/ec2.rb @@ -1,5 +1,6 @@ module SlackAws module Commands + # Do the AWS EC2 things class EC2 < SlackRubyBot::Commands::Base extend SlackAws::Util::AwsClientResponse @@ -7,25 +8,23 @@ class EC2 < SlackRubyBot::Commands::Base arguments = match['expression'].split.reject(&:blank?) if match.names.include?('expression') case arguments && arguments.shift when 'instances' then - reap = Aws::EC2::Client.new.describe_instances() reap = Aws::EC2::Client.new instances = reap.describe_instances() - reservationdescrip = "" instanceprofile = "\n*Summary*:\n" - instances.reservations.each do |reservation| reservation.instances.each do |instance| - if instance.state.name != "running" + if instance.state.name != 'running' next end - instanceprofile = + instanceprofile = "\n#{instanceprofile}\n - *Instance Identifier:* #{instance.instance_id }\n - *IP Address:* #{instance.public_ip_address }\n - *Image Identifier:* #{instance.image_id }\n - *Instance Type:* #{instance.instance_type }\n" + *Instance Identifier:* #{instance.instance_id}\n + *IP Address:* #{instance.public_ip_address}\n + *Image Identifier:* #{instance.image_id}\n + *Instance Type:* #{instance.instance_type}\n" end end + client.say(text: instanceprofile, channel: data.channel) else client.say(text: 'Syntax: aws ec2 [command], need `aws help`? Message @awsbot help.', channel: data.channel) end From 53931384789c937ea2bc398d297ccd6554b23f32 Mon Sep 17 00:00:00 2001 From: Michael Bailey Date: Sat, 29 Jul 2017 01:42:28 -0400 Subject: [PATCH 5/7] add single liner --- slack-aws/commands/ec2.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slack-aws/commands/ec2.rb b/slack-aws/commands/ec2.rb index 1884c19..308ea7d 100644 --- a/slack-aws/commands/ec2.rb +++ b/slack-aws/commands/ec2.rb @@ -9,7 +9,7 @@ class EC2 < SlackRubyBot::Commands::Base case arguments && arguments.shift when 'instances' then reap = Aws::EC2::Client.new - instances = reap.describe_instances() + instances = reap.describe_instances instanceprofile = "\n*Summary*:\n" instances.reservations.each do |reservation| reservation.instances.each do |instance| From a5f3109509a0953707202ea33e27c69a28eacc01 Mon Sep 17 00:00:00 2001 From: Michael Bailey Date: Sat, 29 Jul 2017 01:48:43 -0400 Subject: [PATCH 6/7] Try fixing the faraday issue (see: https://github.com/bundler/bundler/issues/5332) --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index e26b659..5861b2c 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gem 'slack-ruby-bot' gem 'puma' gem 'sinatra' gem 'dentaku' +gem 'faraday-middleware', '~> 0.11.0.1' gem 'aws-sdk', '~> 2' group :development, :test do From 07ec8f9851979317c5f781896d57c0d14251798e Mon Sep 17 00:00:00 2001 From: Michael Bailey Date: Sat, 29 Jul 2017 01:57:39 -0400 Subject: [PATCH 7/7] Im not crazy --- Gemfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Gemfile b/Gemfile index 5861b2c..e26b659 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,6 @@ gem 'slack-ruby-bot' gem 'puma' gem 'sinatra' gem 'dentaku' -gem 'faraday-middleware', '~> 0.11.0.1' gem 'aws-sdk', '~> 2' group :development, :test do