Appends given statement into statement list to have unique statements. - If statement already exists in statement list, it ignores. - If statement exists with different conditions, they are merged. - Else the statement is appended to statement list.
(statements []Statement, statement Statement)
| 434 | // - If statement exists with different conditions, they are merged. |
| 435 | // - Else the statement is appended to statement list. |
| 436 | func appendStatement(statements []Statement, statement Statement) []Statement { |
| 437 | for i, s := range statements { |
| 438 | if s.Actions.Equals(statement.Actions) && |
| 439 | s.Effect == statement.Effect && |
| 440 | s.Principal.AWS.Equals(statement.Principal.AWS) && |
| 441 | reflect.DeepEqual(s.Conditions, statement.Conditions) { |
| 442 | statements[i].Resources = s.Resources.Union(statement.Resources) |
| 443 | return statements |
| 444 | } else if s.Resources.Equals(statement.Resources) && |
| 445 | s.Effect == statement.Effect && |
| 446 | s.Principal.AWS.Equals(statement.Principal.AWS) && |
| 447 | reflect.DeepEqual(s.Conditions, statement.Conditions) { |
| 448 | statements[i].Actions = s.Actions.Union(statement.Actions) |
| 449 | return statements |
| 450 | } |
| 451 | |
| 452 | if s.Resources.Intersection(statement.Resources).Equals(statement.Resources) && |
| 453 | s.Actions.Intersection(statement.Actions).Equals(statement.Actions) && |
| 454 | s.Effect == statement.Effect && |
| 455 | s.Principal.AWS.Intersection(statement.Principal.AWS).Equals(statement.Principal.AWS) { |
| 456 | if reflect.DeepEqual(s.Conditions, statement.Conditions) { |
| 457 | return statements |
| 458 | } |
| 459 | if s.Conditions != nil && statement.Conditions != nil { |
| 460 | if s.Resources.Equals(statement.Resources) { |
| 461 | statements[i].Conditions = mergeConditionMap(s.Conditions, statement.Conditions) |
| 462 | return statements |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | if !statement.Actions.IsEmpty() || !statement.Resources.IsEmpty() { |
| 469 | return append(statements, statement) |
| 470 | } |
| 471 | |
| 472 | return statements |
| 473 | } |
| 474 | |
| 475 | // Appends two statement lists. |
| 476 | func appendStatements(statements, appendStatements []Statement) []Statement { |