cody 0.9.5 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) 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 +3 -3
  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 +4 -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} +23 -4
  22. data/lib/cody/{logs.rb → cli/logs.rb} +3 -2
  23. data/lib/cody/{sequence.rb → cli/sequence.rb} +3 -3
  24. data/lib/cody/{start.rb → cli/start.rb} +3 -3
  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 +20 -0
  30. data/lib/cody/dsl/project.rb +54 -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 +9 -0
  34. data/lib/cody/list/project.rb +5 -2
  35. data/lib/cody/project.rb +26 -29
  36. data/lib/cody/role.rb +22 -23
  37. data/lib/cody/schedule.rb +39 -40
  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 +1 -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 +66 -70
  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/vendor/aws_data/CHANGELOG.md +0 -7
  55. data/vendor/aws_data/Gemfile +0 -4
  56. data/vendor/aws_data/LICENSE.txt +0 -21
  57. data/vendor/aws_data/README.md +0 -42
  58. data/vendor/aws_data/Rakefile +0 -6
  59. data/vendor/aws_data/aws_data.gemspec +0 -30
  60. data/vendor/aws_data/bin/console +0 -14
  61. data/vendor/aws_data/bin/setup +0 -8
  62. data/vendor/aws_data/lib/aws_data.rb +0 -91
  63. data/vendor/aws_data/lib/aws_data/version.rb +0 -3
  64. data/vendor/aws_data/spec/aws_data_spec.rb +0 -5
  65. data/vendor/aws_data/spec/spec_helper.rb +0 -14
  66. data/vendor/cfn-status/Gemfile +0 -4
  67. data/vendor/cfn-status/LICENSE.txt +0 -21
  68. data/vendor/cfn-status/README.md +0 -56
  69. data/vendor/cfn-status/Rakefile +0 -6
  70. data/vendor/cfn-status/bin/console +0 -14
  71. data/vendor/cfn-status/bin/setup +0 -8
  72. data/vendor/cfn-status/cfn-status.gemspec +0 -30
  73. data/vendor/cfn-status/lib/cfn/aws_service.rb +0 -56
  74. data/vendor/cfn-status/lib/cfn/status.rb +0 -220
  75. data/vendor/cfn-status/lib/cfn/status/version.rb +0 -5
  76. data/vendor/cfn-status/spec/cfn/status_spec.rb +0 -81
  77. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-complete.json +0 -1080
  78. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-in-progress.json +0 -1080
  79. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-update-rollback-complete.json +0 -1086
  80. data/vendor/cfn-status/spec/spec_helper.rb +0 -14
  81. data/vendor/cfn_camelizer/CHANGELOG.md +0 -10
  82. data/vendor/cfn_camelizer/Gemfile +0 -4
  83. data/vendor/cfn_camelizer/LICENSE.txt +0 -21
  84. data/vendor/cfn_camelizer/README.md +0 -40
  85. data/vendor/cfn_camelizer/Rakefile +0 -6
  86. data/vendor/cfn_camelizer/bin/console +0 -14
  87. data/vendor/cfn_camelizer/bin/setup +0 -8
  88. data/vendor/cfn_camelizer/cfn_camelizer.gemspec +0 -32
  89. data/vendor/cfn_camelizer/lib/camelizer.yml +0 -33
  90. data/vendor/cfn_camelizer/lib/cfn_camelizer.rb +0 -92
  91. data/vendor/cfn_camelizer/lib/cfn_camelizer/version.rb +0 -3
  92. data/vendor/cfn_camelizer/spec/cfn_camelizer_spec.rb +0 -79
  93. data/vendor/cfn_camelizer/spec/spec_helper.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6b78eae6c5cdfbaf38cfad9111c3900698d66c9fb43d6ff4f56439d4b22fd5b
4
- data.tar.gz: 249d4c906eb35b9175a8cd77b3f5c68847802f391d2d57e75f3a07b30c6bab51
3
+ metadata.gz: 13988c2d00cdc267da97b361bc2345a39cdb4d9b4919c18c74643f5b545b5e18
4
+ data.tar.gz: 33e6ac92deb5858b85fb85a68657a18dfb9a9a224b76bc8317dce62b3a1efb76
5
5
  SHA512:
6
- metadata.gz: e7ebe2dc3e7c2924cc0b19f7585acfc2c3ae0f622b9fa58cfd8aaba2177ceb45fe090d90602e1a57f81947a30662028605c6845e875f12479108a6e18aa584d4
7
- data.tar.gz: 312bb50599a5881262b9dd848f9ea731bd31f859aa18794440397c91ab8861fa629082babd32de13dfef6d44ba0a542b7b8c262f36b55aedf94122fb276c1521
6
+ metadata.gz: d6d0df76e76c60d4df42165020be8077d17318da0c077a90bbcf1f799b1fe7deed90c819061d610b3e8cba713c276ccca36da47fa5e91650301a271728f867c3
7
+ data.tar.gz: a956e457a24eda488c74127005996d90282179c57d442fea5f87889bbefff2f2d23cd49e33a2d646fdd912b75beb417e2a7d3b0ad1dda7da76c8895d17f3957b
@@ -1,9 +0,0 @@
1
- [submodule "vendor/cfn-status"]
2
- path = vendor/cfn-status
3
- url = https://github.com/tongueroo/cfn-status
4
- [submodule "vendor/cfn_camelizer"]
5
- path = vendor/cfn_camelizer
6
- url = https://github.com/tongueroo/cfn_camelizer
7
- [submodule "vendor/aws_data"]
8
- path = vendor/aws_data
9
- url = https://github.com/tongueroo/aws_data
@@ -3,6 +3,29 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [1.0.1]
7
+ - fix EventsRuleRole Service camelcase
8
+
9
+ ## [1.0.0]
10
+ - Breaking changes: CamelCase for properties instead of underscore. Map straight to the CloudFormation resource to remove mental overhead.
11
+ - See: https://cody.run/docs/upgrading/
12
+ - Use unfrozen gems instead of vendors gems: aws_data, cfn-status, cfn_camelizer.
13
+ - Update templates to use the latest
14
+ - Restructure classes to use CLI namespace
15
+ - Change delete: `--sure` to `--yes` option. `-y` shorthand.
16
+ - Rename CODY_EXTRA env variable
17
+
18
+ ## [0.9.8]
19
+ - add minimal deploy iam policy docs
20
+ - list: add --status filter option
21
+
22
+ ## [0.9.7]
23
+ - #25 cody list: add sort-by option
24
+
25
+ ## [0.9.6]
26
+ - #24 refactor: add dsl base class so `project_name` method is available to all dsl classes
27
+ - cody list: fix for projects with no builds yet
28
+
6
29
  ## [0.9.5]
7
30
  - write info messsage to stderr so we can pipe to jq
8
31
 
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem dependencies in codebuild.gemspec
4
4
  gemspec
5
-
6
- gem "codeclimate-test-reporter", group: :test, require: nil
@@ -28,6 +28,9 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency "aws-sdk-cloudformation"
29
29
  spec.add_dependency "aws-sdk-codebuild"
30
30
  spec.add_dependency "aws-sdk-ssm"
31
+ spec.add_dependency "aws_data"
32
+ spec.add_dependency "cfn-status"
33
+ spec.add_dependency "cfn_camelizer"
31
34
  spec.add_dependency "cli-format"
32
35
  spec.add_dependency "memoist"
33
36
  spec.add_dependency "rainbow"
@@ -35,9 +38,6 @@ Gem::Specification.new do |spec|
35
38
  spec.add_dependency "thor"
36
39
  spec.add_dependency "zeitwerk"
37
40
 
38
- # spec.add_dependency "aws_data" # using vendor/cfn_camelizer for now
39
- # spec.add_dependency "cfn_camelizer" # using vendor/cfn_camelizer for now
40
-
41
41
  spec.add_development_dependency "bundler"
42
42
  spec.add_development_dependency "byebug"
43
43
  spec.add_development_dependency "cli_markdown"
@@ -1,19 +1,15 @@
1
1
  $:.unshift(File.expand_path("../", __FILE__))
2
+ require "aws_data"
3
+ require "cfn_camelizer"
4
+ require "cfn_status"
2
5
  require "cody/version"
6
+ require "memoist"
3
7
  require "rainbow/ext/string"
4
8
  require "yaml"
5
9
 
6
10
  require "cody/autoloader"
7
11
  Cody::Autoloader.setup
8
12
 
9
- gem_root = File.dirname(__dir__)
10
- $:.unshift("#{gem_root}/vendor/aws_data/lib")
11
- require "aws_data"
12
- $:.unshift("#{gem_root}/vendor/cfn_camelizer/lib")
13
- require "cfn_camelizer"
14
- $:.unshift("#{gem_root}/vendor/cfn-status/lib")
15
- require "cfn/status"
16
-
17
13
  module Cody
18
14
  class Error < StandardError; end
19
15
  extend Core
@@ -15,4 +15,4 @@ module Cody
15
15
  @cfn ||= Aws::CloudFormation::Client.new
16
16
  end
17
17
  end
18
- end
18
+ end
@@ -1,5 +1,18 @@
1
1
  module Cody::AwsServices
2
2
  module Helpers
3
+ def find_stack(stack_name)
4
+ return if ENV['TEST']
5
+ resp = cfn.describe_stacks(stack_name: stack_name)
6
+ resp.stacks.first
7
+ rescue Aws::CloudFormation::Errors::ValidationError => e
8
+ # example: Stack with id demo-web does not exist
9
+ if e.message =~ /Stack with/ && e.message =~ /does not exist/
10
+ nil
11
+ else
12
+ raise
13
+ end
14
+ end
15
+
3
16
  def stack_exists?(stack_name)
4
17
  return false if ENV['TEST']
5
18
 
@@ -26,7 +39,7 @@ module Cody::AwsServices
26
39
  end
27
40
 
28
41
  def project_name_convention(name_base)
29
- items = [@project_name, @options[:type], Cody.env_extra]
42
+ items = [@project_name, @options[:type], Cody.extra]
30
43
  items.insert(2, Cody.env) if Cody.settings.dig(:stack_naming, :append_env)
31
44
  items.reject(&:blank?).compact.join("-")
32
45
  end
@@ -44,13 +57,13 @@ module Cody::AwsServices
44
57
  #
45
58
  def inferred_stack_name(project_name)
46
59
  append_stack_name = Cody.settings.dig(:stack_naming, :append_stack_name) || "cody"
47
- items = [project_name, @options[:type], Cody.env_extra, append_stack_name]
60
+ items = [project_name, @options[:type], Cody.extra, append_stack_name]
48
61
  items.insert(3, Cody.env) if Cody.settings.dig(:stack_naming, :append_env)
49
62
  items.reject(&:blank?).reject {|i| i == false}.compact.join("-")
50
63
  end
51
64
 
52
65
  def are_you_sure?(stack_name, action)
53
- if @options[:sure]
66
+ if @options[:yes]
54
67
  sure = 'y'
55
68
  else
56
69
  message = case action
@@ -68,5 +81,9 @@ module Cody::AwsServices
68
81
  exit 0
69
82
  end
70
83
  end
84
+
85
+ def normalize_stack_name(name)
86
+ name.gsub('_','-') # cloudformation stack names dont allow _
87
+ end
71
88
  end
72
89
  end
@@ -27,7 +27,7 @@ module Cody
27
27
 
28
28
  desc "delete", "Delete codebuild project."
29
29
  long_desc Help.text(:delete)
30
- option :sure, desc: "Bypass are you sure prompt"
30
+ option :yes, aliases: %w[y], desc: "Bypass are you sure prompt"
31
31
  common_options.call
32
32
  def delete(project_name=nil)
33
33
  Delete.new(options.merge(project_name: project_name)).run
@@ -62,6 +62,9 @@ module Cody
62
62
  desc "list", "list codebuild project."
63
63
  long_desc Help.text(:list)
64
64
  option :format, desc: "Output formats: #{CliFormat.formats.join(', ')}"
65
+ option :sort_by, desc: "Sort by column: name, status, time"
66
+ option :status, desc: "status filter. IE: SUCCEEDED, FAILED, FAULT, TIMED_OUT, IN_PROGRESS, STOPPED. Both upper and lowercase works."
67
+ option :select, desc: "select filter on the project name. The select option gets converted to an Ruby regexp"
65
68
  def list
66
69
  List.new(options).run
67
70
  end
@@ -83,18 +86,6 @@ module Cody
83
86
  Badge.new(options.merge(project_name: project_name)).run
84
87
  end
85
88
 
86
- desc "completion *PARAMS", "Prints words for auto-completion."
87
- long_desc Help.text(:completion)
88
- def completion(*params)
89
- Completer.new(CLI, *params).run
90
- end
91
-
92
- desc "completion_script", "Generates a script that can be eval to setup auto-completion."
93
- long_desc Help.text(:completion_script)
94
- def completion_script
95
- Completer::Script.generate
96
- end
97
-
98
89
  desc "version", "prints version"
99
90
  def version
100
91
  puts VERSION
@@ -1,4 +1,4 @@
1
- module Cody
1
+ class Cody::CLI
2
2
  class Badge < Base
3
3
  def run
4
4
  resp = codebuild.batch_get_projects(names: [@full_project_name])
@@ -1,7 +1,7 @@
1
1
  # Base only for Stop and Start currently.
2
- module Cody
2
+ class Cody::CLI
3
3
  class Base
4
- include AwsServices
4
+ include Cody::AwsServices
5
5
 
6
6
  def initialize(options)
7
7
  @options = options
@@ -24,5 +24,11 @@ module Cody
24
24
  resp = codebuild.list_builds_for_project(project_name: @full_project_name)
25
25
  resp.ids.first # most recent build_id
26
26
  end
27
+
28
+ def check_build_id!
29
+ return if build_id
30
+ puts "WARN: No builds found for #{@project_name.color(:green)} project"
31
+ exit
32
+ end
27
33
  end
28
- end
34
+ end
@@ -1,11 +1,11 @@
1
- module Cody
1
+ class Cody::CLI
2
2
  class Delete
3
- include AwsServices
3
+ include Cody::AwsServices
4
4
 
5
5
  def initialize(options)
6
6
  @options = options
7
7
  @project_name = options[:project_name] || inferred_project_name
8
- @stack_name = options[:stack_name] || inferred_stack_name(@project_name)
8
+ @stack_name = normalize_stack_name(options[:stack_name] || inferred_stack_name(@project_name))
9
9
  end
10
10
 
11
11
  def run
@@ -0,0 +1,7 @@
1
+ class Cody::CLI
2
+ class Deploy < Base
3
+ def run
4
+ Cody::Stack.new(@options).run
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ class Cody::CLI
2
+ module Help
3
+ class << self
4
+ def text(namespaced_command)
5
+ path = namespaced_command.to_s.gsub(':','/')
6
+ path = File.expand_path("../help/#{path}.md", __FILE__)
7
+ IO.read(path) if File.exist?(path)
8
+ end
9
+ end
10
+ end
11
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,4 +1,4 @@
1
- module Cody
1
+ class Cody::CLI
2
2
  class Init < Sequence
3
3
  # Ugly, this is how I can get the options from to match with this Thor::Group
4
4
  def self.cli_options
@@ -28,7 +28,6 @@ module Cody
28
28
  override_source_paths(custom_template)
29
29
  else # additive: modify on top of default template
30
30
  default_template = File.expand_path("../../template", __FILE__)
31
- puts "default_template: #{default_template}"
32
31
  override_source_paths([custom_template, default_template])
33
32
  end
34
33
  end
@@ -1,8 +1,8 @@
1
1
  require 'cli-format'
2
2
 
3
- module Cody
3
+ class Cody::CLI
4
4
  class List
5
- include AwsServices
5
+ include Cody::AwsServices
6
6
  extend Memoist
7
7
 
8
8
  def initialize(options)
@@ -18,13 +18,28 @@ module Cody
18
18
  presenter = CliFormat::Presenter.new(@options)
19
19
  presenter.header = ["Name", "Status", "Time"]
20
20
  projects.each do |project|
21
- presenter.rows << [project.name, project.build_status, project.end_time]
21
+ row = [project.name, project.build_status, project.end_time]
22
+ presenter.rows << row if show?(project.build_status)
22
23
  end
23
24
  presenter.show
24
25
  end
25
26
 
27
+ def show?(build_status)
28
+ status = @options[:status].upcase if @options[:status]
29
+ if status
30
+ build_status == status
31
+ else
32
+ true
33
+ end
34
+ end
35
+
26
36
  def projects
27
- list_projects.map { |p| Project.new(p) }
37
+ projects = list_projects.map { |p| Cody::List::Project.new(p) }
38
+ if @options[:sort_by]
39
+ projects.sort_by { |p| p.send(@options[:sort_by]) }
40
+ else
41
+ projects # default name
42
+ end
28
43
  end
29
44
  memoize :projects
30
45
 
@@ -40,6 +55,10 @@ module Cody
40
55
  next_token = resp.next_token
41
56
  projects += resp.projects
42
57
  end
58
+ if @options[:select]
59
+ regexp = Regexp.new(@options[:select])
60
+ projects.select! { |p| p =~ regexp }
61
+ end
43
62
  projects
44
63
  end
45
64
  memoize :list_projects
@@ -1,8 +1,9 @@
1
- module Cody
1
+ class Cody::CLI
2
2
  class Logs < Base
3
3
  def run
4
+ check_build_id!
4
5
  run_with_exception_handling do
5
- Tailer.new(@options, build_id).run
6
+ Cody::Tailer.new(@options, build_id).run
6
7
  end
7
8
  end
8
9
  end
@@ -1,16 +1,16 @@
1
1
  require 'fileutils'
2
2
  require 'thor'
3
3
 
4
- module Cody
4
+ class Cody::CLI
5
5
  class Sequence < Thor::Group
6
- include AwsServices
6
+ include Cody::AwsServices
7
7
  include Thor::Actions
8
8
 
9
9
  add_runtime_options! # force, pretend, quiet, skip options
10
10
  # https://github.com/erikhuda/thor/blob/master/lib/thor/actions.rb#L49
11
11
 
12
12
  def self.source_paths
13
- [File.expand_path("../../template", __FILE__)]
13
+ [File.expand_path("../../../template", __FILE__)]
14
14
  end
15
15
 
16
16
  private
@@ -1,6 +1,6 @@
1
- module Cody
1
+ class Cody::CLI
2
2
  class Start
3
- include AwsServices
3
+ include Cody::AwsServices
4
4
 
5
5
  def initialize(options)
6
6
  @options = options
@@ -24,7 +24,7 @@ module Cody
24
24
  end
25
25
 
26
26
  def tail_logs(build_id)
27
- Tailer.new(@options, build_id).run
27
+ Cody::Tailer.new(@options, build_id).run
28
28
  end
29
29
 
30
30
  def environment_variables_override
@@ -1,6 +1,7 @@
1
- module Cody
1
+ class Cody::CLI
2
2
  class Status < Base
3
3
  def run
4
+ check_build_id!
4
5
  run_with_exception_handling do
5
6
  puts "Build id: #{build_id}"
6
7
  resp = codebuild.batch_get_builds(ids: [build_id])
@@ -1,6 +1,7 @@
1
- module Cody
1
+ class Cody::CLI
2
2
  class Stop < Base
3
3
  def run
4
+ check_build_id!
4
5
  run_with_exception_handling do
5
6
  codebuild.stop_build(id: build_id)
6
7
  puts "Build has been stopped: #{build_id}"
@@ -13,6 +13,17 @@ class Thor
13
13
  end
14
14
  end
15
15
 
16
+ # Gets rid of the c_l_i extra commands in the help menu. Seems like thor_classes_in is only used
17
+ # for this purpose. More details: https://gist.github.com/tongueroo/ee92ec28a4d3eed301d88e8ccdd2fe10
18
+ module ThorPrepend
19
+ module Util
20
+ def thor_classes_in(klass)
21
+ klass.name.include?("CLI") ? [] : super
22
+ end
23
+ end
24
+ end
25
+ Thor::Util.singleton_class.prepend(ThorPrepend::Util)
26
+
16
27
  module Cody
17
28
  class Command < Thor
18
29
  class << self
@@ -19,12 +19,12 @@ module Cody
19
19
  end
20
20
  memoize :env
21
21
 
22
- def env_extra
23
- env_extra = ENV['CODY_ENV_EXTRA'] if ENV['CODY_ENV_EXTRA'] # highest precedence
24
- return if env_extra&.empty?
25
- env_extra
22
+ def extra
23
+ extra = ENV['CODY_EXTRA'] if ENV['CODY_EXTRA'] # highest precedence
24
+ return if extra&.empty?
25
+ extra
26
26
  end
27
- memoize :env_extra
27
+ memoize :extra
28
28
 
29
29
  # Overrides AWS_PROFILE based on the Cody.env if set in configs/settings.yml
30
30
  # 2-way binding.