mirror of
https://github.com/minio/minio.git
synced 2025-11-07 04:42:56 -05:00
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:
@@ -66,6 +66,42 @@ func (functions Functions) Keys() KeySet {
|
||||
return keySet
|
||||
}
|
||||
|
||||
// Clone clones Functions structure
|
||||
func (functions Functions) Clone() Functions {
|
||||
funcs := []Function{}
|
||||
|
||||
for _, f := range functions {
|
||||
vfn := conditionFuncMap[f.name()]
|
||||
for key, values := range f.toMap() {
|
||||
function, _ := vfn(key, values.Clone())
|
||||
funcs = append(funcs, function)
|
||||
}
|
||||
}
|
||||
|
||||
return funcs
|
||||
}
|
||||
|
||||
// Equals returns true if two Functions structures are equal
|
||||
func (functions Functions) Equals(funcs Functions) bool {
|
||||
if len(functions) != len(funcs) {
|
||||
return false
|
||||
}
|
||||
for _, fi := range functions {
|
||||
fistr := fi.String()
|
||||
found := false
|
||||
for _, fj := range funcs {
|
||||
if fistr == fj.String() {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// MarshalJSON - encodes Functions to JSON data.
|
||||
func (functions Functions) MarshalJSON() ([]byte, error) {
|
||||
nm := make(map[name]map[Key]ValueSet)
|
||||
|
||||
@@ -29,6 +29,15 @@ func (set ValueSet) Add(value Value) {
|
||||
set[value] = struct{}{}
|
||||
}
|
||||
|
||||
// ToSlice converts ValueSet to a slice of Value
|
||||
func (set ValueSet) ToSlice() []Value {
|
||||
var values []Value
|
||||
for k := range set {
|
||||
values = append(values, k)
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
// MarshalJSON - encodes ValueSet to JSON data.
|
||||
func (set ValueSet) MarshalJSON() ([]byte, error) {
|
||||
var values []Value
|
||||
@@ -73,6 +82,11 @@ func (set *ValueSet) UnmarshalJSON(data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Clone clones ValueSet structure
|
||||
func (set ValueSet) Clone() ValueSet {
|
||||
return NewValueSet(set.ToSlice()...)
|
||||
}
|
||||
|
||||
// NewValueSet - returns new value set containing given values.
|
||||
func NewValueSet(values ...Value) ValueSet {
|
||||
set := make(ValueSet)
|
||||
|
||||
Reference in New Issue
Block a user