argonaut-cli 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fc796195ba2c2f52004caf8e903566f05beb9ef8
4
+ data.tar.gz: ea40e12fa2c5d9ce433f0d8a3e04d6fa7ab237a4
5
+ SHA512:
6
+ metadata.gz: e9c2984d8cd01203d79ca942f7856a5742d7e27a492544d95a43a859ac0f1c35c4dc5459687f4b5ad95dfdf7b4579cc7b2c5daf320ac6960c41d0ffa8fdde594
7
+ data.tar.gz: c98c8912ccc9c478ab075abea90f07b0a743aa727fb4a670d44cd1aa4b6bbd1b7176e4cb638a5337a359c71c74b1eae1f9f6cbc2224a3bf9db06c5ec2a6c9d89
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.5
5
+ before_install: gem install bundler -v 1.14.6
@@ -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 gadhikari@covermymeds.com. 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
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in argonaut.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Gopal Adhikari
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,88 @@
1
+ # Argonaut CLI
2
+
3
+ Use Argonaut from your command line!
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem install argonaut-cli
9
+ ```
10
+
11
+ Create the config file `~/.argonaut.yml` and populate it with the sample config below:
12
+
13
+ ```yaml
14
+ # The only required fields for the gem to run are api_token and url_root
15
+
16
+ api_token: YOUR_TOKEN
17
+ url_root: https://theargonaut-api.herokuapp.com
18
+
19
+ # Below are the optional settings to customize output
20
+
21
+ options:
22
+ colorize_rows: true
23
+ time_format: '%d %b %Y %l:%M %p'
24
+ high_contrast_colors: true
25
+ ```
26
+
27
+ Replace `YOUR_TOKEN` in the sample config above with your own token that can be found in the Profile page in the web app.
28
+
29
+ You can also export environment variables `ARGONAUT_API_TOKEN` and `ARGONAUT_URL_ROOT` with the correct values without needing a config file.
30
+
31
+ ## Usage
32
+
33
+ By default, invoking `argonaut` lists all your environment reservations.
34
+
35
+ **View all registered teams:**
36
+
37
+ ```
38
+ argonaut -T
39
+ ```
40
+
41
+ **View reservations table on a particular team's environments:**
42
+
43
+ Using team id
44
+ ```
45
+ argonaut -t 1
46
+ ```
47
+
48
+ Using team name
49
+ ```
50
+ argonaut -t EPA
51
+ ```
52
+
53
+ **Make a reservation:**
54
+
55
+ ```
56
+ argonaut -r pbm1:epamotron
57
+ ```
58
+
59
+ **Release when you are done testing in that environment:**
60
+
61
+ ```
62
+ argonaut -r pbm1:epamotron
63
+ ```
64
+ **Clear all your reservations at once**
65
+
66
+ ```
67
+ argonaut -c
68
+ ```
69
+
70
+ Full list of options can be viewed by running `argonaut -h`. If you are using zsh, you can generate shell completion and add it to your `~/.zshrc` like so:
71
+
72
+ ```
73
+ echo compdef _gnu_generic argonaut >> ~/.zshrc
74
+ ```
75
+
76
+ ## Development
77
+
78
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/qubbit/argonaut-cli/issues. 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.
83
+
84
+
85
+ ## License
86
+
87
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
88
+
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/argonaut.gemspec ADDED
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'argonaut/version'
6
+
7
+ EMAIL_DOMAIN = 'gmail.com'
8
+
9
+ Gem::Specification.new do |spec|
10
+ spec.name = "argonaut-cli"
11
+ spec.version = Argonaut::VERSION
12
+ spec.authors = ["Gopal Adhikari"]
13
+ spec.email = ["nullgeo@#{EMAIL_DOMAIN}"]
14
+ spec.summary = "Command line tool for Argonaut"
15
+ spec.description = "This gem lets users manipulate argonaut using the command line interface"
16
+ spec.homepage = "https://github.com/qubbit/argonaut-cli"
17
+ spec.license = "MIT"
18
+ spec.post_install_message = %Q{
19
+ ⚓️ Please follow instructions at #{spec.homepage} to complete the setup.
20
+ }
21
+
22
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
23
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
24
+ if spec.respond_to?(:metadata)
25
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
26
+ else
27
+ raise "RubyGems 2.0 or newer is required to protect against " \
28
+ "public gem pushes."
29
+ end
30
+
31
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
32
+ f.match(%r{^(test|spec|features)/})
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.14"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ spec.add_development_dependency "pry-byebug", "~> 3.4"
42
+ spec.add_development_dependency 'webmock', '~> 3.0', '>= 3.0.1'
43
+
44
+ spec.add_runtime_dependency 'httparty', '~> 0.15.6'
45
+ spec.add_runtime_dependency 'terminal-table', '~> 1.8', '>= 1.8.0'
46
+ end
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "argonaut"
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
+ require "pry"
10
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/argonaut ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ THIS_FILE = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
4
+
5
+ begin
6
+ require File.dirname(THIS_FILE) + '/../lib/argonaut'
7
+ rescue LoadError
8
+ require "#{Dir.pwd}/lib/argonaut"
9
+ end
10
+
11
+ require 'optparse'
12
+
13
+ # By default show user's reservations if no arguments are supplied
14
+ options = { action: 'list_reservations' }
15
+ options.merge! Argonaut::Settings.config.fetch(:options, {})
16
+
17
+ begin
18
+ OptionParser.new do |opts|
19
+ opts.banner = "Usage: argonaut [options]"
20
+
21
+ opts.on("-T", "--teams", "Show all teams") do |c|
22
+ options[:action] = 'show_teams'
23
+ end
24
+
25
+ opts.on("-r env:app", "--reserve env:app", "Reserve a testing environment. Passed in value should confirm to <environment>:<app_name> format") do |env_app|
26
+ options[:env_app] = env_app
27
+ options[:action] = 'reserve'
28
+ end
29
+
30
+ opts.on("-R env:app", "--release env:app", "Release a testing environment. Passed in value should confirm to <environment>:<app_name> format") do |env_app|
31
+ options[:env_app] = env_app
32
+ options[:action] = 'release'
33
+ end
34
+
35
+ opts.on("-t team_name", "--show-team team_name", "Show the status of team with the passed name") do |team_name|
36
+ options[:team] = team_name
37
+ options[:action] = 'show_status'
38
+ end
39
+
40
+ opts.on("-f app_name", "--find-app app_name", "Find all apps with passed name") do |app_name|
41
+ options[:application] = app_name
42
+ options[:action] = 'find_app'
43
+ end
44
+
45
+ opts.on("-c", "--clear", "Clears all the reservations made by you") do |clear|
46
+ options[:action] = "clear_reservations"
47
+ end
48
+
49
+ opts.on("-l", "--list", "List all your reservations") do |clear|
50
+ options[:action] = "list_reservations"
51
+ end
52
+
53
+ opts.on("-G", "--[no-]color", "Colorize table rows for team status when there is reservations") do |colorize|
54
+ options[:colorize_rows] = colorize
55
+ end
56
+
57
+ opts.on("-v", "--[no-]verbose", "Run the application logging information about things that happen under the hood") do |v|
58
+ options[:verbose] = v
59
+ end
60
+ end.parse!
61
+ rescue OptionParser::InvalidOption
62
+ $stderr.puts 'Invalid option supplied. Enter argonaut -h for help'
63
+ exit(2)
64
+ rescue OptionParser::MissingArgument => ma
65
+ if ["-r", "-R"].include? ma.args.first
66
+ $stderr.puts 'Options -r and -R require <environment>:<app_name>'
67
+ end
68
+ exit(2)
69
+ end
70
+
71
+ require 'ostruct'
72
+
73
+ Argonaut::exec(OpenStruct.new(options))
@@ -0,0 +1,46 @@
1
+ require_relative './gateway'
2
+
3
+ module Argonaut
4
+
5
+ class Cli
6
+ attr_reader :gateway
7
+
8
+ def initialize(gateway:)
9
+ @gateway = gateway
10
+ end
11
+
12
+ def teams
13
+ raw_data = @gateway.fetch(path: 'teams')
14
+ raw_data['data']
15
+ end
16
+
17
+ # Gets all the reservations for the given team
18
+ def reservations(team_name_or_id)
19
+ @gateway.fetch(path: "teams/#{team_name_or_id}/reservations")
20
+ end
21
+
22
+ # Gets list of current user's reservations
23
+ def list_reservations
24
+ @gateway.fetch(path: "list_reservations")
25
+ end
26
+
27
+ def clear_reservations
28
+ @gateway.delete(path: "clear_reservations", data: nil)
29
+ end
30
+
31
+ def reserve!(env_name, app_name)
32
+ data = { application_name: app_name, environment_name: env_name }
33
+ @gateway.post(path: "reservations", data: data)
34
+ end
35
+
36
+ def release!(env_name, app_name)
37
+ data = { application_name: app_name, environment_name: env_name }
38
+ @gateway.delete(path: "reservations", data: data)
39
+ end
40
+
41
+ def find_app(app_name)
42
+ data = { application_name: app_name }
43
+ @gateway.fetch(path: "find_application", data: data)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,10 @@
1
+ module Argonaut
2
+ class Constants
3
+ SETTINGS_FILE = "#{Dir.home}/.argonaut.yml".freeze
4
+ PROJECT_GITHUB_URL = 'https://github.com/qubbit/argonaut-cli'.freeze
5
+ PROJECT_README = "#{PROJECT_GITHUB_URL}/blob/master/README.md".freeze
6
+ NO_CONFIG_ERROR_MESSAGE = 'Could not load settings file ~/.argonaut.yml'.freeze
7
+ NO_URL_ROOT_ERROR_MESSAGE = "URL root for Argonaut is not set. Refer to #{PROJECT_README} for instructions on how to set it up.".freeze
8
+ NO_API_TOKEN_ERROR_MESSAGE = "API token for Argonaut is not set. Refer to #{PROJECT_README} for instructions on how to set it up.".freeze
9
+ end
10
+ end
@@ -0,0 +1,89 @@
1
+ require_relative './constants'
2
+ require 'httparty'
3
+ require 'uri'
4
+
5
+ module Argonaut
6
+ class Gateway
7
+
8
+ attr_reader :api_token
9
+ attr_reader :url_root
10
+
11
+ C = Argonaut::Constants
12
+
13
+ # Initializes the HTTP gateway to connect to argonaut's API endpoint
14
+ # The consumer of this API can supply an API token and
15
+ # URL root directly. If any of these are not set, information
16
+ # obtained from ~/.argonaut.yml is used. If ~/.argonaut.yml is
17
+ # not found or cannot be read, the environment variables are
18
+ # used. If everything fails, an error is printed to notify the user
19
+ def initialize(api_token:, url_root:)
20
+ if api_token.nil? || api_token.empty?
21
+ @api_token = config['api_token']
22
+ else
23
+ @api_token = api_token
24
+ end
25
+
26
+ if url_root.nil? || url_root.empty?
27
+ @url_root = config['url_root']
28
+ else
29
+ @url_root = url_root
30
+ end
31
+
32
+ if @url_root.nil?
33
+ $stderr.puts C::NO_URL_ROOT_ERROR_MESSAGE
34
+ exit(2)
35
+ end
36
+
37
+ if @api_token.nil?
38
+ $stderr.puts C::NO_API_TOKEN_ERROR_MESSAGE
39
+ exit(2)
40
+ end
41
+ end
42
+
43
+ def config
44
+ return @loaded_config if @loaded_config
45
+
46
+ config_from_file = Argonaut::Gateway.load_config_from_file
47
+ if config_from_file
48
+ @loaded_config = config_from_file
49
+ return @loaded_config
50
+ end
51
+
52
+ @loaded_config = {
53
+ 'api_token' => ENV['ARGONAUT_API_TOKEN'],
54
+ 'url_root' => ENV['ARGONAUT_URL_ROOT']
55
+ }
56
+
57
+ if ENV['ARGONAUT_API_TOKEN'].nil? || ENV['ARGONAUT_URL_ROOT'].nil?
58
+ $stderr.puts C::NO_CONFIG_ERROR_MESSAGE
59
+ exit(2)
60
+ end
61
+ end
62
+
63
+ def url_from_path(path)
64
+ # ruby's URI module is shitty, but this should suffice
65
+ URI.join(@url_root, "/api/readonly/#{path}?token=#{@api_token}").to_s
66
+ end
67
+
68
+ %i{ delete get post }.each do |verb|
69
+ define_method(verb) do |path:, data: nil|
70
+ response = HTTParty.send(verb, url_from_path(path), query: data)
71
+
72
+ if response.ok?
73
+ JSON(response.body)
74
+ else
75
+ puts response.body
76
+ end
77
+ end
78
+ end
79
+
80
+ # I made fetch happen 😬
81
+ alias fetch get
82
+
83
+ def self.load_config_from_file
84
+ YAML.load_file(C::SETTINGS_FILE)
85
+ rescue
86
+ nil
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,29 @@
1
+ require_relative './constants'
2
+
3
+ module Argonaut
4
+ class Settings
5
+ def self.config
6
+ @config ||= read_config
7
+ end
8
+
9
+ class << self
10
+
11
+ def read_config
12
+ deep_symbolize(YAML.load_file(Argonaut::Constants::SETTINGS_FILE))
13
+ rescue Errno::ENOENT
14
+ { options: {
15
+ colorize_rows: true,
16
+ time_format: '%d %b %Y %l:%M %p'
17
+ }
18
+ }
19
+ end
20
+
21
+ def deep_symbolize(obj)
22
+ return obj.inject({}){|memo,(k,v)| memo[k.to_sym] = deep_symbolize(v); memo} if obj.is_a? Hash
23
+ return obj.inject([]){|memo,v| memo << deep_symbolize(v); memo} if obj.is_a? Array
24
+ return obj
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Argonaut
2
+ VERSION = "0.1.7"
3
+ end
data/lib/argonaut.rb ADDED
@@ -0,0 +1,151 @@
1
+ require_relative './argonaut/gateway'
2
+ require_relative './argonaut/cli'
3
+ require_relative './argonaut/settings'
4
+ require_relative './argonaut/constants'
5
+ require 'date'
6
+ require 'pp'
7
+
8
+ module Argonaut
9
+ def self.exec(options)
10
+ puts "Executing argonaut command with options:\n#{options}" if options.verbose
11
+ gateway = Argonaut::Gateway.new(api_token: nil, url_root: nil)
12
+ interface = Argonaut::Cli.new(gateway: gateway)
13
+
14
+ @options = options
15
+
16
+ case options.action
17
+ when 'find_app'
18
+ puts interface.find_app(options.application)
19
+ when 'release'
20
+ env, app = parse_env_app(options.env_app)
21
+ puts interface.release!(env, app)
22
+ when 'reserve'
23
+ env, app = parse_env_app(options.env_app)
24
+ puts interface.reserve!(env, app)
25
+ when 'show_teams'
26
+ all_teams = interface.teams
27
+ print_teams(all_teams)
28
+ when 'show_status'
29
+ status = interface.reservations(options.team)
30
+ print_status(status)
31
+ when 'clear_reservations'
32
+ puts interface.clear_reservations
33
+ when 'list_reservations'
34
+ data = interface.list_reservations.fetch('data', nil)
35
+ print_reservations_list(data)
36
+ end
37
+ end
38
+
39
+ private_class_method
40
+
41
+ require 'terminal-table'
42
+
43
+ def self.format_date_time(json_time)
44
+ Time.parse(json_time).getlocal.strftime(@options.time_format || '%d %b %Y %l:%M %p')
45
+ end
46
+
47
+ def self.print_teams(teams_hash)
48
+ rows = []
49
+ rows << ['Id', 'Name', 'Description']
50
+ table = Terminal::Table.new :rows => rows
51
+ table << :separator
52
+
53
+ teams_hash.each do |t|
54
+ table.add_row [ t['id'], t['name'], t['description'] ]
55
+ end
56
+
57
+ puts table
58
+ end
59
+
60
+ def self.print_reservations_list(data)
61
+ if data.empty?
62
+ puts 'You have not reserved any environments for testing 😏'
63
+ return
64
+ end
65
+
66
+ rows = []
67
+ rows << [ 'Environment', 'Application', 'Reserved At' ]
68
+ table = Terminal::Table.new :rows => rows
69
+ table << :separator
70
+
71
+ data.each do |r|
72
+ table.add_row [ r['environment'], r['application'], format_date_time(r['reserved_at']) ]
73
+ end
74
+
75
+ puts table
76
+ end
77
+
78
+ def self.print_status(status_hash)
79
+
80
+ unless status_hash
81
+ puts 'Nothing was found here 😟'
82
+ return
83
+ end
84
+
85
+ applications = status_hash.fetch('applications', [])
86
+ environments = status_hash.fetch('environments', [])
87
+ reservations = status_hash.fetch('reservations', [])
88
+
89
+ header = [' '] + environments.map {|e| e['name'] }
90
+ rows = []
91
+ rows << header
92
+
93
+ table = Terminal::Table.new :rows => rows
94
+ table << :separator
95
+
96
+ empty_cells = (1..environments.size).map{|_| " "}
97
+ sentinel = 0
98
+
99
+ applications.each do |a|
100
+ cells = empty_cells.dup
101
+
102
+ reservations_for_app = find_reservations_for_app(reservations, a)
103
+
104
+ if reservations_for_app.empty?
105
+ table.add_row([ a['name'] ] + empty_cells)
106
+ else
107
+ reservations_for_app.each do |r|
108
+ idx = environments.find_index{|e| e['id'] == r['environment']['id'] }
109
+ cells[idx] = r['user']['username']
110
+ end
111
+
112
+ row = if @options.colorize_rows
113
+ colorize_row([ a['name'] ] + cells, sentinel)
114
+ else
115
+ [ a['name'] ] + cells
116
+ end
117
+
118
+ table.add_row(row)
119
+ sentinel += 1
120
+ end
121
+ end
122
+
123
+ puts table
124
+ end
125
+
126
+ def self.colors
127
+ @colors ||= if @options.high_contrast_colors
128
+ # high contrast colors are based on solarized: http://ethanschoonover.com/solarized
129
+ [136, 166, 160, 125, 61, 33, 37, 64]
130
+ else
131
+ [122, 141, 153, 163, 172, 178, 183, 186, 223]
132
+ end
133
+ end
134
+
135
+ def self.color(index)
136
+ colors[index % colors.length]
137
+ end
138
+
139
+ def self.colorize_row(row, index)
140
+ color = color(index)
141
+ row.map{|cell| "\x1b[38;5;#{color}m#{cell}\e[0m"}
142
+ end
143
+
144
+ def self.find_reservations_for_app(reservations, a)
145
+ reservations.select{|r| r['application']['id'] == a['id']}
146
+ end
147
+
148
+ def self.parse_env_app(env_app)
149
+ env_app.split(':')
150
+ end
151
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: argonaut-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.7
5
+ platform: ruby
6
+ authors:
7
+ - Gopal Adhikari
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 3.0.1
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '3.0'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 3.0.1
89
+ - !ruby/object:Gem::Dependency
90
+ name: httparty
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.15.6
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.15.6
103
+ - !ruby/object:Gem::Dependency
104
+ name: terminal-table
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.8'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 1.8.0
113
+ type: :runtime
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '1.8'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 1.8.0
123
+ description: This gem lets users manipulate argonaut using the command line interface
124
+ email:
125
+ - nullgeo@gmail.com
126
+ executables:
127
+ - argonaut
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - ".gitignore"
132
+ - ".rspec"
133
+ - ".travis.yml"
134
+ - CODE_OF_CONDUCT.md
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - argonaut.gemspec
140
+ - bin/console
141
+ - bin/setup
142
+ - exe/argonaut
143
+ - lib/argonaut.rb
144
+ - lib/argonaut/cli.rb
145
+ - lib/argonaut/constants.rb
146
+ - lib/argonaut/gateway.rb
147
+ - lib/argonaut/settings.rb
148
+ - lib/argonaut/version.rb
149
+ homepage: https://github.com/qubbit/argonaut-cli
150
+ licenses:
151
+ - MIT
152
+ metadata:
153
+ allowed_push_host: https://rubygems.org
154
+ post_install_message: "\n⚓️ Please follow instructions at https://github.com/qubbit/argonaut-cli
155
+ to complete the setup.\n "
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.4.5
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Command line tool for Argonaut
175
+ test_files: []