Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pkg/resource/bucket/acl_custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,25 @@ func formGrantHeader(grants []*svcsdk.Grant) string {
return strings.Join(headers, ",")
}

// isDefaultCannedACLPossibilities determines whether the list of joined ACL
// possibilites is the default for a bucket.
func isDefaultCannedACLPossibilities(joinedPossibilities string) bool {
return matchPossibleCannedACL(CannedACLPrivate, joinedPossibilities) != nil
}

// matchPossibleCannedACL attempts to find a canned ACL string in a joined
// list of possibilities. If any of the possibilities matches, it will be
// returned, otherwise nil.
func matchPossibleCannedACL(search string, joinedPossibilities string) *string {
splitPossibilities := strings.Split(joinedPossibilities, CannedACLJoinDelimiter)
for _, possible := range splitPossibilities {
if search == possible {
return &possible
}
}
return nil
}

// GetHeadersFromGrants will return a list of grant headers from grants
func GetHeadersFromGrants(
resp *svcsdk.GetBucketAclOutput,
Expand Down
18 changes: 5 additions & 13 deletions pkg/resource/bucket/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,11 @@ func customPreCompare(
b.ko.Spec.ACL = matchPossibleCannedACL(*a.ko.Spec.ACL, *b.ko.Spec.ACL)
}
} else {
// Ignore diff if possible canned ACLs are the default
if b.ko.Spec.ACL != nil && isDefaultCannedACLPossibilities(*b.ko.Spec.ACL) {
b.ko.Spec.ACL = nil
}

// If we are sure the grants weren't set from the header strings
if a.ko.Spec.GrantFullControl == nil &&
a.ko.Spec.GrantRead == nil &&
Expand Down Expand Up @@ -677,19 +682,6 @@ func (rm *resourceManager) setResourceACL(
ko.Spec.ACL = &joinedACLs
}

// matchPossibleCannedACL attempts to find a canned ACL string in a joined
// list of possibilities. If any of the possibilities matches, it will be
// returned, otherwise nil.
func matchPossibleCannedACL(search string, joinedPossibilities string) *string {
splitPossibilities := strings.Split(joinedPossibilities, CannedACLJoinDelimiter)
for _, possible := range splitPossibilities {
if search == possible {
return &possible
}
}
return nil
}

func (rm *resourceManager) newGetBucketACLPayload(
r *resource,
) *svcsdk.GetBucketAclInput {
Expand Down