Class: Jets::Cfn::Resource::Codebuild::IamRole

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/cfn/resource/codebuild/iam_role.rb

Instance Method Summary collapse

Methods inherited from Base

#attributes, #config, #logical_id, #normalize_tags, #outputs, #parameters, #properties, #replacements, #replacer, #standarize, #template, truncate_id, #type

Methods included from Util::Camelize

#camelize

Methods included from Util::Logging

#log

Instance Method Details

#custom_managed_policyObject



59
60
61
# File 'lib/jets/cfn/resource/codebuild/iam_role.rb', line 59

def custom_managed_policy
  Jets::Cfn::Iam::ManagedPolicy.new(config.codebuild.iam.managed_policy).standardize
end

#custom_policyObject



47
48
49
# File 'lib/jets/cfn/resource/codebuild/iam_role.rb', line 47

def custom_policy
  Jets::Cfn::Iam::Policy.new("CustomPolicy", config.codebuild.iam.policy).standardize
end

#default_managed_policyObject



55
56
57
# File 'lib/jets/cfn/resource/codebuild/iam_role.rb', line 55

def default_managed_policy
  Jets::Cfn::Iam::ManagedPolicy.new(config.codebuild.iam.default_managed_policy).standardize
end

#default_policyObject



36
37
38
# File 'lib/jets/cfn/resource/codebuild/iam_role.rb', line 36

def default_policy
  Jets::Cfn::Iam::Policy.new("DefaultPolicy", config.codebuild.iam.default_policy).standardize
end

#definitionObject



3
4
5
6
7
8
9
10
# File 'lib/jets/cfn/resource/codebuild/iam_role.rb', line 3

def definition
  {
    "CodebuildRole" => {
      Type: "AWS::IAM::Role",
      Properties: props
    }
  }
end

#managed_policy_arnsObject



51
52
53
# File 'lib/jets/cfn/resource/codebuild/iam_role.rb', line 51

def managed_policy_arns
  [default_managed_policy, custom_managed_policy].flatten.compact
end

#policiesObject



32
33
34
# File 'lib/jets/cfn/resource/codebuild/iam_role.rb', line 32

def policies
  [default_policy, custom_policy, vpc_policy].flatten.compact
end

#propsObject

Do not name this method properties as that’s a computed method



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jets/cfn/resource/codebuild/iam_role.rb', line 13

def props
  text = <<~EOL
    AssumeRolePolicyDocument:
      Statement:
      - Action:
        - sts:AssumeRole
        Effect: Allow
        Principal:
          Service:
          - codebuild.amazonaws.com
      Version: '2012-10-17'
    Path: "/"
  EOL
  props = YAML.load(text).deep_symbolize_keys
  props[:Policies] = policies
  props[:ManagedPolicyArns] = managed_policy_arns
  props
end

#vpc_policyObject



40
41
42
43
44
45
# File 'lib/jets/cfn/resource/codebuild/iam_role.rb', line 40

def vpc_policy
  policy = config.codebuild.iam.default_vpc_policy
  if !policy.nil? && !policy.empty?
    Jets::Cfn::Iam::Policy.new("VpcPolicy", policy).standardize
  end
end