policy: Add Merge API (#11793)

This commit adds a new API in pkg/bucket/policy package called
Merge to merge multiple policies of a user or a group into one
policy document.
This commit is contained in:
Anis Elleuch
2021-03-16 16:50:36 +01:00
committed by GitHub
parent 6160188bf3
commit fa94682e83
12 changed files with 279 additions and 31 deletions

View File

@@ -33,6 +33,26 @@ type Statement struct {
Conditions condition.Functions `json:"Condition,omitempty"`
}
// Equals checks if two statements are equal
func (statement Statement) Equals(st Statement) bool {
if statement.Effect != st.Effect {
return false
}
if !statement.Principal.Equals(st.Principal) {
return false
}
if !statement.Actions.Equals(st.Actions) {
return false
}
if !statement.Resources.Equals(st.Resources) {
return false
}
if !statement.Conditions.Equals(st.Conditions) {
return false
}
return true
}
// IsAllowed - checks given policy args is allowed to continue the Rest API.
func (statement Statement) IsAllowed(args Args) bool {
check := func() bool {
@@ -143,6 +163,12 @@ func (statement Statement) Validate(bucketName string) error {
return statement.Resources.Validate(bucketName)
}
// Clone clones Statement structure
func (statement Statement) Clone() Statement {
return NewStatement(statement.Effect, statement.Principal.Clone(),
statement.Actions.Clone(), statement.Resources.Clone(), statement.Conditions.Clone())
}
// NewStatement - creates new statement.
func NewStatement(effect Effect, principal Principal, actionSet ActionSet, resourceSet ResourceSet, conditions condition.Functions) Statement {
return Statement{