MCPcopy
hub / github.com/minio/minio-go / appendStatement

Function appendStatement

pkg/policy/bucket-policy.go:436–473  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

434// - If statement exists with different conditions, they are merged.
435// - Else the statement is appended to statement list.
436func 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.
476func appendStatements(statements, appendStatements []Statement) []Statement {

Callers 2

appendStatementsFunction · 0.85
TestAppendStatementFunction · 0.85

Calls 5

mergeConditionMapFunction · 0.85
EqualsMethod · 0.45
UnionMethod · 0.45
IntersectionMethod · 0.45
IsEmptyMethod · 0.45

Tested by 1

TestAppendStatementFunction · 0.68