-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bucket): Convert bools to string in policy
AWS converts bool values in policy conditions to strings when getting them from the API. Add a new policy parser based on structs that can handle AWS policies correctly, including single items instead of lists. Signed-off-by: Maximilian Blatt (external expert on behalf of DB Netz) <maximilian.blatt-extern@deutschebahn.com>
- Loading branch information
Showing
9 changed files
with
599 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package policy | ||
|
||
import ( | ||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
// ArePoliciesEqal determines if the two Policy objects can be considered | ||
// equal. | ||
func ArePoliciesEqal(a, b *Policy) (equal bool, diff string) { | ||
diff = cmp.Diff(a, b) | ||
return diff == "", diff | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package policy | ||
|
||
import "encoding/json" | ||
|
||
// ParsePolicyBytes from a byte array representing a raw JSOn string. | ||
func ParsePolicyBytes(raw []byte) (Policy, error) { | ||
policy := Policy{} | ||
err := json.Unmarshal(raw, &policy) | ||
return policy, err | ||
} | ||
|
||
// ParsePolicyString from a raw JSON string. | ||
func ParsePolicyString(raw string) (Policy, error) { | ||
return ParsePolicyBytes([]byte(raw)) | ||
} | ||
|
||
// ParsePolicyObject parses a policy from an object (i.e. an API struct) which | ||
// can be marshalled into JSON. | ||
func ParsePolicyObject(obj any) (Policy, error) { | ||
input, err := json.Marshal(obj) | ||
if err != nil { | ||
return Policy{}, err | ||
} | ||
return ParsePolicyBytes(input) | ||
} |
Oops, something went wrong.