cody 0.9.5 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,20 @@
1
+ module Cody::Dsl
2
+ class Base
3
+ attr_reader :project_name, :full_project_name
4
+ def initialize(options={})
5
+ @options = options
6
+ @project_name = options[:project_name]
7
+ @full_project_name = options[:full_project_name] # includes -development at the end
8
+ @properties = default_properties # defaults make project.rb simpler
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
19
+ end
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
@@ -1,16 +1,16 @@
1
1
  module Cody::Dsl
2
2
  module Role
3
3
  PROPERTIES = %w[
4
- assume_role_policy_document
5
- managed_policy_arns
6
- max_session_duration
7
- path
8
- permissions_boundary
9
- policies
10
- role_name
4
+ AssumeRolePolicyDocument
5
+ ManagedPolicyArns
6
+ MaxSessionDuration
7
+ Path
8
+ PermissionsBoundary
9
+ Policies
10
+ RoleName
11
11
  ]
12
12
  PROPERTIES.each do |prop|
13
- define_method(prop) do |v|
13
+ define_method(prop.underscore) do |v|
14
14
  @properties[prop.to_sym] = v
15
15
  end
16
16
  end
@@ -27,9 +27,9 @@ module Cody::Dsl
27
27
  # Expands simple string from: logs => logs:*
28
28
  definition = "#{definition}:*" unless definition.include?(':')
29
29
  {
30
- action: [definition],
31
- effect: "Allow",
32
- resource: "*",
30
+ Action: [definition],
31
+ Effect: "Allow",
32
+ Resource: "*",
33
33
  }
34
34
  when Hash
35
35
  definition
@@ -1,16 +1,16 @@
1
1
  module Cody::Dsl
2
2
  module Schedule
3
3
  PROPERTIES = %w[
4
- description
5
- event_pattern
6
- name
7
- role_arn
8
- schedule_expression
9
- state
10
- targets
4
+ Description
5
+ EventPattern
6
+ Name
7
+ RoleArn
8
+ ScheduleExpression
9
+ State
10
+ Targets
11
11
  ]
12
12
  PROPERTIES.each do |prop|
13
- define_method(prop) do |v|
13
+ define_method(prop.underscore) do |v|
14
14
  @properties[prop.to_sym] = v
15
15
  end
16
16
  end
@@ -0,0 +1,9 @@
1
+ # Represents a project with no builds yet. In this case we just return an info message for the columns.
2
+ # This allows `cody list` to work without breaking for Fresh projects with zero builds.
3
+ module Cody::List
4
+ class NoBuildsProject
5
+ def method_missing(meth, *args, &block)
6
+ "no builds"
7
+ end
8
+ end
9
+ end
@@ -1,10 +1,12 @@
1
1
  # Wrap project in object to allow lazy loading of status
2
- class Cody::List
2
+ module Cody::List
3
3
  class Project
4
4
  include Cody::AwsServices
5
5
  extend Memoist
6
6
 
7
7
  delegate :build_status, :start_time, :end_time, to: :build
8
+ alias_method :time, :end_time
9
+ alias_method :status, :build_status
8
10
 
9
11
  attr_reader :name
10
12
  def initialize(name)
@@ -12,8 +14,9 @@ class Cody::List
12
14
  end
13
15
 
14
16
  def build
17
+ return NoBuildsProject.new unless build_id # most recent build
15
18
  resp = codebuild.batch_get_builds(ids: [build_id])
16
- resp.builds.first # most recent build
19
+ resp.builds.first
17
20
  end
18
21
  memoize :build
19
22
  alias_method :load, :build # interface to eager load
@@ -1,18 +1,15 @@
1
1
  require "yaml"
2
2
 
3
3
  module Cody
4
- class Project
4
+ class Project < Dsl::Base
5
5
  include Dsl::Project
6
6
  include Evaluate
7
7
  include Variables
8
8
 
9
- attr_reader :project_name, :full_project_name, :project_path
9
+ attr_reader :project_path
10
10
  def initialize(options={})
11
- @options = options
12
- @project_name = options[:project_name]
13
- @full_project_name = options[:full_project_name] # includes -development at the end
11
+ super
14
12
  @project_path = options[:project_path] || get_project_path
15
- @properties = default_properties # defaults make project.rb simpler
16
13
  end
17
14
 
18
15
  def exist?
@@ -23,40 +20,40 @@ module Cody
23
20
  load_variables
24
21
  evaluate(@project_path)
25
22
  resource = {
26
- code_build: {
27
- type: "AWS::CodeBuild::Project",
28
- properties: @properties
23
+ CodeBuild: {
24
+ Type: "AWS::CodeBuild::Project",
25
+ Properties: @properties
29
26
  }
30
27
  }
31
- CfnCamelizer.transform(resource)
28
+ auto_camelize(resource)
32
29
  end
33
30
 
34
31
  def default_properties
35
32
  {
36
- name: @full_project_name,
37
- description: @full_project_name,
38
- artifacts: { type: "NO_ARTIFACTS" },
39
- service_role: { ref: "IamRole" },
40
- badge_enabled: true,
41
- timeout_in_minutes: 20,
42
- logs_config: {
43
- cloud_watch_logs: {
44
- status: "ENABLED",
33
+ Name: @full_project_name,
34
+ Description: @full_project_name,
35
+ Artifacts: { Type: "NO_ARTIFACTS" },
36
+ ServiceRole: { Ref: "IamRole" },
37
+ BadgeEnabled: true,
38
+ TimeoutInMinutes: 20,
39
+ LogsConfig: {
40
+ CloudWatchLogs: {
41
+ Status: "ENABLED",
45
42
  # the default log group name is thankfully the project name
46
43
  }
47
44
  },
48
- source: {
49
- type: "GITHUB",
45
+ Source: {
46
+ Type: "GITHUB",
50
47
  # location: "", # required
51
- # git_clone_depth: 1,
52
- git_submodules_config: { fetch_submodules: true },
53
- build_spec: build_spec,
54
- # auth doesnt seem to work, refer to https://github.com/tongueroo/cody/blob/master/readme/github_oauth.md
55
- # auth: {
56
- # type: "OAUTH",
57
- # # resource: "", # required
48
+ # GitCloneDepth: 1,
49
+ GitSubmodulesConfig: { FetchSubmodules: true },
50
+ BuildSpec: build_spec,
51
+ # auth doesnt seem to work, refer to https://github.com/tongueroo/cody/blob/master/readme/GithubOauth.md
52
+ # Auth: {
53
+ # Type: "OAUTH",
54
+ # # Resource: "", # required
58
55
  # },
59
- report_build_status: true,
56
+ ReportBuildStatus: true,
60
57
  }
61
58
  }
62
59
  end
@@ -1,38 +1,37 @@
1
1
  require "yaml"
2
2
 
3
3
  module Cody
4
- class Role
4
+ class Role < Dsl::Base
5
5
  include Cody::Dsl::Role
6
6
  include Evaluate
7
7
  include Variables
8
8
 
9
9
  def initialize(options={})
10
- @options = options
10
+ super
11
11
  @role_path = options[:role_path] || get_role_path
12
- @properties = default_properties
13
12
  @iam_policy = {}
14
13
  end
15
14
 
16
15
  def run
17
16
  load_variables
18
17
  evaluate(@role_path) if File.exist?(@role_path)
19
- @properties[:policies] = [{
20
- policy_name: "CodeBuildAccess",
21
- policy_document: {
22
- version: "2012-10-17",
23
- statement: derived_iam_statements
18
+ @properties[:Policies] = [{
19
+ PolicyName: "CodeBuildAccess",
20
+ PolicyDocument: {
21
+ Version: "2012-10-17",
22
+ Statement: derived_iam_statements
24
23
  }
25
24
  }]
26
25
 
27
- @properties[:managed_policy_arns] ||= @managed_policy_arns || default_managed_policy_arns
26
+ @properties[:ManagedPolicyArns] ||= @managed_policy_arns || default_managed_policy_arns
28
27
 
29
28
  resource = {
30
29
  IamRole: {
31
- type: "AWS::IAM::Role",
32
- properties: @properties
30
+ Type: "AWS::IAM::Role",
31
+ Properties: @properties
33
32
  }
34
33
  }
35
- CfnCamelizer.transform(resource)
34
+ auto_camelize(resource)
36
35
  end
37
36
 
38
37
  private
@@ -42,17 +41,17 @@ module Cody
42
41
 
43
42
  def default_properties
44
43
  {
45
- assume_role_policy_document: {
46
- statement: [{
47
- action: ["sts:AssumeRole"],
48
- effect: "Allow",
49
- principal: {
50
- service: ["codebuild.amazonaws.com"]
44
+ AssumeRolePolicyDocument: {
45
+ Statement: [{
46
+ Action: ["sts:AssumeRole"],
47
+ Effect: "Allow",
48
+ Principal: {
49
+ Service: ["codebuild.amazonaws.com"]
51
50
  }
52
51
  }],
53
- version: "2012-10-17"
52
+ Version: "2012-10-17"
54
53
  },
55
- path: "/"
54
+ Path: "/"
56
55
  }
57
56
  end
58
57
 
@@ -62,7 +61,7 @@ module Cody
62
61
 
63
62
  def default_iam_statements
64
63
  [{
65
- action: [
64
+ Action: [
66
65
  "logs:CreateLogGroup",
67
66
  "logs:CreateLogStream",
68
67
  "logs:PutLogEvents",
@@ -70,8 +69,8 @@ module Cody
70
69
  "ssm:DescribeParameters",
71
70
  "ssm:GetParameter*",
72
71
  ],
73
- effect: "Allow",
74
- resource: "*"
72
+ Effect: "Allow",
73
+ Resource: "*"
75
74
  }]
76
75
  end
77
76