cody 0.9.8 → 1.0.0

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 +8 -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 +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} +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 +9 -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 +1 -1
  34. data/lib/cody/list/project.rb +1 -1
  35. data/lib/cody/project.rb +23 -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 +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 +64 -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/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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f84323d071291727d2b3bdf96dbcb4e2bc1e1059f67bcf55dc0a062fbd326e0
4
- data.tar.gz: e83e848a9b35fff1b555472c0fbcc5ec48f3068f5cae3c33b244b710928d1416
3
+ metadata.gz: affa968f8c18562b877c26f70abbc6c747b7ef3542fbc2c714218e44e017b114
4
+ data.tar.gz: 74d95d28f13744a40c759844f46046e443eb1f0446f330683864eb19357baa65
5
5
  SHA512:
6
- metadata.gz: d2ddb7689115463ee43717d0f647f73e320d17b3a468f9b6ba40d4c806bc8bd8f448e18c66d66d1674b28ca90d6898369523b4b16a3de02f11a2d68256c65768
7
- data.tar.gz: 4c21a9d3ab5019335dd2f11453efcc7e6726815d41d5a0dc68531c07ca2c3e11b7eff174d1c5d93808f9647ab257f137df3078abdc6ce49e5d301f387390c9fd
6
+ metadata.gz: 76c6feeb50683d4d5eea4e4944fd0385f698d91e013f5917be219302dd9aa12fa1b46213dc7695a9390e3c1bd5a2f5b200f4b83eff2b2f285f73d2049833ed55
7
+ data.tar.gz: df3d1926d50125b9f7b21537e973c63e4309f9407c538f78fe9f2e2501f2f3228d3ad8ec8e852241fc0379ee8ba46c200275555e5f45e32475953a9981e083fb
@@ -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,14 @@
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.0]
7
+ * Breaking changes: CamelCase for properties instead of underscore. Map straight to the CloudFormation resource to remove mental overhead.
8
+ * Use unfrozen gems instead of vendors gems: aws_data, cfn-status, cfn_camelizer.
9
+ * Update templates to use the latest
10
+ * Restructure classes to use CLI namespace
11
+ * Change delete: `--sure` to `--yes` option. `-y` shorthand.
12
+ * Rename CODY_EXTRA env variable
13
+
6
14
  ## [0.9.8]
7
15
  - add minimal deploy iam policy docs
8
16
  - list: add --status filter option
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
@@ -64,6 +64,7 @@ module Cody
64
64
  option :format, desc: "Output formats: #{CliFormat.formats.join(', ')}"
65
65
  option :sort_by, desc: "Sort by column: name, status, time"
66
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"
67
68
  def list
68
69
  List.new(options).run
69
70
  end
@@ -85,18 +86,6 @@ module Cody
85
86
  Badge.new(options.merge(project_name: project_name)).run
86
87
  end
87
88
 
88
- desc "completion *PARAMS", "Prints words for auto-completion."
89
- long_desc Help.text(:completion)
90
- def completion(*params)
91
- Completer.new(CLI, *params).run
92
- end
93
-
94
- desc "completion_script", "Generates a script that can be eval to setup auto-completion."
95
- long_desc Help.text(:completion_script)
96
- def completion_script
97
- Completer::Script.generate
98
- end
99
-
100
89
  desc "version", "prints version"
101
90
  def version
102
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)
@@ -34,7 +34,7 @@ module Cody
34
34
  end
35
35
 
36
36
  def projects
37
- projects = list_projects.map { |p| Project.new(p) }
37
+ projects = list_projects.map { |p| Cody::List::Project.new(p) }
38
38
  if @options[:sort_by]
39
39
  projects.sort_by { |p| p.send(@options[:sort_by]) }
40
40
  else
@@ -55,6 +55,10 @@ module Cody
55
55
  next_token = resp.next_token
56
56
  projects += resp.projects
57
57
  end
58
+ if @options[:select]
59
+ regexp = Regexp.new(@options[:select])
60
+ projects.select! { |p| p =~ regexp }
61
+ end
58
62
  projects
59
63
  end
60
64
  memoize :list_projects
@@ -0,0 +1,10 @@
1
+ class Cody::CLI
2
+ class Logs < Base
3
+ def run
4
+ check_build_id!
5
+ run_with_exception_handling do
6
+ Cody::Tailer.new(@options, build_id).run
7
+ end
8
+ end
9
+ end
10
+ 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.
@@ -7,5 +7,14 @@ module Cody::Dsl
7
7
  @full_project_name = options[:full_project_name] # includes -development at the end
8
8
  @properties = default_properties # defaults make project.rb simpler
9
9
  end
10
+
11
+ # In v1.0.0 defaults to not auto-camelize
12
+ def auto_camelize(data)
13
+ if Cody.settings[:auto_camelize]
14
+ CfnCamelizer.transform(data)
15
+ else
16
+ data.deep_stringify_keys!
17
+ end
18
+ end
10
19
  end
11
20
  end
@@ -3,35 +3,40 @@ module Cody::Dsl
3
3
  include Ssm
4
4
 
5
5
  PROPERTIES = %w[
6
- artifacts
7
- badge_enabled
8
- cache
9
- description
10
- encryption_key
11
- environment
12
- logs_config
13
- name
14
- queued_timeout_in_minutes
15
- secondary_artifacts
16
- secondary_sources
17
- service_role
18
- source
19
- tags
20
- timeout_in_minutes
21
- triggers
22
- vpc_config
6
+ Artifacts
7
+ BadgeEnabled
8
+ Cache
9
+ Description
10
+ EncryptionKey
11
+ Environment
12
+ LogsConfig
13
+ Name
14
+ QueuedTimeoutInMinutes
15
+ SecondaryArtifacts
16
+ SecondarySources
17
+ ServiceRole
18
+ Source
19
+ Tags
20
+ TimeoutInMinutes
21
+ Triggers
22
+ VpcConfig
23
23
  ]
24
24
  PROPERTIES.each do |prop|
25
- define_method(prop) do |v|
25
+ define_method(prop.underscore) do |v|
26
26
  @properties[prop.to_sym] = v
27
27
  end
28
28
  end
29
29
 
30
30
  # Convenience wrapper methods
31
31
  def github_url(url)
32
- @properties[:source][:location] = url
32
+ @properties[:Source][:Location] = url
33
33
  end
34
34
 
35
+ def buildspec(file=".cody/buildspec.yaml")
36
+ @properties[:Source][:BuildSpec] = file
37
+ end
38
+ alias_method :build_spec, :buildspec
39
+
35
40
  # So it looks like the auth resource property doesnt really get used.
36
41
  # Instead an account level credential is worked. Refer to:
37
42
  # https://github.com/tongueroo/cody/blob/master/readme/github_oauth.md
@@ -39,47 +44,47 @@ module Cody::Dsl
39
44
  # Keeping this method around in case the CloudFormation method works one day,
40
45
  # or end up figuring out to use it properly.
41
46
  def github_token(token)
42
- @properties[:source][:auth][:resource] = token
47
+ @properties[:Source][:Auth][:Resource] = token
43
48
  end
44
49
 
45
50
  def github_source(options={})
46
51
  source = {
47
- type: "GITHUB",
48
- location: options[:location],
49
- git_clone_depth: 1,
50
- git_submodules_config: { fetch_submodules: true },
51
- build_spec: options[:buildspec] || ".cody/buildspec.yml", # options[:buildspec] accounts for type already
52
- report_build_status: true,
52
+ Type: "GITHUB",
53
+ Location: options[:Location],
54
+ GitCloneDepth: 1,
55
+ GitSubmodulesConfig: { fetch_submodules: true },
56
+ BuildSpec: options[:BuildSpec] || ".cody/buildspec.yml", # options[:Buildspec] accounts for type already
57
+ ReportBuildStatus: true,
53
58
  }
54
59
 
55
- if options[:oauth_token]
56
- source[:auth] = {
57
- type: "OAUTH",
58
- resource: options[:oauth_token],
60
+ if options[:OauthToken]
61
+ source[:Auth] = {
62
+ Type: "OAUTH",
63
+ Resource: options[:OauthToken],
59
64
  }
60
65
  end
61
66
 
62
- @properties[:source] = source
67
+ @properties[:Source] = source
63
68
  end
64
69
 
65
70
  def linux_image(name)
66
- linux_environment(image: name)
71
+ linux_environment(Image: name)
67
72
  end
68
73
 
69
74
  def linux_environment(options={})
70
- image = options[:image] || "aws/codebuild/amazonlinux2-x86_64-standard:2.0"
75
+ image = options[:Image] || "aws/codebuild/amazonlinux2-x86_64-standard:2.0"
71
76
  env = {
72
- compute_type: options[:compute_type] || "BUILD_GENERAL1_SMALL",
73
- image_pull_credentials_type: "CODEBUILD", # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-environment.html#cfn-codebuild-project-environment-imagepullcredentialstype
74
- privileged_mode: true,
75
- image: image,
76
- type: "LINUX_CONTAINER"
77
+ ComputeType: options[:ComputeType] || "BUILD_GENERAL1_SMALL",
78
+ ImagePullCredentialsType: "CODEBUILD", # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-environment.html#cfn-codebuild-project-environment-imagepullcredentialstype
79
+ PrivilegedMode: true,
80
+ Image: image,
81
+ Type: "LINUX_CONTAINER"
77
82
  }
78
83
  # @mapped_env_vars is in memory
79
- env[:environment_variables] = @mapped_env_vars if @mapped_env_vars
84
+ env[:EnvironmentVariables] = @mapped_env_vars if @mapped_env_vars
80
85
  # options has highest precedence
81
- env[:environment_variables] = options[:environment_variables] if options[:environment_variables]
82
- @properties[:environment] = env
86
+ env[:EnvironmentVariables] = options[:EnvironmentVariables] if options[:EnvironmentVariables]
87
+ @properties[:Environment] = env
83
88
  end
84
89
 
85
90
  def environment_variables(vars)
@@ -87,20 +92,20 @@ module Cody::Dsl
87
92
  @mapped_env_vars = vars.map { |k,v|
88
93
  k, v = k.to_s, v.to_s
89
94
  if v =~ /^ssm:/
90
- { type: "PARAMETER_STORE", name: k, value: v.sub('ssm:','') }
95
+ { Type: "PARAMETER_STORE", Name: k, Value: v.sub('ssm:','') }
91
96
  else
92
- { type: "PLAINTEXT", name: k, value: v }
97
+ { Type: "PLAINTEXT", Name: k, Value: v }
93
98
  end
94
99
  }
95
- @properties[:environment] ||= {}
96
- @properties[:environment][:environment_variables] = @mapped_env_vars
100
+ @properties[:Environment] ||= {}
101
+ @properties[:Environment][:EnvironmentVariables] = @mapped_env_vars
97
102
  end
98
103
 
99
104
  def local_cache(enable=true)
100
105
  cache = if enable
101
106
  {
102
- type: "LOCAL",
103
- modes: [
107
+ Type: "LOCAL",
108
+ Modes: [
104
109
  "LOCAL_DOCKER_LAYER_CACHE",
105
110
  "LOCAL_SOURCE_CACHE",
106
111
  "LOCAL_CUSTOM_CACHE"
@@ -109,11 +114,11 @@ module Cody::Dsl
109
114
  else
110
115
  {type: "NO_CACHE"}
111
116
  end
112
- @properties[:cache] = cache
117
+ @properties[:Cache] = cache
113
118
  end
114
119
 
115
120
  def type
116
- @options[:type]
121
+ @options[:type] # should be lowercase
117
122
  end
118
123
  end
119
124
  end