contexto 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rubocop.yml +32 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +81 -0
- data/Rakefile +10 -0
- data/bin/console +11 -0
- data/bin/contexto +35 -0
- data/bin/setup +8 -0
- data/contexto.gemspec +30 -0
- data/lib/contexto/contextualize.rb +112 -0
- data/lib/contexto/display.rb +70 -0
- data/lib/contexto/version.rb +4 -0
- data/lib/contexto.rb +7 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 54035544f0eb7fa0de0c9dad30c43354f408983e
|
4
|
+
data.tar.gz: 877daecadcdd6eee388e035574aa28fbe709d846
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8c75520a641dba12b5f3bcf7060cd93840eb8f6ccec8e8edca845fa59641478326e73535a14616bad5134b6a11a51e484194863d448514f528d37f303add9193
|
7
|
+
data.tar.gz: c2d00df3d0e5f80c4be26b468f7ef1f88ba26b8efc74f7369e475c50ea8a31b9d12aa9d1610ecdcd53cd69622ab94e72396db966d0fc63ae7adcf891e362292b
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# intentional decisions
|
2
|
+
Style/RaiseArgs:
|
3
|
+
EnforcedStyle: compact
|
4
|
+
Style/Documentation:
|
5
|
+
Enabled: false
|
6
|
+
Style/MutableConstant:
|
7
|
+
Enabled: false
|
8
|
+
Style/Lambda:
|
9
|
+
EnforcedStyle: literal
|
10
|
+
Metrics/LineLength:
|
11
|
+
Max: 300
|
12
|
+
Metrics/MethodLength:
|
13
|
+
Max: 25
|
14
|
+
Metrics/AbcSize:
|
15
|
+
Enabled: false
|
16
|
+
Style/IndentArray:
|
17
|
+
EnforcedStyle: consistent
|
18
|
+
Style/IndentHash:
|
19
|
+
EnforcedStyle: consistent
|
20
|
+
Style/AlignParameters:
|
21
|
+
EnforcedStyle: with_fixed_indentation
|
22
|
+
Metrics/BlockLength:
|
23
|
+
Exclude:
|
24
|
+
- 'test/**/*_test.rb'
|
25
|
+
- '**/*.rake'
|
26
|
+
Metrics/ClassLength:
|
27
|
+
Exclude:
|
28
|
+
- 'test/**/*_test.rb'
|
29
|
+
Style/MultilineMethodCallIndentation:
|
30
|
+
EnforcedStyle: indented
|
31
|
+
Style/FrozenStringLiteralComment:
|
32
|
+
EnforcedStyle: never
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at james@lovedthanlost.net. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 James Turnbull
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Contexto
|
2
|
+
|
3
|
+
The Contexto gem gives you information about the current state of ECS resources and more specifically the internal IP address of specific containers.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install via the command line.
|
8
|
+
|
9
|
+
```shelll
|
10
|
+
$ gem install contexto
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Run the binary to check on the status of a cluster or service.
|
16
|
+
|
17
|
+
### Cluster
|
18
|
+
|
19
|
+
```shell
|
20
|
+
$ contexto -c sandbox
|
21
|
+
|
22
|
+
** Contexto Contextualizes **
|
23
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
24
|
+
|
25
|
+
Cluster sandbox
|
26
|
+
|
27
|
+
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
|
28
|
+
┃ Name ┃ Status ┃ Instances ┃ Services ┃ RunningTasks ┃ PendingTasks ┃
|
29
|
+
┣━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━┫
|
30
|
+
┃ sandbox ┃ ACTIVE ┃ 4 ┃ 3 ┃ 3 ┃ 0 ┃
|
31
|
+
┗━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
|
32
|
+
```
|
33
|
+
|
34
|
+
### Service
|
35
|
+
|
36
|
+
```shell
|
37
|
+
$ contexto -c sandbox -s backend-app
|
38
|
+
|
39
|
+
** Contexto Contextualizes **
|
40
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
41
|
+
|
42
|
+
Cluster sandbox
|
43
|
+
|
44
|
+
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
|
45
|
+
┃ Name ┃ Status ┃ Instances ┃ Services ┃ RunningTasks ┃ PendingTasks ┃
|
46
|
+
┣━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━┫
|
47
|
+
┃ sandbox ┃ ACTIVE ┃ 4 ┃ 3 ┃ 3 ┃ 0 ┃
|
48
|
+
┗━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
|
49
|
+
|
50
|
+
Service backend-app
|
51
|
+
|
52
|
+
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
|
53
|
+
┃ Name ┃ Status ┃ Desired ┃ Running ┃ Pending ┃
|
54
|
+
┣━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━┫
|
55
|
+
┃ backend-app ┃ ACTIVE ┃ 1 ┃ 1 ┃ 0 ┃
|
56
|
+
┗━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
|
57
|
+
|
58
|
+
Containers
|
59
|
+
|
60
|
+
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
|
61
|
+
┃ Container ┃ Status ┃ IP ┃
|
62
|
+
┣━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━┫
|
63
|
+
┃ sidekiq ┃ RUNNING ┃ 10.2.1.218 ┃
|
64
|
+
┣━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━┫
|
65
|
+
┃ app ┃ RUNNING ┃ 10.2.1.218 ┃
|
66
|
+
┗━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
|
67
|
+
```
|
68
|
+
|
69
|
+
## Development
|
70
|
+
|
71
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
72
|
+
|
73
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jamtur01/contexto. 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.
|
78
|
+
|
79
|
+
## License
|
80
|
+
|
81
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'contexto'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require 'pry'
|
11
|
+
Pry.start
|
data/bin/contexto
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path('../../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'contexto'
|
8
|
+
require 'optparse'
|
9
|
+
require 'English'
|
10
|
+
|
11
|
+
options = {}
|
12
|
+
options[:cluster] = 'sandbox'
|
13
|
+
|
14
|
+
optparse = OptionParser.new do |opts|
|
15
|
+
opts.banner = 'Usage: contexto [options]'
|
16
|
+
opts.on('-c', '--cluster CLUSTER', 'Cluster') { |v| options[:cluster] = v }
|
17
|
+
opts.on('-s', '--service SERVICE', 'Service') { |v| options[:service] = v }
|
18
|
+
opts.on('-t', '--container CONTAINER', 'Container') { |v| options[:container] = v }
|
19
|
+
end
|
20
|
+
|
21
|
+
begin
|
22
|
+
optparse.parse!
|
23
|
+
mandatory = [:cluster]
|
24
|
+
missing = mandatory.select { |param| options[param].nil? }
|
25
|
+
unless missing.empty?
|
26
|
+
raise OptionParser::MissingArgument.new(missing.join(', '))
|
27
|
+
end
|
28
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
29
|
+
puts $ERROR_INFO.to_s
|
30
|
+
puts optparse
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
c = Contexto::Contextualize.new(options)
|
35
|
+
c.show
|
data/bin/setup
ADDED
data/contexto.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'contexto/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'contexto'
|
8
|
+
spec.version = Contexto::VERSION
|
9
|
+
spec.authors = ['James Turnbull']
|
10
|
+
spec.email = ['james@lovedthanlost.net']
|
11
|
+
spec.summary = 'Shows you context for ECS services and containers.'
|
12
|
+
spec.homepage = 'https://github.com/EmpaticoOrg/contexto'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = 'bin'
|
19
|
+
spec.executables = %w(contexto)
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'aws-sdk', '~> 2'
|
23
|
+
spec.add_dependency 'command_line_reporter'
|
24
|
+
spec.add_dependency 'slack-ruby-client', '~> 0.8.0'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
27
|
+
spec.add_development_dependency 'pry', '~> 0.10.4'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
30
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
# Context
|
4
|
+
module Contexto
|
5
|
+
# ECS class
|
6
|
+
class Contextualize
|
7
|
+
attr_reader :display, :cluster, :service
|
8
|
+
|
9
|
+
def initialize(params = {})
|
10
|
+
@cluster = params.fetch(:cluster)
|
11
|
+
@service = params.fetch(:service) if params[:service]
|
12
|
+
@container = params.fetch(:container) if params[:container]
|
13
|
+
@display = Contexto::Display.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def show
|
17
|
+
cluster
|
18
|
+
puts "\n"
|
19
|
+
return unless @service
|
20
|
+
service
|
21
|
+
puts "\n"
|
22
|
+
tasks
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def cluster
|
28
|
+
resp = ecs_client.describe_clusters(
|
29
|
+
clusters: [
|
30
|
+
@cluster
|
31
|
+
]
|
32
|
+
)
|
33
|
+
title = "Cluster #{@cluster}"
|
34
|
+
headings = %w(Name Status Instances Services RunningTasks PendingTasks)
|
35
|
+
cluster = resp.clusters[0].to_h
|
36
|
+
rows = []
|
37
|
+
rows << [cluster[:cluster_name], cluster[:status], cluster[:registered_container_instances_count], cluster[:active_services_count], cluster[:running_tasks_count], cluster[:pending_tasks_count]]
|
38
|
+
@display.create_display(title, headings, rows)
|
39
|
+
end
|
40
|
+
|
41
|
+
def service
|
42
|
+
resp = ecs_client.describe_services(
|
43
|
+
cluster: @cluster,
|
44
|
+
services: [
|
45
|
+
@service
|
46
|
+
]
|
47
|
+
)
|
48
|
+
title = "Service #{@service}"
|
49
|
+
headings = %w(Name Status Desired Running Pending)
|
50
|
+
service = resp.services[0].to_h
|
51
|
+
rows = []
|
52
|
+
rows << [service[:service_name], service[:status], service[:desired_count], service[:running_count], service[:pending_count]]
|
53
|
+
@display.create_display(title, headings, rows)
|
54
|
+
rescue Aws::ECS::Errors::ServiceNotFoundException
|
55
|
+
puts 'Service not found'
|
56
|
+
end
|
57
|
+
|
58
|
+
def tasks
|
59
|
+
resp = ecs_client.describe_tasks(
|
60
|
+
cluster: @cluster,
|
61
|
+
tasks: [task_arn]
|
62
|
+
)
|
63
|
+
task = resp.tasks[0].to_h
|
64
|
+
containers = task[:containers]
|
65
|
+
ec2_instance_id = describe_container_instance(task[:container_instance_arn])
|
66
|
+
title = 'Containers'
|
67
|
+
headings = %w(Container Status IP)
|
68
|
+
rows = []
|
69
|
+
containers.each do |container|
|
70
|
+
rows << [container[:name], container[:last_status], describe_instances(ec2_instance_id)]
|
71
|
+
end
|
72
|
+
@display.create_display(title, headings, rows)
|
73
|
+
end
|
74
|
+
|
75
|
+
def task_arn
|
76
|
+
resp = ecs_client.list_tasks(
|
77
|
+
cluster: @cluster,
|
78
|
+
service_name: @service
|
79
|
+
)
|
80
|
+
resp.task_arns[0]
|
81
|
+
end
|
82
|
+
|
83
|
+
def describe_container_instance(container_instance_arn)
|
84
|
+
resp = ecs_client.describe_container_instances(
|
85
|
+
cluster: @cluster,
|
86
|
+
container_instances: [
|
87
|
+
container_instance_arn
|
88
|
+
]
|
89
|
+
)
|
90
|
+
resp.container_instances[0].ec2_instance_id
|
91
|
+
end
|
92
|
+
|
93
|
+
def describe_instances(ec2_instance_id)
|
94
|
+
resp = ec2_client.describe_instances(
|
95
|
+
instance_ids: [ec2_instance_id]
|
96
|
+
)
|
97
|
+
resp.reservations[0].instances[0].private_ip_address
|
98
|
+
end
|
99
|
+
|
100
|
+
def region_name
|
101
|
+
ENV['AWS_REGION'] || 'us-east-1'
|
102
|
+
end
|
103
|
+
|
104
|
+
def ecs_client
|
105
|
+
Aws::ECS::Client.new(region: region_name.to_s)
|
106
|
+
end
|
107
|
+
|
108
|
+
def ec2_client
|
109
|
+
Aws::EC2::Client.new(region: region_name.to_s)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'command_line_reporter'
|
2
|
+
|
3
|
+
# Context
|
4
|
+
module Contexto
|
5
|
+
# Display class
|
6
|
+
class Display
|
7
|
+
include CommandLineReporter
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@header = '** Contexto Contextualizes **'
|
11
|
+
puts "\n"
|
12
|
+
header title: @header,
|
13
|
+
width: 80,
|
14
|
+
align: 'center',
|
15
|
+
rule: true,
|
16
|
+
color: 'green',
|
17
|
+
bold: true
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_display(title, headings, rows)
|
21
|
+
@title = title
|
22
|
+
@headings = headings
|
23
|
+
@rows = rows
|
24
|
+
create_new_table
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_new_table
|
28
|
+
if @title
|
29
|
+
header title: @title,
|
30
|
+
width: 50,
|
31
|
+
align: 'left',
|
32
|
+
color: 'red',
|
33
|
+
bold: true
|
34
|
+
end
|
35
|
+
table(border: true) do
|
36
|
+
row header: true do
|
37
|
+
@headings.each do |h|
|
38
|
+
column(h, headings_options)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
@rows.each do |r|
|
42
|
+
row do
|
43
|
+
r.each do |rr|
|
44
|
+
column(rr, row_options)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def headings_options
|
52
|
+
{
|
53
|
+
align: 'center',
|
54
|
+
width: col_width
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def row_options
|
59
|
+
{
|
60
|
+
align: 'center',
|
61
|
+
width: col_width,
|
62
|
+
color: 'green'
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
def col_width
|
67
|
+
@col_width ||= @rows.map(&:size).max + 6
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/contexto.rb
ADDED
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: contexto
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Turnbull
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: command_line_reporter
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: slack-ruby-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.8.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.8.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.10.4
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.10.4
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '5.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '5.0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- james@lovedthanlost.net
|
114
|
+
executables:
|
115
|
+
- contexto
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- ".travis.yml"
|
122
|
+
- CODE_OF_CONDUCT.md
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/contexto
|
129
|
+
- bin/setup
|
130
|
+
- contexto.gemspec
|
131
|
+
- lib/contexto.rb
|
132
|
+
- lib/contexto/contextualize.rb
|
133
|
+
- lib/contexto/display.rb
|
134
|
+
- lib/contexto/version.rb
|
135
|
+
homepage: https://github.com/EmpaticoOrg/contexto
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
metadata: {}
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 2.5.2
|
156
|
+
signing_key:
|
157
|
+
specification_version: 4
|
158
|
+
summary: Shows you context for ECS services and containers.
|
159
|
+
test_files: []
|