lita-aws-ecs 0.1.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe16c0690b7a6a4b80c9f28bd514d25ed5222de0380add07b1c2974550d3b213
4
- data.tar.gz: f17df8634a2dd3227fdf02a83a9a940cc0b1f2bd4e5f91c02c821730f4351b74
3
+ metadata.gz: 3a0d37de4fea3f2d4fe8ededcabf6d978ac6306507062a174e7045606f059301
4
+ data.tar.gz: 7e2c64de2166722f7745c6f8147376e006b3c54c483abfc895c586c31890b518
5
5
  SHA512:
6
- metadata.gz: 248a2093cc7a02c60cd6eb7372f7daaeb3a7b63153283f8c23ee1c750f78d78630be2b89454638b3d6d0c0a1cc5972795787df5adf4607c610404d692073f7ab
7
- data.tar.gz: cec1b562a39666c1ca59c445ac498640066dc6a2c7f7db09635857867f6c981153a8b53ed0f7591e1f1a6eb71a3fef8af192f8d1bea8dd3211072ff11d6982f4
6
+ metadata.gz: f3d4c682c52651cc161c5c210f0de05615670e4dfa9034bc04f3cb008a341a65edbd9ce774fb6a5ce7cad07b82455b9341e1718cc421bd0db3510302487fc9d4
7
+ data.tar.gz: 3416e1d7043934353a6243aa6443e696455d122136ca14be3f9910a5511e24686dd8bf9642bec2c17b7e8bc7b08a397b63f1a7c52b23f8bbd81d17373a296dc1
@@ -54,7 +54,7 @@ jobs:
54
54
  environment:
55
55
  RAILS_ENV: test
56
56
  COVERAGE: true
57
- CODECOV_TOKEN: c8c31078-b811-4301-bd35-c36e14cfc075
57
+ CODECOV_TOKEN: 4d137656-ace8-424a-afc1-28e03b45b45a
58
58
  command: bundle exec rspec
59
59
  workflows:
60
60
  version: 2.1
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
55
55
  ## Enforcement
56
56
 
57
57
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at unhappychoice@gmail.com. All
58
+ reported by contacting the project team at seibii.it@seibii.com. All
59
59
  complaints will be reviewed and investigated and will result in a response that
60
60
  is deemed necessary and appropriate to the circumstances. The project team is
61
61
  obligated to maintain confidentiality with regard to the reporter of an incident.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lita-aws-ecs (0.1.0)
4
+ lita-aws-ecs (1.0.0)
5
5
  aws-sdk-ecs (~> 1)
6
6
  lita (>= 4.7)
7
7
 
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 Yuji Ueki
3
+ Copyright (c) 2019 Seibii, Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1 +1,57 @@
1
+ # lita-aws-ecs
2
+ [![Gem Version](https://badge.fury.io/rb/lita-aws-ecs.svg)](https://badge.fury.io/rb/lita-aws-ecs)
3
+ [![Circle CI](https://circleci.com/gh/seibii/lita-aws-ecs.svg?style=shield)](https://circleci.com/gh/seibii/lita-aws-ecs)
4
+ [![Code Climate](https://codeclimate.com/github/seibii/lita-aws-ecs/badges/gpa.svg)](https://codeclimate.com/github/seibii/lita-aws-ecs)
5
+ [![codecov](https://codecov.io/gh/seibii/lita-aws-ecs/branch/master/graph/badge.svg)](https://codecov.io/gh/seibii/lita-aws-ecs)
6
+ [![Libraries.io dependency status for GitHub repo](https://img.shields.io/librariesio/github/seibii/lita-aws-ecs.svg)](https://libraries.io/github/seibii/lita-aws-ecs)
7
+ ![](http://ruby-gem-downloads-badge.herokuapp.com/lita-aws-ecs?type=total)
8
+ ![GitHub](https://img.shields.io/github/license/seibii/lita-aws-ecs.svg)
1
9
 
10
+ `lita-aws-ecs` allows you to manage AWS ECS by commands.
11
+
12
+ ## Installation
13
+
14
+ Add lita-aws-ecs to your Lita instance's Gemfile:
15
+
16
+ ``` ruby
17
+ gem "lita-aws-ecs"
18
+ ```
19
+
20
+ ## Configuration
21
+ Set environment variables below.
22
+
23
+ ```
24
+ AWS_REGION=us-east-1
25
+ AWS_ACCESS_KEY_ID=xxxx
26
+ AWS_SECRET_ACCESS_KEY=xxxx
27
+ ```
28
+
29
+ or use config
30
+
31
+ ```
32
+ Lita.config.handlers.aws_ecs.aws_region = 'us-east-1'
33
+ Lita.config.handlers.aws_ecs.aws_access_key_id = 'xxxx'
34
+ Lita.config.handlers.aws_ecs.aws_secret_access_key = 'xxxx'
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ```bash
40
+ lita ecs clusters
41
+ lita ecs cluster services ${cluster_name}
42
+ lita ecs cluster tasks ${cluster_name}
43
+ lita ecs service tasks ${service_name}
44
+ lita ecs service update_task ${cluster_name} ${service_name} ${task_name:revision}
45
+ ```
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/seibii/lita-aws-ecs. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
54
+
55
+ ## Code of Conduct
56
+
57
+ Everyone interacting in the Lita::AWS::ECS project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/seibii/lita-aws-ecs/blob/master/CODE_OF_CONDUCT.md).
@@ -4,7 +4,7 @@ require 'aws-sdk-ecs'
4
4
 
5
5
  module Lita
6
6
  module Handlers
7
- class AwsEcs < Handler # rubocop:disable Metrics/ClassLength
7
+ class AwsEcs < Handler
8
8
  config :aws_region
9
9
  config :aws_access_key_id
10
10
  config :aws_secret_access_key
@@ -21,8 +21,12 @@ module Lita
21
21
  cluster_services_help = { 'ecs cluster services ${cluster_name}' => 'List ecs cluster services' }
22
22
  route(/ecs cluster services\s+([a-zA-Z0-9 -~]+)\s*$/, help: cluster_services_help) do |response|
23
23
  cluster_name = response.matches.first[0]
24
- cluster_services = client.list_services(cluster: cluster_name)
25
- response.reply(render_template('cluster_services', cluster_services: cluster_services))
24
+ services = client.list_services(cluster: cluster_name)
25
+ &.service_arns
26
+ &.map { |service| [service, service_tasks(cluster_name, service)] }
27
+ &.to_h || {}
28
+
29
+ response.reply(render_template('cluster_services', cluster_name: cluster_name, services: services))
26
30
  rescue StandardError => e
27
31
  response.reply ':rage: Error has occurred'
28
32
  response.reply e.to_s
@@ -46,68 +50,38 @@ module Lita
46
50
  help: cluster_service_tasks_help) do |response|
47
51
  cluster_name = response.matches.first[0]
48
52
  service_name = response.matches.first[1]
49
- service_tasks = service_tasks_array(cluster_name, service_name)
53
+ service_tasks = service_tasks(cluster_name, service_name)
50
54
  response.reply(render_template('service_tasks', service_tasks: service_tasks))
51
55
  rescue StandardError => e
52
56
  response.reply ':rage: Error has occurred'
53
57
  response.reply e.to_s
54
58
  end
55
59
 
56
- cluster_service_tasks_help =
57
- { 'ecs cluster component ${cluster_name}' => 'List cluster service name and task definition' }
58
- route(/ecs cluster component\s+([a-zA-Z0-9 -~]+)\s*$/,
59
- help: cluster_service_tasks_help) do |response|
60
- cluster_name = response.matches.first[0]
61
- services = client.list_services(cluster: cluster_name)
62
- cluster_component = {}
63
- services&.service_arns&.each do |service|
64
- cluster_component[service] = service_tasks_array(cluster_name, service)
65
- end
66
- response
67
- .reply(render_template(
68
- 'cluster_component',
69
- cluster_name: cluster_name,
70
- cluster_component: cluster_component
71
- ))
72
-
73
- rescue StandardError => e
74
- response.reply ':rage: Error has occurred'
75
- response.reply e.to_s
76
- end
77
-
78
60
  clusters_service_update_help =
79
- { 'ecs cluster service update ${cluster_name} ${service_name} ${task_name}' => 'Update ecs service' }
80
- route(/ecs cluster service update\s+([a-zA-Z0-9 -~]+)\s+([a-zA-Z0-9 -~]+)\s+([a-zA-Z0-9 -~]+)\s*$/,
61
+ { 'ecs cluster service update_task ${cluster_name} ${service_name} ${task_name}' => 'Update ecs service' }
62
+ route(/ecs cluster service update_task\s+([a-zA-Z0-9 -~]+)\s+([a-zA-Z0-9 -~]+)\s+([a-zA-Z0-9 -~]+)\s*$/,
81
63
  help: clusters_service_update_help) do |response|
82
64
  cluster_name = response.matches.first[0]
83
65
  service_name = response.matches.first[1]
84
66
  task_name = response.matches.first[2]
85
- service_update = client.update_service(
67
+ client.update_service(
86
68
  cluster: cluster_name,
87
69
  service: service_name,
88
70
  task_definition: task_name
89
71
  )
90
- response.reply(render_template('service_update', service_update: service_update))
72
+ response.reply("Updated #{service_name} task to #{task_name} successfully.")
91
73
  rescue StandardError => e
92
74
  response.reply ':rage: Error has occurred'
93
75
  response.reply e.to_s
94
76
  end
95
77
 
96
- private def service_tasks_array(cluster_name, service_name) # rubocop:disable Metrics/MethodLength
78
+ private def service_tasks(cluster_name, service_name)
97
79
  describe_services = client.describe_services(
98
80
  cluster: cluster_name,
99
- services: [
100
- service_name
101
- ]
81
+ services: [service_name]
102
82
  )
103
83
 
104
- describe_service_tasks = []
105
- unless describe_services.nil?
106
- describe_services.services.each do |describe_service|
107
- describe_service_tasks.push(describe_service.task_definition)
108
- end
109
- end
110
- describe_service_tasks
84
+ describe_services&.services&.map(&:task_definition) || []
111
85
  end
112
86
 
113
87
  private def client
@@ -117,6 +91,7 @@ module Lita
117
91
  secret_access_key: config.aws_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY']
118
92
  )
119
93
  end
94
+
120
95
  Lita.register_handler(self)
121
96
  end
122
97
  end
@@ -2,9 +2,9 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'lita-aws-ecs'
5
- spec.version = '0.1.0'
5
+ spec.version = '1.0.0'
6
6
  spec.authors = ['Teturo Nakamura']
7
- spec.email = ['notify_company_questionnaire']
7
+ spec.email = ['seibii.it@seibii.com']
8
8
  spec.description = 'Lita handler to manage ecs'
9
9
  spec.summary = 'Lita handler to manage ecs'
10
10
  spec.homepage = 'https://github.com/seibii/lita-aws-ecs'
Binary file
@@ -4,11 +4,10 @@ require 'spec_helper'
4
4
  describe Lita::Handlers::AwsEcs, lita_handler: true do # rubocop:disable Metrics/BlockLength
5
5
  describe 'Routing' do
6
6
  it { is_expected.to route('ecs clusters') }
7
- it { is_expected.to route('ecs cluster services cluster') }
8
- it { is_expected.to route('ecs cluster tasks cluster') }
9
- it { is_expected.to route('ecs cluster service tasks cluster service') }
10
- it { is_expected.to route('ecs cluster component cluster') }
11
- it { is_expected.to route('ecs cluster service update cluster service task 1') }
7
+ it { is_expected.to route('ecs cluster services cluster_name') }
8
+ it { is_expected.to route('ecs cluster tasks cluster_name') }
9
+ it { is_expected.to route('ecs cluster service tasks cluster_name service_name') }
10
+ it { is_expected.to route('ecs cluster service update_task cluster_name service_name task_name 1') }
12
11
  end
13
12
 
14
13
  describe 'Behavior' do # rubocop:disable Metrics/BlockLength
@@ -63,15 +62,14 @@ describe Lita::Handlers::AwsEcs, lita_handler: true do # rubocop:disable Metrics
63
62
  end
64
63
 
65
64
  describe 'cluster services command' do # rubocop:disable Metrics/BlockLength
66
- let(:ecs_response) {}
67
-
68
65
  before do
69
66
  allow_any_instance_of(Aws::ECS::Client)
70
- .to receive_message_chain(:list_services) { ecs_response }
71
- send_message 'ecs cluster services cluster'
67
+ .to receive_messages(list_services: services, describe_services: ecs_response)
68
+ send_message 'ecs cluster services cluster_name'
72
69
  end
73
70
 
74
71
  context 'with empty cluster services response' do
72
+ let(:services) {}
75
73
  let(:ecs_response) { [] }
76
74
  let(:reply_message) { "There are no services.\n" }
77
75
 
@@ -79,16 +77,23 @@ describe Lita::Handlers::AwsEcs, lita_handler: true do # rubocop:disable Metrics
79
77
  end
80
78
 
81
79
  context 'with cluster services response' do
82
- let(:ecs_response) do
80
+ let!(:services) do
83
81
  JSON.parse(
84
82
  { service_arns: ['/service_name'] }
85
- .to_json, object_class: OpenStruct
83
+ .to_json, object_class: OpenStruct
84
+ )
85
+ end
86
+ let!(:ecs_response) do
87
+ JSON.parse(
88
+ { services: [{ task_definition: '/task_name' }] }
89
+ .to_json, object_class: OpenStruct
86
90
  )
87
91
  end
88
92
  let(:reply_message) do
89
93
  <<~MESSAGE
90
94
  --------------------------------------------------------
91
- name: service_name
95
+ service_name: service_name
96
+ attached_task: task_name
92
97
  --------------------------------------------------------
93
98
  MESSAGE
94
99
  end
@@ -99,9 +104,10 @@ describe Lita::Handlers::AwsEcs, lita_handler: true do # rubocop:disable Metrics
99
104
  context 'when something raises error' do
100
105
  before do
101
106
  allow_any_instance_of(Aws::ECS::Client)
102
- .to receive_message_chain(:update_service).and_raise(StandardError)
107
+ .to receive_message_chain(:describe_services).and_raise(StandardError)
103
108
  end
104
-
109
+ let(:services) { 'example' }
110
+ let(:ecs_response) { 'example' }
105
111
  let(:reply_message) { ':rage: Error has occurred' }
106
112
  it_behaves_like 'a command that replies message'
107
113
  end
@@ -193,89 +199,21 @@ describe Lita::Handlers::AwsEcs, lita_handler: true do # rubocop:disable Metrics
193
199
  end
194
200
  end
195
201
 
196
- describe 'clusters component command' do # rubocop:disable Metrics/BlockLength
197
- before do
198
- allow_any_instance_of(Aws::ECS::Client)
199
- .to receive_messages(list_services: services, describe_services: ecs_response)
200
- send_message 'ecs cluster component cluster'
201
- end
202
-
203
- context 'with empty cluster component response' do
204
- let(:services) {}
205
- let(:ecs_response) { [] }
206
- let(:reply_message) { "There are no cluster.\n" }
207
-
208
- it_behaves_like 'a command that replies message'
209
- end
210
-
211
- context 'with cluster component response' do
212
- let!(:services) do
213
- JSON.parse(
214
- { service_arns: ['/service_name'] }
215
- .to_json, object_class: OpenStruct
216
- )
217
- end
218
- let!(:ecs_response) do
219
- JSON.parse(
220
- { services: [{ task_definition: '/task_name' }] }
221
- .to_json, object_class: OpenStruct
222
- )
223
- end
224
- let(:reply_message) do
225
- <<~MESSAGE
226
- --------------------------------------------------------
227
- name: cluster service_name task_name
228
- --------------------------------------------------------
229
- MESSAGE
230
- end
231
-
232
- it_behaves_like 'a command that replies message'
233
- end
234
-
235
- context 'when something raises error' do
236
- before do
237
- allow_any_instance_of(Aws::ECS::Client)
238
- .to receive_message_chain(:describe_services).and_raise(StandardError)
239
- end
240
- let(:services) { 'example' }
241
- let(:ecs_response) { 'example' }
242
- let(:reply_message) { ':rage: Error has occurred' }
243
- it_behaves_like 'a command that replies message'
244
- end
245
- end
246
-
247
- describe 'clusters service update command' do # rubocop:disable Metrics/BlockLength
202
+ describe 'clusters service update_task command' do
248
203
  before do
249
204
  allow_any_instance_of(Aws::ECS::Client)
250
205
  .to receive_message_chain(:update_service) { ecs_response }
251
- send_message 'ecs cluster service update cluster service task 1'
252
- end
253
-
254
- context 'with empty clusters service updat response' do
255
- let(:ecs_response) { [] }
256
- let(:reply_message) { "There are no services parameter.\n" }
257
-
258
- it_behaves_like 'a command that replies message'
206
+ send_message 'ecs cluster service update_task cluster_name service_name task_name:1'
259
207
  end
260
208
 
261
- context 'with clusters service updat response' do
209
+ context 'with clusters service update response' do
262
210
  let(:ecs_response) do
263
211
  JSON.parse(
264
212
  { service: { service_name: 'service_name', cluster_arn: 'cluster_name', task_definition: 'task_name' } }
265
213
  .to_json, object_class: OpenStruct
266
214
  )
267
215
  end
268
- let(:reply_message) do
269
- <<~MESSAGE
270
- --------------------------------------------------------
271
- **your update servise parameter
272
- update service name : service_name
273
- service target cluster : cluster_name
274
- service target task : task_name
275
- --------------------------------------------------------
276
- MESSAGE
277
- end
278
-
216
+ let(:reply_message) { 'Updated service_name task to task_name:1 successfully.' }
279
217
  it_behaves_like 'a command that replies message'
280
218
  end
281
219
 
@@ -1,10 +1,14 @@
1
- <% if @cluster_services.empty? %>
1
+ <% if @services.empty? %>
2
2
  There are no services.
3
3
  <% else %>
4
- <% @cluster_services.service_arns.each do |service| %>
4
+ <% @services.each do |service, tasks| %>
5
+ <% tasks.sort.each do |task| %>
5
6
  --------------------------------------------------------
6
- <% /\// =~ service %>
7
- name: <%= $' %>
8
- <% end %>
7
+ <% service = service.match(/\//)%>
8
+ <% task = task.match(/\//)%>
9
+ service_name: <%= "#{service.post_match}" %>
10
+ attached_task: <%= "#{task.post_match}" %>
9
11
  --------------------------------------------------------
10
- <% end %>
12
+ <% end %>
13
+ <% end %>
14
+ <% end %>
@@ -1,7 +1,7 @@
1
1
  <% if @cluster_tasks.empty? %>
2
2
  There are no tasks.
3
3
  <% else %>
4
- <% @cluster_tasks.task_arns.each do |task| %>
4
+ <% @cluster_tasks.task_arns.sort.each do |task| %>
5
5
  --------------------------------------------------------
6
6
  <% /\// =~ task %>
7
7
  name: <%= $' %>
@@ -1,7 +1,7 @@
1
1
  <% if @clusters.empty? %>
2
2
  There are no clusters.
3
3
  <% else %>
4
- <% @clusters.cluster_arns.each do |cluster| %>
4
+ <% @clusters.cluster_arns.sort.each do |cluster| %>
5
5
  --------------------------------------------------------
6
6
  <% /\// =~ cluster %>
7
7
  name: <%= $' %>
@@ -1,7 +1,7 @@
1
1
  <% if @service_tasks.empty? %>
2
2
  There are no tasks.
3
3
  <% else %>
4
- <% @service_tasks.each do |task| %>
4
+ <% @service_tasks.sort.each do |task| %>
5
5
  --------------------------------------------------------
6
6
  <% /\// =~ task %>
7
7
  name: <%= $' %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-aws-ecs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Teturo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-03 00:00:00.000000000 Z
11
+ date: 2020-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-ecs
@@ -194,7 +194,7 @@ dependencies:
194
194
  version: '0'
195
195
  description: Lita handler to manage ecs
196
196
  email:
197
- - notify_company_questionnaire
197
+ - seibii.it@seibii.com
198
198
  executables: []
199
199
  extensions: []
200
200
  extra_rdoc_files: []
@@ -218,15 +218,14 @@ files:
218
218
  - locales/en.yml
219
219
  - locales/ja.yml
220
220
  - pkg/lita-aws-ecs-0.1.0.gem
221
+ - pkg/lita-aws-ecs-1.0.0.gem
221
222
  - spec/lita/handlers/aws_ecs_spec.rb
222
223
  - spec/spec_helper.rb
223
224
  - templates/.gitkeep
224
- - templates/cluster_component.erb
225
225
  - templates/cluster_services.erb
226
226
  - templates/cluster_tasks.erb
227
227
  - templates/clusters.erb
228
228
  - templates/service_tasks.erb
229
- - templates/service_update.erb
230
229
  homepage: https://github.com/seibii/lita-aws-ecs
231
230
  licenses:
232
231
  - MIT
@@ -1,13 +0,0 @@
1
- <% if @cluster_component.empty? %>
2
- There are no cluster.
3
- <% else %>
4
- <% @cluster_component.each do |service, tasks| %>
5
- <% tasks.each do |task| %>
6
- --------------------------------------------------------
7
- <% service = service.match(/\//)%>
8
- <% task = task.match(/\//)%>
9
- name: <%= "#{@cluster_name} #{service.post_match} #{task.post_match}" %>
10
- --------------------------------------------------------
11
- <% end %>
12
- <% end %>
13
- <% end %>
@@ -1,10 +0,0 @@
1
- <%if @service_update.empty?%>
2
- There are no services parameter.
3
- <% else %>
4
- --------------------------------------------------------
5
- **your update servise parameter
6
- update service name : <%= @service_update.service.service_name %>
7
- service target cluster : <%= @service_update.service.cluster_arn %>
8
- service target task : <%= @service_update.service.task_definition %>
9
- --------------------------------------------------------
10
- <%end %>