lita-aws 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0bd224dc01c114fb7d28b90fd62755a9780d410c
4
+ data.tar.gz: c9eb9e31b8563d325d4abd736d6f4bf281b55cfd
5
+ SHA512:
6
+ metadata.gz: 1b5f4d79182d7c4611048318bbfe96a782b08c0c61175dbd42618c4f8b51123a980efb4c135739fadb68e787184e791553bfec778dde923d169df8a8f213c9b1
7
+ data.tar.gz: 2504901197409855be053edd14d29c0ea3c8b801c12a1d0ce7e635fc8ac3b4954c6f488b78cf6858e5b9f943c18d31a6c86ba896ff5508f29db3da12a7b0558a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.3
4
+ script: bundle exec rake
5
+ before_install:
6
+ - gem update --system
7
+ services:
8
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # lita-aws
2
+
3
+ [![Build Status](https://travis-ci.org/marsz/lita-aws.png?branch=master)](https://travis-ci.org/marsz/lita-aws)
4
+ [![Coverage Status](https://coveralls.io/repos/marsz/lita-aws/badge.png)](https://coveralls.io/r/marsz/lita-aws)
5
+
6
+ TODO: Add a description of the plugin.
7
+
8
+ ## Installation
9
+
10
+ Add lita-aws to your Lita instance's Gemfile:
11
+
12
+ ``` ruby
13
+ gem 'lita-aws'
14
+ ```
15
+
16
+ ## System requirement
17
+
18
+ 1. [AWS-CLI](https://docs.aws.amazon.com/cli/latest/userguide/installing.html) must be installed, make sure your lita user can execute `aws`.
19
+
20
+
21
+ ## Configuration
22
+
23
+ - lita-aws support multiple aws accounts, configurating through aws-cli, you can use following commands to manage aws accounts.
24
+
25
+
26
+ #### List saved accounts
27
+
28
+ ```
29
+ (lita) aws profile
30
+ ```
31
+
32
+ #### Create or update account.
33
+
34
+ ```
35
+ (lita) aws profile [profile_name] [region] [api_key] [secret_key]
36
+ ```
37
+
38
+ - profile_name: Only accept lower letter and numbers. `default` will set to aws-cli default profile.
39
+ - region: AWS region, such as: `ap-northeast-1`
40
+ - api_key: AWS access key id.
41
+ - secret_key: AWS secret access key.
42
+
43
+ Example:
44
+
45
+ ```
46
+ (lita) aws profile 5fpro ap-northeast-1 abcdefg ababcdcd
47
+ ```
48
+
49
+ ## Usage
50
+
51
+ #### Get AWS account number.
52
+
53
+ ```
54
+ # with default profile
55
+ (lita) aws account-id
56
+ # with specific profile
57
+ (lita) aws account-id --profile {profile_name}
58
+ # Example:
59
+ (lita) aws account-id --profile 5fpro
60
+ ```
61
+
62
+ #### Execute as aws-cli.
63
+
64
+ ```
65
+ (lita) aws-cli ec2 describe-instances --page-size 10 --profile {profile_name}
66
+ ```
67
+
68
+ That will execute as command line:
69
+
70
+ ```
71
+ aws ec2 describe-instances --page-size 10 --profile {profile_name}
72
+ ```
73
+
74
+ and return json.
75
+
76
+
77
+ #### Get cloudwatch metric data.
78
+
79
+ - lita-aws provide gem-owned command for re-composing json data and formatting output for bot response. All of these customized command will use `aws ` as prefix, here is the exmaple to get cloudwatch data.
80
+
81
+ ```
82
+ (lita) aws ec2-memutil {Instance ID} --ago 2d --cal Average --period 300s --profile {profile_name}
83
+ ```
84
+
85
+ output:
86
+
87
+ ```
88
+ 2017-02-26T16:00:00Z : 45.56%
89
+ 2017-02-26T16:05:00Z : 39.58%
90
+ 2017-02-26T16:10:00Z : 39.32%
91
+ 2017-02-26T16:15:00Z : 39.33%
92
+ 2017-02-26T16:20:00Z : 39.55%
93
+ 2017-02-26T16:25:00Z : 39.65%
94
+ 2017-02-26T16:30:00Z : 39.72%
95
+ 2017-02-26T16:35:00Z : 39.69%
96
+ 2017-02-26T16:40:00Z : 39.68%
97
+ 2017-02-26T16:45:00Z : 39.69%
98
+ 2017-02-26T16:50:00Z : 39.68%
99
+ 2017-02-26T16:55:00Z : 39.71%
100
+ ```
101
+
102
+ options:
103
+
104
+ - ago: `2d` means get 2 days ago data. Currently, the unit only `d` as `day`.
105
+ - period: `300s` means each data contains 300 seconds.
106
+ - cal: `Averages` means each period data will calculate its average as output value. To see more values http://docs.aws.amazon.com/cli/latest/reference/cloudwatch/get-metric-statistics.html and find `--statistics`.
107
+
108
+ #### More customized commands
109
+
110
+ ```
111
+ (lita) help aws
112
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/TODO.md ADDED
@@ -0,0 +1,24 @@
1
+ - Set aws-cli command text to alias name. For example:
2
+
3
+ ```
4
+ (lita) aws-cli ec2 describe-instances --profile 5fpro --alias 5fpro-ec2s
5
+ ```
6
+
7
+ Execute by alias name:
8
+
9
+ ```
10
+ (lita) aws-alias ec2s 5fpro-ec2s
11
+ ```
12
+
13
+ List all alias names:
14
+
15
+ ```
16
+ (lita) aws-alias-all
17
+ ```
18
+
19
+ (output)
20
+
21
+ ```
22
+ 5fpro-ec2s :
23
+ ec2 describe-instances --profile 5fpro
24
+ ```
@@ -0,0 +1,11 @@
1
+ module Lita
2
+ module Handlers
3
+ class AwsBaseHandler < Handler
4
+ include ::LitaAws::Base
5
+ include ::LitaAws::ReplyFormatter
6
+ include ::LitaAws::Parser
7
+ include ::LitaAws::Data
8
+ include ::LitaAws::Scripts
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,93 @@
1
+ module Lita
2
+ module Handlers
3
+ class AwsCloudWatchHandler < AwsBaseHandler
4
+
5
+ help = { 'aws ec2-memutil {instance id}[ --ago 2d][ --cal Average|SampleCount|Sum|Minimum|Maximum][ --period 300s][ --profile NAME]' => 'Show memory utilization of EC2 instance.' }
6
+ route(/aws ec2\-memutil ([i][\-][0-9a-zA-Z]+)[ ]*(.*)$/, help: help) do |response|
7
+ opts = get_options_for_cloudwatch(response, ago: '2d', period: '300s', cal: 'Average')
8
+ instance_id = response.matches.first.first
9
+ cmd = "cloudwatch get-metric-statistics --namespace System/Linux --metric-name MemoryUtilization --dimensions Name=InstanceId,Value=#{instance_id} --start-time #{opts[:start_time]} --end-time #{opts[:end_time]} --period #{opts[:period]} --statistics #{opts[:cal]}"
10
+ data = exec_cli_json(cmd, opts[:cmd_opts])
11
+ render_cloudwatch_data(response, data, opts[:cal])
12
+ end
13
+
14
+ help = { 'aws ec2-cpuutil {instance id}[ --ago 2d][ --period 300s][ --profile NAME]' => 'Show CPU utilization of EC2 instance.'}
15
+ route(/aws ec2\-cpuutil ([i][\-][0-9a-zA-Z]+)[ ]*(.*)$/, help: help) do |response|
16
+ opts = get_options_for_cloudwatch(response, ago: '2d', period: '300s')
17
+ instance_id = response.matches.first.first
18
+ cmd = "cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name CPUUtilization --dimensions Name=InstanceId,Value=#{instance_id} --start-time #{opts[:start_time]} --end-time #{opts[:end_time]} --period #{opts[:period]} --statistics Average"
19
+ data = exec_cli_json(cmd, opts[:cmd_opts])
20
+ render_cloudwatch_data(response, data, 'Average')
21
+ end
22
+
23
+ help = { 'aws elb-req-sum {ELB name}[ --ago 2d][ --period 300s][ --profile NAME]' => 'Show ELB request count.'}
24
+ route(/aws elb\-req-sum ([0-9a-zA-Z_]+)[ ]*(.*)$/, help: help) do |response|
25
+ opts = get_options_for_cloudwatch(response, ago: '2d', period: '300s')
26
+ elb_name = response.matches.first.first
27
+ cmd = "cloudwatch get-metric-statistics --namespace AWS/ELB --metric-name RequestCount --dimensions Name=LoadBalancerName,Value=#{elb_name} --start-time #{opts[:start_time]} --end-time #{opts[:end_time]} --period #{opts[:period]} --statistics Sum"
28
+ data = exec_cli_json(cmd, opts[:cmd_opts])
29
+ render_cloudwatch_data(response, data, 'Sum')
30
+ end
31
+
32
+ help = { 'aws rds-space {RDS Identifier}[ --profile NAME]' => 'Show RDS instance current disk space in GB.' }
33
+ route(/aws rds\-space ([0-9a-zA-Z_]+)[ ]*(.*)$/, help: help) do |response|
34
+ opts = get_options_for_cloudwatch(response)
35
+ rds = response.matches.first.first
36
+ start_time = (Time.now.utc - (12 * 60 * 60)).strftime("%Y-%m-%dT%H:00")
37
+ end_time = Time.now.utc.strftime("%Y-%m-%dT%H:00")
38
+ cmd = "cloudwatch get-metric-statistics --namespace AWS/RDS --metric-name FreeStorageSpace --dimensions Name=DBInstanceIdentifier,Value=#{rds} --start-time #{start_time} --end-time #{end_time} --period 120 --statistics Minimum"
39
+ data = convert_datapoints(exec_cli_json(cmd, opts[:cmd_opts]), 'Minimum')
40
+ render(response, "Free space of #{rds}:\n #{(data.last || []).last}")
41
+ end
42
+
43
+ private
44
+
45
+ def get_options_for_cloudwatch(response, defaults = {})
46
+ results = {}
47
+ opts = get_options(response)
48
+ defaults.each { |k, v| results[k] = (opts.delete(k) || v) }
49
+
50
+ if results[:ago]
51
+ results[:start_time] = (Time.now - (results[:ago].to_i) * (60 * 60 * 24)).utc.strftime("%Y-%m-%dT%H:00")
52
+ results[:end_time] = Time.now.utc.strftime("%Y-%m-%dT%H:00")
53
+ end
54
+ results[:period] = results[:period].to_i if results[:period]
55
+
56
+ results[:cmd_opts] = opts
57
+ results
58
+ end
59
+
60
+ def render_cloudwatch_data(response, data, cal = 'Average')
61
+ data = convert_datapoints(data, cal)
62
+ render(response, format_timeline(data))
63
+ end
64
+
65
+ def convert_datapoints(data, cal)
66
+ data['Datapoints'].map do |d|
67
+ unit = unit_name(d['Unit'])
68
+ value = convert_value(d['Unit'], d[cal])
69
+ [ d['Timestamp'], "#{value}#{unit}"]
70
+ end.sort_by { |d| Time.parse(d[0]).to_i }
71
+ end
72
+
73
+ def unit_name(unit)
74
+ case unit
75
+ when 'Percent' then '%'
76
+ when 'Bytes' then 'GB'
77
+ else ''
78
+ end
79
+ end
80
+
81
+ def convert_value(unit, value)
82
+ case unit
83
+ when 'Percent' then value.round(2)
84
+ when 'Bytes' then (value / 1024 / 1024 / 1024).round(1)
85
+ else value
86
+ end
87
+
88
+ end
89
+
90
+ Lita.register_handler(AwsCloudWatchHandler)
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,44 @@
1
+ module Lita
2
+ module Handlers
3
+ class AwsEc2 < AwsBaseHandler
4
+
5
+ help = { 'aws ec2-instances[ --profile NAME]' => 'List instances on EC2.'}
6
+ route(/aws ec2\-instances[ ]*(.*)$/, help: help) do |response|
7
+ data = exec_cli_json('ec2 describe-instances', get_options(response))
8
+ instances = data['Reservations'].map do |tmp|
9
+ tmp['Instances'].map { |instance| ec2_to_hash(instance) }
10
+ end.flatten
11
+ response.reply format_hash_list_with_title(:name, instances)
12
+ end
13
+
14
+ help = { 'aws ec2-create-ami {Instance ID} {AMI name}[ --profile NAME]' => 'Create AMI from EC2 instance.' }
15
+ route(/aws ec2\-create\-ami ([i][\-][^ ]+)[ ]+([^ ]+)[ ]*(.*)$/, help: help) do |response|
16
+ opts = get_options(response)
17
+ instance_id = response.matches.first[0]
18
+ ami_name = response.matches.first[1]
19
+ data = exec_cli_json("ec2 create-image --instance-id #{instance_id} --name #{ami_name} --no-reboot", opts)
20
+ ami_id = data['ImageId']
21
+ render response, "Your AMI ID: #{ami_id}"
22
+ end
23
+
24
+ help = { 'aws ec2-ami {AMI ID}[ --profile NAME]' => 'Show AMI detail.' }
25
+ route(/aws ec2\-ami ([a][m][i][\-][^ ]+)[ ]*(.*)$/, help: help) do |response|
26
+ opts = get_options(response)
27
+ ami_id = response.matches.first[0]
28
+ data = exec_cli_json("ec2 describe-images --image-ids #{ami_id}", opts)
29
+ data = data['Images'].map { |img| ami_to_hash(img) }
30
+ render response, format_hash_list_with_title(:name, data)
31
+ end
32
+
33
+ help = { 'aws ec2-amis[ --profile NAME]' => 'Show AMI detail.' }
34
+ route(/aws ec2\-amis[ ]*(.*)$/, help: help) do |response|
35
+ opts = get_options(response)
36
+ data = exec_cli_json("ec2 describe-images --owners #{account_id(opts)}", opts)
37
+ data = data['Images'].map { |img| ami_to_hash(img) }
38
+ render response, format_hash_list_with_title(:name, data)
39
+ end
40
+
41
+ Lita.register_handler(AwsEc2)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,57 @@
1
+ module Lita
2
+ module Handlers
3
+ class AwsElbHandler < AwsBaseHandler
4
+
5
+ help = { 'aws elbs[ --profile NAME]' => 'List all ELB.'}
6
+ route(/aws elbs[ ]*(.*)$/, help: help) do |response|
7
+ opts = get_options(response)
8
+ data = exec_cli_json('elb describe-load-balancers', opts)
9
+ res = data['LoadBalancerDescriptions'].map do |elb|
10
+ { name: elb['LoadBalancerName'],
11
+ dns: elb['DNSName'],
12
+ listeners: elb['ListenerDescriptions'].map { |l| l['Listener']['Protocol'] },
13
+ instances: elb['Instances'].map { |i| i['InstanceId'] },
14
+ instance_count: elb['Instances'].count
15
+ }
16
+ end
17
+ render(response, format_hash_list_with_title(:name, res))
18
+ end
19
+
20
+ help = { 'aws elb {ELB name}[ --profile NAME]' => 'Show single ELB details.' }
21
+ route(/aws elb ([^ ]+)[ ]*(.*)$/, help: help) do |response|
22
+ opts = get_options(response)
23
+ elb = response.matches.first[0]
24
+ data = exec_cli_json('elb describe-load-balancers --load-balancer-names ' + elb, opts)
25
+ instance_ids = data['LoadBalancerDescriptions'].map { |e| e['Instances'].map { |i| i['InstanceId'] } }.flatten
26
+ if instance_ids.size > 0
27
+ instances = exec_cli_json("ec2 describe-instances --instance-ids \"#{instance_ids.join('" "')}\"", opts)
28
+ instances = instances['Reservations'].map { |r| r['Instances'] }.flatten
29
+ else
30
+ instances = []
31
+ end
32
+ res = instances.map { |instance| ec2_to_hash(instance) }
33
+ render(response, "ELB #{elb} instances:\n" + format_hash_list_with_title(:name, res))
34
+ end
35
+
36
+ help = { 'aws elb-remove-instance {ELB name} {Instance ID}[ --profile NAME]' => 'Remove instance from ELB' }
37
+ route(/aws elb\-remove\-instance ([^ ]+)[ ]+([i][\-][^ ]+)[ ]*(.*)$/, help: help) do |response|
38
+ opts = get_options(response)
39
+ elb = response.matches.first[0]
40
+ ec2 = response.matches.first[1]
41
+ data = exec_cli_json("elb deregister-instances-from-load-balancer --load-balancer-name #{elb} --instances #{ec2}", opts)
42
+ render(response, "removed!\nType `aws elb #{elb} #{response.matches.first[2]}` to check current online instances.")
43
+ end
44
+
45
+ help = { 'aws ele-add-instance {ELB name} {Instance ID}[ --profile NAME]' => 'Attach instance to ELB.' }
46
+ route(/aws elb\-add\-instance ([^ ]+)[ ]+([i][\-][^ ]+)[ ]*(.*)$/, help: help) do |response|
47
+ opts = get_options(response)
48
+ elb = response.matches.first[0]
49
+ ec2 = response.matches.first[1]
50
+ data = exec_cli_json("elb register-instances-with-load-balancer --load-balancer-name #{elb} --instances #{ec2}", opts)
51
+ render(response, "Attached!\nType `aws elb #{elb} #{response.matches.first[2]}` to check current online instances.")
52
+ end
53
+
54
+ Lita.register_handler(AwsElbHandler)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,39 @@
1
+ module Lita
2
+ module Handlers
3
+ class AwsProfile < AwsBaseHandler
4
+
5
+ help = { 'aws profile' => 'list all aws profile.'}
6
+ route(/aws profile$/, help: help) do |response|
7
+ config_text = `cat ~/.aws/config`
8
+ profiles = ['default'] + config_text.scan(/\[profile ([a-z0-9A-Z\-_]+)\]\n/).map(&:first)
9
+ attrs = ['region', 'aws_access_key_id']
10
+ results = profiles.inject({}) do |h, e|
11
+ h.merge(e => attrs.inject({}) do |hh, ee|
12
+ profile = e == 'default' ? '' : "--profile #{e}"
13
+ hh.merge(ee => `aws configure get #{ee} #{profile}`.gsub("\n", ''))
14
+ end)
15
+ end
16
+ lines = results.to_a.inject([]) { |a, e| a + ["#{e[0]}: #{e[1].values.join(', ')}"] }
17
+ response.reply(lines.join("\n"))
18
+ end
19
+
20
+ help = { 'aws profile {name} {region} {api key} {secret key}' => 'Create or update aws profile credentials and region. If use \'default\' as name, it would set to default profile.'}
21
+ route(/aws profile ([a-zA-Z\-0-9]+) ([a-z\-0-9]+) ([^ ]+) ([^ ]+)/, help: help) do |response|
22
+ name, @region, @aws_access_key_id, @aws_secret_access_key = response.matches.first
23
+ cmd_postfix = name == 'default' ? '' : "--profile #{name}"
24
+ ['region', 'aws_access_key_id', 'aws_secret_access_key'].each do |attr|
25
+ `aws configure set #{attr} #{instance_variable_get("@#{attr}")} #{cmd_postfix}`
26
+ end
27
+ response.reply("Set profile #{name}:\n region: #{@region}\n aws_access_key_id: #{@aws_access_key_id}\n aws_secret_access_key: #{@aws_secret_access_key}")
28
+ end
29
+
30
+ help = { 'aws account-id[ --profile NAME]' => 'Get your aws account id.' }
31
+ route(/aws account\-id[ ]*(.*)$/, help: help) do |response|
32
+ opts = get_options(response)
33
+ render response, "Your AWS account id: #{account_id(opts)}"
34
+ end
35
+
36
+ Lita.register_handler(AwsProfile)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,20 @@
1
+ module Lita
2
+ module Handlers
3
+ class Aws < Handler
4
+
5
+ help = { 'aws [service] help' => 'Get command options help of [service].' }
6
+ route(/aws (.+) help$/, help: help) do |response|
7
+ service = response.matches[0][0]
8
+ text = `aws #{service} help|cat`
9
+ response.reply(text.gsub("\n\n", "\n"))
10
+ end
11
+
12
+ help = { 'aws-cli [command]' => 'Execute aws-cli.' }
13
+ route(/aws\-cli (.+)$/, help: help) do |response|
14
+ response.reply(`aws #{response.matches.first[0]}`)
15
+ end
16
+
17
+ Lita.register_handler(self)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ require 'json'
2
+ module LitaAws
3
+ module Base
4
+
5
+ protected
6
+
7
+ def exec_cli(cmd, opts = {})
8
+ cmd_postfix = opts.to_a.map { |e| "--#{e.first} #{e.last}"}.join(' ')
9
+ `aws #{cmd} #{cmd_postfix}`
10
+ end
11
+
12
+ def exec_cli_json(cmd, opts = {})
13
+ JSON.parse exec_cli(cmd, opts)
14
+ end
15
+
16
+ def render(response, text)
17
+ # TODO: debug here
18
+ response.reply(text)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ require 'json'
2
+ module LitaAws
3
+ module Data
4
+ protected
5
+
6
+ def ec2_to_hash(instance)
7
+ {
8
+ instance_id: instance['InstanceId'],
9
+ name: instance['Tags'].select { |d| d['Key'] == 'Name' }.first['Value'],
10
+ public_dns: instance['PublicDnsName'],
11
+ public_ip: instance['PublicIpAddress'],
12
+ state: instance['State']['Name'],
13
+ security_group: instance['SecurityGroups'].first['GroupName'],
14
+ type: instance['InstanceType'],
15
+ }
16
+ end
17
+
18
+ def ami_to_hash(ami)
19
+ {
20
+ name: ami['Name'],
21
+ id: ami['ImageId'],
22
+ state: ami['State'],
23
+ type: ami['ImageType'],
24
+ desc: ami['Description']
25
+ }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ module LitaAws
2
+ module Parser
3
+
4
+ protected
5
+
6
+ def get_options(response)
7
+ parse_options(response.matches.first.last.to_s)
8
+ end
9
+
10
+ def parse_options(opt_str)
11
+ opt_str.scan(/\-\-([ a-zA-Z0-9\-]+?)[ ]+([^ ]+)/).inject({}) do |h, groups|
12
+ h.merge(groups[0].to_sym => groups[1])
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ module LitaAws
2
+ module ReplyFormatter
3
+
4
+ protected
5
+
6
+ def format_timeline(array)
7
+ array.map { |d| "#{d[0]} : #{d[1]}" }.join("\n")
8
+ end
9
+
10
+ def format_hash_list_with_title(title_key, hash_list)
11
+ lines = []
12
+ hash_list.each do |hash|
13
+ lines << hash[title_key]
14
+ hash.reject { |k, _| k == title_key }.each do |col, v|
15
+ lines << " #{col}: #{v}"
16
+ end
17
+ lines << '---------------------'
18
+ end
19
+ lines.join("\n")
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ module LitaAws
2
+ module Scripts
3
+ protected
4
+
5
+ def account_id(opts = {})
6
+ unless @account_id
7
+ data = exec_cli_json('ec2 describe-security-groups --group-names default', opts)
8
+ @account_id = data['SecurityGroups'].first['OwnerId']
9
+ end
10
+ @account_id
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module LitaAws
2
+ VERSION = '0.1.0'
3
+ end
data/lib/lita-aws.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'lita'
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join('..', '..', 'locales', '*.yml'), __FILE__
5
+ )]
6
+
7
+
8
+ # modules
9
+ require 'lita-aws/version'
10
+ require 'lita-aws/base'
11
+ require 'lita-aws/reply_formatter'
12
+ require 'lita-aws/parser'
13
+ require 'lita-aws/data'
14
+ require 'lita-aws/scripts'
15
+
16
+ # handlers
17
+ require 'lita/handlers/aws-base-handler'
18
+ require 'lita/handlers/aws'
19
+ require 'lita/handlers/aws-profile'
20
+ require 'lita/handlers/aws-ec2'
21
+ require 'lita/handlers/aws-cloudwatch'
22
+ require 'lita/handlers/aws-elb'
23
+ # require 'lita/handlers/aws-rds'
24
+
25
+ Lita::Handlers::Aws.template_root File.expand_path(
26
+ File.join('..', '..', 'templates'),
27
+ __FILE__
28
+ )
29
+
data/lita-aws.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
2
+ require 'lita-aws/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "lita-aws"
6
+ spec.version = LitaAws::VERSION
7
+ spec.authors = ["marsz"]
8
+ spec.email = ["marsz330@gmail.com"]
9
+ spec.description = "Lita plugin for managing AWS services on multple accounts"
10
+ spec.summary = "Lita plugin for managing AWS services on multple accounts"
11
+ spec.homepage = "https://github.com/marsz/lita-aws"
12
+ spec.license = "MIT"
13
+ spec.metadata = { "lita_plugin_type" => "handler" }
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "lita", ">= 4.7"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "pry-byebug"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rack-test"
26
+ spec.add_development_dependency "rspec", ">= 3.0.0"
27
+ spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency "coveralls"
29
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ aws:
@@ -0,0 +1,4 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::Aws, lita_handler: true do
4
+ end
@@ -0,0 +1,14 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start { add_filter "/spec/" }
8
+
9
+ require "lita-aws"
10
+ require "lita/rspec"
11
+
12
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
13
+ # was generated with Lita 4, the compatibility mode should be left disabled.
14
+ Lita.version_3_compatibility_mode = false
File without changes
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-aws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - marsz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Lita plugin for managing AWS services on multple accounts
126
+ email:
127
+ - marsz330@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - Gemfile
135
+ - README.md
136
+ - Rakefile
137
+ - TODO.md
138
+ - lib/lita-aws.rb
139
+ - lib/lita-aws/base.rb
140
+ - lib/lita-aws/data.rb
141
+ - lib/lita-aws/parser.rb
142
+ - lib/lita-aws/reply_formatter.rb
143
+ - lib/lita-aws/scripts.rb
144
+ - lib/lita-aws/version.rb
145
+ - lib/lita/handlers/aws-base-handler.rb
146
+ - lib/lita/handlers/aws-cloudwatch.rb
147
+ - lib/lita/handlers/aws-ec2.rb
148
+ - lib/lita/handlers/aws-elb.rb
149
+ - lib/lita/handlers/aws-profile.rb
150
+ - lib/lita/handlers/aws.rb
151
+ - lita-aws.gemspec
152
+ - locales/en.yml
153
+ - spec/lita/handlers/aws_spec.rb
154
+ - spec/spec_helper.rb
155
+ - templates/.gitkeep
156
+ homepage: https://github.com/marsz/lita-aws
157
+ licenses:
158
+ - MIT
159
+ metadata:
160
+ lita_plugin_type: handler
161
+ post_install_message:
162
+ rdoc_options: []
163
+ require_paths:
164
+ - lib
165
+ required_ruby_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ requirements: []
176
+ rubyforge_project:
177
+ rubygems_version: 2.6.8
178
+ signing_key:
179
+ specification_version: 4
180
+ summary: Lita plugin for managing AWS services on multple accounts
181
+ test_files:
182
+ - spec/lita/handlers/aws_spec.rb
183
+ - spec/spec_helper.rb