class Convection::Model::Mixin::Policy
Add definition helpers for entities with policies
Constants
- DEFAULT_VERSION
Public Class Methods
new(options = {})
click to toggle source
# File lib/convection/model/mixin/policy.rb, line 19 def initialize(options = {}) @name = options.fetch(:name) { SecureRandom.uuid } @version = DEFAULT_VERSION @statement = [] @template = options[:template] end
Public Instance Methods
allow(sid = nil, &block)
click to toggle source
# File lib/convection/model/mixin/policy.rb, line 27 def allow(sid = nil, &block) add_statement = Statement.new('Allow', @template) add_statement.sid = sid unless sid.nil? add_statement.instance_exec(&block) if block statement(add_statement) end
deny(sid = nil, &block)
click to toggle source
# File lib/convection/model/mixin/policy.rb, line 35 def deny(sid = nil, &block) add_statement = Statement.new('Deny', @template) add_statement.sid = sid unless sid.nil? add_statement.instance_exec(&block) if block statement(add_statement) end
document()
click to toggle source
# File lib/convection/model/mixin/policy.rb, line 43 def document doc = { 'Version' => version, 'Statement' => statement.map(&:render) } doc['Id'] = id if id doc end
render(parent = {})
click to toggle source
# File lib/convection/model/mixin/policy.rb, line 52 def render(parent = {}) parent.tap do |resource| resource['PolicyName'] = name unless name.is_a?(FalseClass) resource['PolicyDocument'] = document end end