Class: Cumulus::IAM::PolicyConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/iam/models/PolicyConfig.rb

Overview

Public: Represents a policy in AWS. Contains StatementConfig objects that define the things this policy allows.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePolicyConfig

Public: Constructor. Will be created with no statements.



14
15
16
17
# File 'lib/iam/models/PolicyConfig.rb', line 14

def initialize
  @version = Configuration.instance.iam.policy_version
  @statements = []
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/iam/models/PolicyConfig.rb', line 11

def name
  @name
end

Instance Method Details

#add_statement(statement) ⇒ Object

Public: Add a StatementConfig object to the statements in this PolicyConfig

statement - the StatementConfig object to add to this PolicyConfig



22
23
24
# File 'lib/iam/models/PolicyConfig.rb', line 22

def add_statement(statement)
  @statements.push(statement)
end

#as_hashObject

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



54
55
56
57
58
59
60
61
62
63
# 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

#as_jsonObject

Public: Create a JSON string representing this PolicyConfig which can be used by AWS IAMs.

Returns the String JSON representation



38
39
40
# File 'lib/iam/models/PolicyConfig.rb', line 38

def as_json
  as_hash.to_json
end

#as_pretty_jsonObject

Public: Create a pretty JSON string representing this PolicyConfig which can be used by AWS IAMs.

Returns the String JSON representation (pretty printed)



46
47
48
# File 'lib/iam/models/PolicyConfig.rb', line 46

def as_pretty_json
  JSON.pretty_generate(as_hash)
end

#empty?Boolean

Public: Determine if this policy is empty. It is considered empty if there are no statements.

Returns true if empty, false if not

Returns:

  • (Boolean)


30
31
32
# File 'lib/iam/models/PolicyConfig.rb', line 30

def empty?
  @statements.empty?
end