class Cumulus::IAM::PolicyConfig
Public: Represents a policy in AWS. Contains StatementConfig
objects that define the things this policy allows.
Attributes
Public Class Methods
Public: Constructor. Will be created with no statements.
# File lib/iam/models/PolicyConfig.rb, line 14 def initialize @version = Configuration.instance.iam.policy_version @statements = [] end
Public Instance Methods
Public: Add a StatementConfig
object to the statements in this PolicyConfig
statement - the StatementConfig
object to add to this PolicyConfig
# File lib/iam/models/PolicyConfig.rb, line 22 def add_statement(statement) @statements.push(statement) end
Public: Create a Hash that contains the data in this PolicyConfig
which will conform to the AWS IAM
format when converted to JSON
Returns a Hash representing this PolicyConfig
# File lib/iam/models/PolicyConfig.rb, line 54 def as_hash statements = @statements.map do |statement| statement.as_hash end { "Version" => @version, "Statement" => statements }.deep_sort end
Public: Create a JSON string representing this PolicyConfig
which can be used by AWS IAMs.
Returns the String JSON representation
# File lib/iam/models/PolicyConfig.rb, line 38 def as_json as_hash.to_json end
Public: Create a pretty JSON string representing this PolicyConfig
which can be used by AWS IAMs.
Returns the String JSON representation (pretty printed)
# File lib/iam/models/PolicyConfig.rb, line 46 def as_pretty_json JSON.pretty_generate(as_hash) end
Public: Determine if this policy is empty. It is considered empty if there are no statements.
Returns true if empty, false if not
# File lib/iam/models/PolicyConfig.rb, line 30 def empty? @statements.empty? end