cody 1.0.6 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8381cda42f017707307d5de7118130640258798382938df63bdb4a028bfe43a
4
- data.tar.gz: 4543b413ef1ecf727aa2b0151b62fed6b7928b946d142d1cbc1ed1897c53ed4f
3
+ metadata.gz: fd70b6f28e07b8c790325ac4a3c0e7703f60c91bf787d757e2827a61b2eaed48
4
+ data.tar.gz: 353f4fe4eec6dc7b4e0d473f29cc9389a6e907ecfef2a3552b8e4b960873784f
5
5
  SHA512:
6
- metadata.gz: 1dc6cb7f35e4d21ae53c93746a22ed5df183dd06555939d4bec59f9b855197e67d2acbfc984b83a544c6dc9e79708709fb5c62005a654fffa0ea8108f25ffb3e
7
- data.tar.gz: 45f3a91f478796108ed53fa7eba76f0743432c61872745d829a4d48c0b9ddbab7a733b98cd6e06db68a635aeaa7622b198226d85f1feddbca40a6e2a416b5247
6
+ metadata.gz: 1d17eed03ad6069022ca100899bb10739acf31804a7743beed5deb2e9ed17c9dac3967a8e6ae51c6dd268c586e7d86f9f5db21de8763cefe7be1c883da8765bd
7
+ data.tar.gz: 91dfd9d4df7923fb6cb26081a53ec5eb8b6c8d1eda2dddb9882095cab80f9bc253aef38dd694e3ddc1b14eebc824b42885a4f4763a5c8c1da34076ba5d719718
data/CHANGELOG.md CHANGED
@@ -3,6 +3,11 @@
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.1.0] - 2022-03-03
7
+ - [#33](https://github.com/tongueroo/cody/pull/33) fix cfn status when auto deleting rollback completed stack
8
+ - [#34](https://github.com/tongueroo/cody/pull/34) iam roles: support multiple calls
9
+ - update iam role docs
10
+
6
11
  ## [1.0.6] - 2021-12-17
7
12
  - [#32](https://github.com/tongueroo/cody/pull/32) fix activesupport require
8
13
  - fix warn not found ssm param message
data/cody.gemspec CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_dependency "cfn-status"
33
33
  spec.add_dependency "cfn_camelizer"
34
34
  spec.add_dependency "cli-format"
35
+ spec.add_dependency "dsl_evaluator"
35
36
  spec.add_dependency "memoist"
36
37
  spec.add_dependency "rainbow"
37
38
  spec.add_dependency "render_me_pretty"
data/lib/cody/cli.rb CHANGED
@@ -37,7 +37,7 @@ module Cody
37
37
  long_desc Help.text(:start)
38
38
  option :source_version, default: "master", desc: "git branch"
39
39
  option :branch, aliases: "b", default: "master", desc: "git branch"
40
- option :env_vars, type: :array, desc: "env var overrides. IE: KEY1=VALUE1 KEY2=VALUE2"
40
+ option :env_vars, aliases: "e", type: :array, desc: "env var overrides. IE: KEY1=VALUE1 KEY2=VALUE2"
41
41
  common_options.call
42
42
  def start(project_name=nil)
43
43
  Start.new(options.merge(project_name: project_name)).run
data/lib/cody/dsl/base.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  module Cody::Dsl
2
2
  class Base
3
- attr_reader :project_name, :full_project_name
3
+ attr_reader :options, :project_name, :full_project_name, :type
4
4
  def initialize(options={})
5
5
  @options = options
6
6
  @project_name = options[:project_name]
7
+ @type = options[:type]
7
8
  @full_project_name = options[:full_project_name] # includes -development at the end
8
9
  @properties = default_properties # defaults make project.rb simpler
9
10
  end
@@ -0,0 +1,25 @@
1
+ require "set"
2
+
3
+ module Cody::Dsl::Role
4
+ class Registry
5
+ class_attribute :iam_statements
6
+ self.iam_statements = nil # nil to allow fallback to default_iam_statements in cody/role.rb
7
+ class_attribute :managed_policy_arns
8
+ self.managed_policy_arns = nil # nil to allow fallback to default_managed_policy_arns in cody/role.rb
9
+
10
+ class << self
11
+ def register_policy(*statements)
12
+ statements.flatten!
13
+ self.iam_statements ||= []
14
+ self.iam_statements += statements # using set so DSL can safely be evaluated multiple times
15
+ end
16
+
17
+ def register_managed_policy(*policies)
18
+ policies.flatten!
19
+ self.managed_policy_arns ||= []
20
+ self.managed_policy_arns += policies # using set so DSL can safely be evaluated multiple times
21
+ self.managed_policy_arns.uniq!
22
+ end
23
+ end
24
+ end
25
+ end
data/lib/cody/dsl/role.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Cody::Dsl
2
2
  module Role
3
+ extend Memoist
4
+
3
5
  PROPERTIES = %w[
4
6
  AssumeRolePolicyDocument
5
7
  ManagedPolicyArns
@@ -17,7 +19,13 @@ module Cody::Dsl
17
19
 
18
20
  # convenience wrapper methods
19
21
  def iam_policy(*definitions)
20
- @iam_statements = definitions.map { |definition| standardize_iam_policy(definition) }
22
+ statements = definitions.map { |definition| standardize_iam_policy(definition) }
23
+ Registry.register_policy(statements)
24
+ end
25
+
26
+ def managed_iam_policy(*definitions)
27
+ managed_policy_arns = definitions.map { |definition| standardize_managed_iam_policy(definition) }
28
+ Registry.register_managed_policy(managed_policy_arns)
21
29
  end
22
30
 
23
31
  # Returns standarized IAM statement
@@ -36,15 +44,15 @@ module Cody::Dsl
36
44
  end
37
45
  end
38
46
 
39
- def managed_iam_policy(*definitions)
40
- @managed_policy_arns = definitions.map { |definition| standardize_managed_iam_policy(definition) }
41
- end
42
-
43
47
  # AmazonEC2ReadOnlyAccess => arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess
44
48
  def standardize_managed_iam_policy(definition)
45
49
  return definition if definition.include?('iam::aws:policy')
46
-
47
50
  "arn:aws:iam::aws:policy/#{definition}"
48
51
  end
52
+
53
+ def aws
54
+ AwsData.new
55
+ end
56
+ memoize :aws
49
57
  end
50
58
  end
data/lib/cody/evaluate.rb CHANGED
@@ -1,47 +1,8 @@
1
1
  module Cody
2
2
  module Evaluate
3
+ include DslEvaluator
3
4
  include Interface
4
5
 
5
- def evaluate(path)
6
- source_code = IO.read(path)
7
- begin
8
- instance_eval(source_code, path)
9
- rescue Exception => e
10
- if e.class == SystemExit # allow exit to happen normally
11
- raise
12
- else
13
- task_definition_error(e)
14
- puts "\nFull error:"
15
- raise
16
- end
17
- end
18
- end
19
-
20
- private
21
- # Prints out a user friendly task_definition error message
22
- def task_definition_error(e)
23
- error_info = e.backtrace.first
24
- path, line_no, _ = error_info.split(':')
25
- line_no = line_no.to_i
26
- puts "Error evaluating #{path}:".color(:red)
27
- puts e.message
28
- puts "Here's the line in #{path} with the error:\n\n"
29
-
30
- contents = IO.read(path)
31
- content_lines = contents.split("\n")
32
- context = 5 # lines of context
33
- top, bottom = [line_no-context-1, 0].max, line_no+context-1
34
- spacing = content_lines.size.to_s.size
35
- content_lines[top..bottom].each_with_index do |line_content, index|
36
- line_number = top+index+1
37
- if line_number == line_no
38
- printf("%#{spacing}d %s\n".color(:red), line_number, line_content)
39
- else
40
- printf("%#{spacing}d %s\n", line_number, line_content)
41
- end
42
- end
43
- end
44
-
45
6
  def lookup_cody_file(name)
46
7
  [".cody", @options[:type], name].compact.join("/")
47
8
  end
data/lib/cody/project.rb CHANGED
@@ -18,7 +18,7 @@ module Cody
18
18
 
19
19
  def run
20
20
  load_variables
21
- evaluate(@project_path)
21
+ evaluate_file(@project_path)
22
22
  resource = {
23
23
  CodeBuild: {
24
24
  Type: "AWS::CodeBuild::Project",
data/lib/cody/role.rb CHANGED
@@ -2,9 +2,9 @@ require "yaml"
2
2
 
3
3
  module Cody
4
4
  class Role < Dsl::Base
5
- include Cody::Dsl::Role
6
5
  include Evaluate
7
6
  include Variables
7
+ include Dsl::Role
8
8
 
9
9
  def initialize(options={})
10
10
  super
@@ -14,7 +14,8 @@ module Cody
14
14
 
15
15
  def run
16
16
  load_variables
17
- evaluate(@role_path) if File.exist?(@role_path)
17
+ evaluate_file(@role_path) if File.exist?(@role_path) # registers definitions to registry
18
+ build # build definitions from registry. can set: @iam_statements and @managed_policy_arns
18
19
  @properties[:Policies] = [{
19
20
  PolicyName: "CodeBuildAccess",
20
21
  PolicyDocument: {
@@ -35,6 +36,12 @@ module Cody
35
36
  end
36
37
 
37
38
  private
39
+ Registry = Cody::Dsl::Role::Registry
40
+ def build
41
+ @iam_statements = Registry.iam_statements if Registry.iam_statements
42
+ @managed_policy_arns = Registry.managed_policy_arns if Registry.managed_policy_arns
43
+ end
44
+
38
45
  def get_role_path
39
46
  lookup_cody_file("role.rb")
40
47
  end
data/lib/cody/schedule.rb CHANGED
@@ -15,7 +15,7 @@ module Cody
15
15
 
16
16
  old_properties = @properties.clone
17
17
  load_variables
18
- evaluate(@schedule_path)
18
+ evaluate_file(@schedule_path)
19
19
 
20
20
  @properties[:ScheduleExpression] = @schedule_expression if @schedule_expression
21
21
  set_rule_event! if @rule_event_props
@@ -1,6 +1,7 @@
1
1
  class Cody::Stack
2
2
  class Base
3
3
  include Cody::AwsServices
4
+ include Status
4
5
 
5
6
  def initialize(options)
6
7
  @options = options
@@ -40,6 +41,7 @@ class Cody::Stack
40
41
  FileUtils.mkdir_p(File.dirname(template_path))
41
42
  IO.write(template_path, YAML.dump(@template))
42
43
  puts "Generated CloudFormation template at #{template_path.color(:green)}"
44
+
43
45
  return if @options[:noop]
44
46
  puts "Deploying stack #{@stack_name.color(:green)} with CodeBuild project #{@full_project_name.color(:green)}"
45
47
 
@@ -68,10 +70,6 @@ class Cody::Stack
68
70
  puts "Here's the CloudFormation url to check for more details #{url}"
69
71
  end
70
72
 
71
- def status
72
- @status ||= CfnStatus.new(@stack_name)
73
- end
74
-
75
73
  def rollback_complete?(stack)
76
74
  stack.stack_status == 'ROLLBACK_COMPLETE'
77
75
  end
@@ -0,0 +1,7 @@
1
+ class Cody::Stack
2
+ module Status
3
+ def status
4
+ @status ||= CfnStatus.new(@stack_name)
5
+ end
6
+ end
7
+ end
data/lib/cody/stack.rb CHANGED
@@ -3,6 +3,7 @@ require "aws-sdk-cloudformation"
3
3
  module Cody
4
4
  class Stack
5
5
  include Cody::AwsServices
6
+ include Status
6
7
 
7
8
  def initialize(options)
8
9
  @options = options
data/lib/cody/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cody
2
- VERSION = "1.0.6"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/cody.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  $:.unshift(File.expand_path("../", __FILE__))
2
- require 'active_support'
3
- require 'active_support/core_ext/string'
2
+ require "active_support"
3
+ require "active_support/core_ext/string"
4
4
  require "aws_data"
5
5
  require "cfn_camelizer"
6
6
  require "cfn_status"
7
7
  require "cody/version"
8
+ require "dsl_evaluator"
8
9
  require "memoist"
9
10
  require "rainbow/ext/string"
10
11
  require "yaml"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cody
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-17 00:00:00.000000000 Z
11
+ date: 2022-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: dsl_evaluator
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: memoist
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -357,6 +371,7 @@ files:
357
371
  - lib/cody/dsl/project.rb
358
372
  - lib/cody/dsl/project/ssm.rb
359
373
  - lib/cody/dsl/role.rb
374
+ - lib/cody/dsl/role/registry.rb
360
375
  - lib/cody/dsl/schedule.rb
361
376
  - lib/cody/evaluate.rb
362
377
  - lib/cody/evaluate/interface.rb
@@ -369,6 +384,7 @@ files:
369
384
  - lib/cody/stack.rb
370
385
  - lib/cody/stack/base.rb
371
386
  - lib/cody/stack/create.rb
387
+ - lib/cody/stack/status.rb
372
388
  - lib/cody/stack/update.rb
373
389
  - lib/cody/tailer.rb
374
390
  - lib/cody/variables.rb