3
0
Files
corteza/internal/rules/rules.go
Tit Petric 876a304def upd(all):
- moved Access type from system to internal/rules,
- moved Resource from system to internal/rules,
- update imports for new type locations,
- add scope list container to inject permissions,
- update permissions API call to return default perms,
- update codegen for generated Rules types
2019-02-06 11:19:32 +01:00

45 lines
636 B
Go

package rules
import (
"encoding/json"
"errors"
)
type Access int
const (
Allow Access = 2
Deny = 1
Inherit = 0
)
type Rules struct {
TeamID uint64 `db:"rel_team"`
Resource string `db:"resource"`
Operation string `db:"operation"`
Value Access `db:"value"`
}
func (a *Access) UnmarshalJSON(data []byte) error {
var i interface{}
err := json.Unmarshal(data, &i)
if err != nil {
return err
}
s, ok := i.(string)
if !ok {
return errors.New("Type assertion .(string) failed.")
}
switch s {
case "allow":
*a = Allow
case "deny":
*a = Deny
default:
*a = Inherit
}
return nil
}