Class: Cumulus::IAM::IamDiff
- Inherits:
-
Common::Diff
- Object
- Common::Diff
- Cumulus::IAM::IamDiff
- Includes:
- IamChange
- Defined in:
- lib/iam/models/IamDiff.rb
Overview
Public: Represents a single difference between local configuration and AWS configuration of an IAM resource
Constant Summary
Constants included from IamChange
Cumulus::IAM::IamChange::ADDED_POLICY, Cumulus::IAM::IamChange::ATTACHED, Cumulus::IAM::IamChange::POLICY, Cumulus::IAM::IamChange::POLICY_DOC, Cumulus::IAM::IamChange::UNMANAGED_POLICY, Cumulus::IAM::IamChange::USER
Constants included from Common::DiffChange
Common::DiffChange::ADD, Common::DiffChange::MODIFIED, Common::DiffChange::UNMANAGED
Instance Attribute Summary collapse
-
#added_users ⇒ Object
Returns the value of attribute added_users.
-
#attached ⇒ Object
Returns the value of attribute attached.
-
#detached ⇒ Object
Returns the value of attribute detached.
-
#policy_name ⇒ Object
Returns the value of attribute policy_name.
-
#removed_users ⇒ Object
Returns the value of attribute removed_users.
Attributes inherited from Common::Diff
#aws, #changes, #info_only, #local, #type
Class Method Summary collapse
-
.added_policy(policy_name, config) ⇒ Object
Public: Create an IamDiff that represents an added policy.
-
.attached(added, removed) ⇒ Object
Public: Create an IamDiff to represent changes in attached policies.
-
.unmanaged_policy(policy_name) ⇒ Object
Public: Create an IamDiff that represents an unmanaged policy.
-
.users(added, removed) ⇒ Object
Public: Create an IamDiff to represent the changes in users for an IAM group.
Instance Method Summary collapse
Methods included from Common::DiffChange
Methods inherited from Common::Diff
#add_string, added, #initialize, #local_name, modified, #to_s, unmanaged, #unmanaged_string
Constructor Details
This class inherits a constructor from Cumulus::Common::Diff
Instance Attribute Details
#added_users ⇒ Object
Returns the value of attribute added_users.
25 26 27 |
# File 'lib/iam/models/IamDiff.rb', line 25 def added_users @added_users end |
#attached ⇒ Object
Returns the value of attribute attached.
26 27 28 |
# File 'lib/iam/models/IamDiff.rb', line 26 def attached @attached end |
#detached ⇒ Object
Returns the value of attribute detached.
29 30 31 |
# File 'lib/iam/models/IamDiff.rb', line 29 def detached @detached end |
#policy_name ⇒ Object
Returns the value of attribute policy_name.
27 28 29 |
# File 'lib/iam/models/IamDiff.rb', line 27 def policy_name @policy_name end |
#removed_users ⇒ Object
Returns the value of attribute removed_users.
28 29 30 |
# File 'lib/iam/models/IamDiff.rb', line 28 def removed_users @removed_users end |
Class Method Details
.added_policy(policy_name, config) ⇒ Object
Public: Create an IamDiff that represents an added policy
policy_name - the name of the policy that is added config - the configuration for the policy
Returns an IamDiff representing the changes
48 49 50 51 52 |
# File 'lib/iam/models/IamDiff.rb', line 48 def self.added_policy(policy_name, config) diff = IamDiff.new(ADDED_POLICY, nil, config) diff.policy_name = policy_name diff end |
.attached(added, removed) ⇒ Object
Public: Create an IamDiff to represent changes in attached policies
added - the added attached policies removed - the removed attached policies
Returns an IamDiff representing those changes
73 74 75 76 77 78 |
# File 'lib/iam/models/IamDiff.rb', line 73 def self.attached(added, removed) diff = IamDiff.new(ATTACHED) diff.attached = added diff.detached = removed diff end |
.unmanaged_policy(policy_name) ⇒ Object
Public: Create an IamDiff that represents an unmanaged policy
policy_name - the name of the policy that is unmanaged
Returns an IamDiff representing the changes
36 37 38 39 40 |
# File 'lib/iam/models/IamDiff.rb', line 36 def self.unmanaged_policy(policy_name) diff = IamDiff.new(UNMANAGED_POLICY) diff.policy_name = policy_name diff end |
.users(added, removed) ⇒ Object
Public: Create an IamDiff to represent the changes in users for an IAM group
added - the added users removed - the removed users
Returns an IamDiff representing those changes
60 61 62 63 64 65 |
# File 'lib/iam/models/IamDiff.rb', line 60 def self.users(added, removed) diff = IamDiff.new(USER) diff.added_users = added diff.removed_users = removed diff end |
Instance Method Details
#asset_type ⇒ Object
123 124 125 |
# File 'lib/iam/models/IamDiff.rb', line 123 def asset_type "IAM resource" end |
#aws_name ⇒ Object
127 128 129 |
# File 'lib/iam/models/IamDiff.rb', line 127 def aws_name @aws.name end |
#diff_string ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/iam/models/IamDiff.rb', line 80 def diff_string case @type when ADDED_POLICY Colors.added("Policy #{@policy_name} will be created.") when ATTACHED lines = ["Attached policies:"] lines << @attached.map { |arn| Colors.added("\t#{arn}") } lines << @detached.map { |arn| Colors.removed("\t#{arn}") } lines.flatten.join("\n") when POLICY lines = ["Policy differences:"] locals = @local.as_hash["Statement"] @aws.each do |aws| if !locals.include?(aws) lines << "\tAWS:\t#{Colors.aws_changes(aws.to_json)}" end end locals.each do |local| if !@aws.include?(local) lines << "\tLocal:\t#{Colors.local_changes(local.to_json)}" end end lines.join("\n") when POLICY_DOC aws = JSON.parse(URI.unescape(@aws.assume_role_policy_document)).to_s [ "Assume role policy document:", Colors.aws_changes("\tAWS -\t#{aws}"), Colors.local_changes("\tLocal -\t#{@local.one_line_policy_document}") ].join("\n") when UNMANAGED_POLICY Colors.unmanaged("Policy #{@policy_name} is not managed by Cumulus") when USER lines = ["User differences:"] lines << @added_users.map { |u| Colors.added("\t#{u}") } lines << @removed_users.map { |u| Colors.removed("\t#{u}") } lines.flatten.join("\n") end end |