Class: Convection::Model::Mixin::Policy::Statement

Inherits:
Object
  • Object
show all
Includes:
DSL::Helpers
Defined in:
lib/convection/model/mixin/policy.rb

Overview

An IAM policy statement

Instance Method Summary collapse

Methods included from DSL::Helpers

#camel_case, included, method_name, #screaming_snake_case, #snake_case

Methods included from DSL::IntrinsicFunctions

#base64, #find_in_map, #fn_and, #fn_equals, #fn_if, #fn_not, #fn_or, #fn_ref, #get_att, #get_azs, #join, #select

Constructor Details

#initialize(effect = 'Allow', template = nil) ⇒ Statement

Returns a new instance of Statement



84
85
86
87
88
89
90
91
# File 'lib/convection/model/mixin/policy.rb', line 84

def initialize(effect = 'Allow', template = nil)
  @effect = effect

  @action = []
  @resource = []

  @template = template
end

Instance Method Details

#renderObject



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/convection/model/mixin/policy.rb', line 93

def render
  {
    'Effect' => effect,
    'Action' => action
  }.tap do |statement|
    statement['Sid'] = sid unless sid.nil?
    statement['Condition'] = condition unless condition.nil?
    statement['Principal'] = principal unless principal.nil?
    statement['NotPrincipal'] = not_principal unless not_principal.nil?
    statement['Resource'] = resource unless resource.empty? # Avoid failure in CF if empty Resources array is passed
  end
end

#s3_resource(bucket, path = nil) ⇒ Object



71
72
73
74
# File 'lib/convection/model/mixin/policy.rb', line 71

def s3_resource(bucket, path = nil)
  return resource "arn:aws:s3:::#{ bucket }/#{ path }" unless path.nil?
  resource "arn:aws:s3:::#{ bucket }"
end

#sns_resource(region, account, topic) ⇒ Object



80
81
82
# File 'lib/convection/model/mixin/policy.rb', line 80

def sns_resource(region, , topic)
  resource "arn:aws:sns:#{ region }:#{  }:#{ topic }"
end

#sqs_resource(region, account, queue) ⇒ Object



76
77
78
# File 'lib/convection/model/mixin/policy.rb', line 76

def sqs_resource(region, , queue)
  resource "arn:aws:sqs:#{ region }:#{  }:#{ queue }"
end