cody 0.9.8 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -9
  3. data/CHANGELOG.md +23 -0
  4. data/Gemfile +0 -2
  5. data/cody.gemspec +4 -4
  6. data/lib/cody.rb +4 -8
  7. data/lib/cody/aws_services.rb +1 -1
  8. data/lib/cody/aws_services/helpers.rb +20 -3
  9. data/lib/cody/cli.rb +2 -13
  10. data/lib/cody/{badge.rb → cli/badge.rb} +1 -1
  11. data/lib/cody/{base.rb → cli/base.rb} +9 -3
  12. data/lib/cody/{delete.rb → cli/delete.rb} +3 -3
  13. data/lib/cody/cli/deploy.rb +7 -0
  14. data/lib/cody/cli/help.rb +11 -0
  15. data/lib/cody/{help → cli/help}/deploy.md +0 -0
  16. data/lib/cody/{help → cli/help}/init.md +0 -0
  17. data/lib/cody/{help → cli/help}/logs.md +0 -0
  18. data/lib/cody/{help → cli/help}/start.md +0 -0
  19. data/lib/cody/{help → cli/help}/stop.md +0 -0
  20. data/lib/cody/{init.rb → cli/init.rb} +1 -2
  21. data/lib/cody/{list.rb → cli/list.rb} +7 -3
  22. data/lib/cody/cli/logs.rb +10 -0
  23. data/lib/cody/{sequence.rb → cli/sequence.rb} +3 -3
  24. data/lib/cody/{start.rb → cli/start.rb} +10 -5
  25. data/lib/cody/{status.rb → cli/status.rb} +2 -1
  26. data/lib/cody/{stop.rb → cli/stop.rb} +2 -1
  27. data/lib/cody/command.rb +11 -0
  28. data/lib/cody/core.rb +5 -5
  29. data/lib/cody/dsl/base.rb +9 -0
  30. data/lib/cody/dsl/project.rb +67 -49
  31. data/lib/cody/dsl/role.rb +11 -11
  32. data/lib/cody/dsl/schedule.rb +8 -8
  33. data/lib/cody/list/no_builds_project.rb +1 -1
  34. data/lib/cody/list/project.rb +1 -1
  35. data/lib/cody/project.rb +22 -23
  36. data/lib/cody/role.rb +20 -20
  37. data/lib/cody/schedule.rb +37 -37
  38. data/lib/cody/stack.rb +16 -71
  39. data/lib/cody/stack/base.rb +104 -0
  40. data/lib/cody/{create.rb → stack/create.rb} +2 -2
  41. data/lib/cody/{update.rb → stack/update.rb} +2 -2
  42. data/lib/cody/tailer.rb +9 -1
  43. data/lib/cody/version.rb +1 -1
  44. data/lib/template/project/buildspec.yml +1 -1
  45. data/lib/template/project/project.rb.tt +5 -19
  46. metadata +69 -75
  47. data/lib/cody/completer.rb +0 -159
  48. data/lib/cody/completer/script.rb +0 -6
  49. data/lib/cody/completer/script.sh +0 -10
  50. data/lib/cody/deploy.rb +0 -40
  51. data/lib/cody/help.rb +0 -9
  52. data/lib/cody/help/completion.md +0 -22
  53. data/lib/cody/help/completion_script.md +0 -3
  54. data/lib/cody/logs.rb +0 -14
  55. data/vendor/aws_data/CHANGELOG.md +0 -7
  56. data/vendor/aws_data/Gemfile +0 -4
  57. data/vendor/aws_data/LICENSE.txt +0 -21
  58. data/vendor/aws_data/README.md +0 -42
  59. data/vendor/aws_data/Rakefile +0 -6
  60. data/vendor/aws_data/aws_data.gemspec +0 -30
  61. data/vendor/aws_data/bin/console +0 -14
  62. data/vendor/aws_data/bin/setup +0 -8
  63. data/vendor/aws_data/lib/aws_data.rb +0 -91
  64. data/vendor/aws_data/lib/aws_data/version.rb +0 -3
  65. data/vendor/aws_data/spec/aws_data_spec.rb +0 -5
  66. data/vendor/aws_data/spec/spec_helper.rb +0 -14
  67. data/vendor/cfn-status/Gemfile +0 -4
  68. data/vendor/cfn-status/LICENSE.txt +0 -21
  69. data/vendor/cfn-status/README.md +0 -56
  70. data/vendor/cfn-status/Rakefile +0 -6
  71. data/vendor/cfn-status/bin/console +0 -14
  72. data/vendor/cfn-status/bin/setup +0 -8
  73. data/vendor/cfn-status/cfn-status.gemspec +0 -30
  74. data/vendor/cfn-status/lib/cfn/aws_service.rb +0 -56
  75. data/vendor/cfn-status/lib/cfn/status.rb +0 -220
  76. data/vendor/cfn-status/lib/cfn/status/version.rb +0 -5
  77. data/vendor/cfn-status/spec/cfn/status_spec.rb +0 -81
  78. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-complete.json +0 -1080
  79. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-in-progress.json +0 -1080
  80. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-update-rollback-complete.json +0 -1086
  81. data/vendor/cfn-status/spec/spec_helper.rb +0 -14
  82. data/vendor/cfn_camelizer/CHANGELOG.md +0 -10
  83. data/vendor/cfn_camelizer/Gemfile +0 -4
  84. data/vendor/cfn_camelizer/LICENSE.txt +0 -21
  85. data/vendor/cfn_camelizer/README.md +0 -40
  86. data/vendor/cfn_camelizer/Rakefile +0 -6
  87. data/vendor/cfn_camelizer/bin/console +0 -14
  88. data/vendor/cfn_camelizer/bin/setup +0 -8
  89. data/vendor/cfn_camelizer/cfn_camelizer.gemspec +0 -32
  90. data/vendor/cfn_camelizer/lib/camelizer.yml +0 -33
  91. data/vendor/cfn_camelizer/lib/cfn_camelizer.rb +0 -92
  92. data/vendor/cfn_camelizer/lib/cfn_camelizer/version.rb +0 -3
  93. data/vendor/cfn_camelizer/spec/cfn_camelizer_spec.rb +0 -79
  94. data/vendor/cfn_camelizer/spec/spec_helper.rb +0 -14
@@ -1,159 +0,0 @@
1
- =begin
2
- Code Explanation:
3
-
4
- There are 3 types of things to auto-complete:
5
-
6
- 1. command: the command itself
7
- 2. parameters: command parameters.
8
- 3. options: command options
9
-
10
- Here's an example:
11
-
12
- mycli hello name --from me
13
-
14
- * command: hello
15
- * parameters: name
16
- * option: --from
17
-
18
- When command parameters are done processing, the remaining completion words will be options. We can tell that the command params are completed based on the method arity.
19
-
20
- ## Arity
21
-
22
- For example, say you had a method for a CLI command with the following form:
23
-
24
- ufo scale service count --cluster development
25
-
26
- It's equivalent ruby method:
27
-
28
- scale(service, count) = has an arity of 2
29
-
30
- So typing:
31
-
32
- ufo scale service count [TAB] # there are 3 parameters including the "scale" command according to Thor's CLI processing.
33
-
34
- So the completion should only show options, something like this:
35
-
36
- --noop --verbose --cluster
37
-
38
- ## Splat Arguments
39
-
40
- When the ruby method has a splat argument, it's arity is negative. Here are some example methods and their arities.
41
-
42
- ship(service) = 1
43
- scale(service, count) = 2
44
- ships(*services) = -1
45
- foo(example, *rest) = -2
46
-
47
- Fortunately, negative and positive arity values are processed the same way. So we take simply take the absolute value of the arity and process it the same.
48
-
49
- Here are some test cases, hit TAB after typing the command:
50
-
51
- cody completion
52
- cody completion hello
53
- cody completion hello name
54
- cody completion hello name --
55
- cody completion hello name --noop
56
-
57
- cody completion
58
- cody completion sub:goodbye
59
- cody completion sub:goodbye name
60
-
61
- ## Subcommands and Thor::Group Registered Commands
62
-
63
- Sometimes the commands are not simple thor commands but are subcommands or Thor::Group commands. A good specific example is the ufo tool.
64
-
65
- * regular command: ufo ship
66
- * subcommand: ufo docker
67
- * Thor::Group command: ufo init
68
-
69
- Auto-completion accounts for each of these type of commands.
70
- =end
71
- module Cody
72
- class Completer
73
- def initialize(command_class, *params)
74
- @params = params
75
- @current_command = @params[0]
76
- @command_class = command_class # CLI initiall
77
- end
78
-
79
- def run
80
- if subcommand?(@current_command)
81
- subcommand_class = @command_class.subcommand_classes[@current_command]
82
- @params.shift # destructive
83
- Completer.new(subcommand_class, *@params).run # recursively use subcommand
84
- return
85
- end
86
-
87
- # full command has been found!
88
- unless found?(@current_command)
89
- puts all_commands
90
- return
91
- end
92
-
93
- # will only get to here if command aws found (above)
94
- arity = @command_class.instance_method(@current_command).arity.abs
95
- if @params.size > arity or thor_group_command?
96
- puts options_completion
97
- else
98
- puts params_completion
99
- end
100
- end
101
-
102
- def subcommand?(command)
103
- @command_class.subcommands.include?(command)
104
- end
105
-
106
- # hacky way to detect that command is a registered Thor::Group command
107
- def thor_group_command?
108
- command_params(raw=true) == [[:rest, :args]]
109
- end
110
-
111
- def found?(command)
112
- public_methods = @command_class.public_instance_methods(false)
113
- command && public_methods.include?(command.to_sym)
114
- end
115
-
116
- # all top-level commands
117
- def all_commands
118
- commands = @command_class.all_commands.reject do |k,v|
119
- v.is_a?(Thor::HiddenCommand)
120
- end
121
- commands.keys
122
- end
123
-
124
- def command_params(raw=false)
125
- params = @command_class.instance_method(@current_command).parameters
126
- # Example:
127
- # >> Sub.instance_method(:goodbye).parameters
128
- # => [[:req, :name]]
129
- # >>
130
- raw ? params : params.map!(&:last)
131
- end
132
-
133
- def params_completion
134
- offset = @params.size - 1
135
- offset_params = command_params[offset..-1]
136
- command_params[offset..-1].first
137
- end
138
-
139
- def options_completion
140
- used = ARGV.select { |a| a.include?('--') } # so we can remove used options
141
-
142
- method_options = @command_class.all_commands[@current_command].options.keys
143
- class_options = @command_class.class_options.keys
144
-
145
- all_options = method_options + class_options + ['help']
146
-
147
- all_options.map! { |o| "--#{o.to_s.gsub('_','-')}" }
148
- filtered_options = all_options - used
149
- filtered_options.uniq
150
- end
151
-
152
- # Useful for debugging. Using puts messes up completion.
153
- def log(msg)
154
- File.open("/tmp/complete.log", "a") do |file|
155
- file.puts(msg)
156
- end
157
- end
158
- end
159
- end
@@ -1,6 +0,0 @@
1
- class Cody::Completer::Script
2
- def self.generate
3
- bash_script = File.expand_path("script.sh", File.dirname(__FILE__))
4
- puts "source #{bash_script}"
5
- end
6
- end
@@ -1,10 +0,0 @@
1
- _cody() {
2
- COMPREPLY=()
3
- local word="${COMP_WORDS[COMP_CWORD]}"
4
- local words=("${COMP_WORDS[@]}")
5
- unset words[0]
6
- local completion=$(cody completion ${words[@]})
7
- COMPREPLY=( $(compgen -W "$completion" -- "$word") )
8
- }
9
-
10
- complete -F _cody cody
@@ -1,40 +0,0 @@
1
- module Cody
2
- class Deploy < Stack
3
- def run
4
- handle_rollback_completed!
5
- if stack_exists?(@stack_name)
6
- Update.new(@options).run
7
- else
8
- Create.new(@options).run
9
- end
10
- end
11
-
12
- def handle_rollback_completed!
13
- @stack = find_stack(@stack_name)
14
- if @stack && rollback_complete?(@stack)
15
- puts "Existing stack in ROLLBACK_COMPLETE state. Deleting stack before continuing."
16
- cfn.delete_stack(stack_name: @stack_name)
17
- status.wait
18
- status.reset
19
- @stack = nil # at this point stack has been deleted
20
- end
21
- end
22
-
23
- def rollback_complete?(stack)
24
- stack.stack_status == 'ROLLBACK_COMPLETE'
25
- end
26
-
27
- def find_stack(stack_name)
28
- return if ENV['TEST']
29
- resp = cfn.describe_stacks(stack_name: stack_name)
30
- resp.stacks.first
31
- rescue Aws::CloudFormation::Errors::ValidationError => e
32
- # example: Stack with id demo-web does not exist
33
- if e.message =~ /Stack with/ && e.message =~ /does not exist/
34
- nil
35
- else
36
- raise
37
- end
38
- end
39
- end
40
- end
@@ -1,9 +0,0 @@
1
- module Cody::Help
2
- class << self
3
- def text(namespaced_command)
4
- path = namespaced_command.to_s.gsub(':','/')
5
- path = File.expand_path("../help/#{path}.md", __FILE__)
6
- IO.read(path) if File.exist?(path)
7
- end
8
- end
9
- end
@@ -1,22 +0,0 @@
1
- Example:
2
-
3
- cody completion
4
-
5
- Prints words for TAB auto-completion.
6
-
7
- Examples:
8
-
9
- cody completion
10
- cody completion hello
11
- cody completion hello name
12
-
13
- To enable, TAB auto-completion add the following to your profile:
14
-
15
- eval $(cody completion_script)
16
-
17
- Auto-completion example usage:
18
-
19
- cody [TAB]
20
- cody hello [TAB]
21
- cody hello name [TAB]
22
- cody hello name --[TAB]
@@ -1,3 +0,0 @@
1
- To use, add the following to your `~/.bashrc` or `~/.profile`
2
-
3
- eval $(cody completion_script)
@@ -1,14 +0,0 @@
1
- module Cody
2
- class Logs < Base
3
- def run
4
- unless build_id
5
- puts "WARN: No builds found for #{@project_name.color(:green)} project"
6
- return
7
- end
8
-
9
- run_with_exception_handling do
10
- Tailer.new(@options, build_id).run
11
- end
12
- end
13
- end
14
- end
@@ -1,7 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).
5
-
6
- ## [0.1.0]
7
- - Initial release
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in aws_data.gemspec
4
- gemspec
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2019 Tung Nguyen
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.
@@ -1,42 +0,0 @@
1
- # AwsData
2
-
3
- Simple AWS data library helper. Info like region and account id.
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'aws_data'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install aws_data
20
-
21
- ## Usage
22
-
23
- ```ruby
24
- require "aws_data"
25
- aws = AwsData.new
26
- aws.account # account id
27
- aws.region # region
28
- ```
29
-
30
- ## Development
31
-
32
- 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.
33
-
34
- 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).
35
-
36
- ## Contributing
37
-
38
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/aws_data.
39
-
40
- ## License
41
-
42
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -1,30 +0,0 @@
1
- lib = File.expand_path("../lib", __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "aws_data/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "aws_data"
7
- spec.version = AwsData::VERSION
8
- spec.authors = ["Tung Nguyen"]
9
- spec.email = ["tongueroo@gmail.com"]
10
-
11
- spec.summary = "AWS info like region and account id"
12
- spec.homepage = "https://github.com/tongueroo/aws_data"
13
- spec.license = "MIT"
14
-
15
- # Specify which files should be added to the gem when it is released.
16
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
- end
20
- spec.bindir = "exe"
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
23
-
24
- spec.add_dependency "memoist"
25
- spec.add_dependency "aws-sdk-core" # contains sts service
26
-
27
- spec.add_development_dependency "bundler", "~> 2.0"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
- spec.add_development_dependency "rspec", "~> 3.0"
30
- end
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "aws_data"
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
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
@@ -1,8 +0,0 @@
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
@@ -1,91 +0,0 @@
1
- require "aws_data/version"
2
- require "aws-sdk-core"
3
- require "aws-sdk-sts"
4
- require "memoist"
5
-
6
- class AwsData
7
- class Error < StandardError; end
8
- extend Memoist
9
-
10
- def region
11
- return 'us-east-1' if test?
12
-
13
- return ENV['AWS_REGION'] if ENV['AWS_REGION'] # highest precedence
14
-
15
- region = nil
16
-
17
- # First if aws binary is available
18
- # try to get it from the ~/.aws/config
19
- if which('aws')
20
- region = `aws configure get region 2>&1`.strip rescue nil
21
- exit_code = $?.exitstatus
22
- if exit_code != 0
23
- exception_message = region.split("\n").grep(/botocore\.exceptions/).first
24
- if exception_message
25
- puts "WARN: #{exception_message}".color(:yellow)
26
- else
27
- # show full message as warning
28
- puts region.color(:yellow)
29
- end
30
- puts "You can also get rid of this message by setting AWS_REGION or configuring ~/.aws/config with the region"
31
- region = nil
32
- end
33
- region = nil if region == ''
34
- return region if region
35
- end
36
-
37
- # Second try the metadata endpoint, should be available on AWS Lambda environment
38
- # https://stackoverflow.com/questions/4249488/find-region-from-within-an-ec2-instance
39
- begin
40
- az = `curl -s --max-time 3 --connect-timeout 5 http://169.254.169.254/latest/meta-data/placement/availability-zone`
41
- region = az.strip.chop # remove last char
42
- region = nil if region == ''
43
- rescue
44
- end
45
- return region if region
46
-
47
- 'us-east-1' # default if all else fails
48
- end
49
- memoize :region
50
-
51
- # aws sts get-caller-identity
52
- def account
53
- return '123456789' if test?
54
- return ENV['AWS_ACCOUNT'] if ENV['AWS_ACCOUNT']
55
-
56
- # ensure region set, required for sts.get_caller_identity.account to work
57
- ENV['AWS_REGION'] ||= region
58
- begin
59
- sts.get_caller_identity.account
60
- rescue Aws::Errors::MissingCredentialsError
61
- puts "INFO: You're missing AWS credentials. Only local services are currently available"
62
- end
63
- end
64
- memoize :account
65
-
66
- private
67
- def test?
68
- ENV['TEST']
69
- end
70
-
71
- # Cross-platform way of finding an executable in the $PATH.
72
- #
73
- # which('ruby') #=> /usr/bin/ruby
74
- #
75
- # source: https://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
76
- def which(cmd)
77
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
78
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
79
- exts.each { |ext|
80
- exe = File.join(path, "#{cmd}#{ext}")
81
- return exe if File.executable?(exe) && !File.directory?(exe)
82
- }
83
- end
84
- return nil
85
- end
86
-
87
- def sts
88
- Aws::STS::Client.new
89
- end
90
- memoize :sts
91
- end