Skip to content

Commit

Permalink
feat: fix LoadPolicy() for Amazon MemoryDB for Redis (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 authored Mar 9, 2024
1 parent 2f9f7cf commit 00e084b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,12 @@ func (a *Adapter) LoadPolicy(model model.Model) error {
for _, value := range values {
text, ok := value.([]byte)
if !ok {
return errors.New("the type is wrong")
// Amazon MemoryDB for Redis returns string instead of []byte
if textStr, ok := value.(string); ok {
text = []byte(textStr)
} else {
return errors.New("the type is wrong")
}
}
err = json.Unmarshal(text, &line)
if err != nil {
Expand Down Expand Up @@ -545,7 +550,12 @@ func (a *Adapter) loadFilteredPolicy(model model.Model, filter *Filter) error {
for _, value := range values {
text, ok := value.([]byte)
if !ok {
return errors.New("the type is wrong")
// Amazon MemoryDB for Redis returns string instead of []byte
if textStr, ok := value.(string); ok {
text = []byte(textStr)
} else {
return errors.New("the type is wrong")
}
}

if !re.Match(text) {
Expand Down

0 comments on commit 00e084b

Please sign in to comment.