Skip to content
Snippets Groups Projects
Unverified Commit 193df33e authored by Silas Davis's avatar Silas Davis
Browse files

Make PermArgs field naming less inpenetrable


Signed-off-by: default avatarSilas Davis <silas@monax.io>
parent 47e3d965
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
name = "github.com/btcsuite/btcd" name = "github.com/btcsuite/btcd"
packages = ["btcec"] packages = ["btcec"]
pruneopts = "NUT" pruneopts = "NUT"
revision = "f673a4b563b57b9a95832545c878669a7fa801d9" revision = "9a2f9524024889e129a5422aca2cff73cb3eabf6"
[[projects]] [[projects]]
branch = "master" branch = "master"
...@@ -436,7 +436,7 @@ ...@@ -436,7 +436,7 @@
"ssh/terminal", "ssh/terminal",
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "a2144134853fc9a27a7b1e3eb4f19f1a76df13c9" revision = "c126467f60eb25f8f27e5a981f32a87e3965053f"
[[projects]] [[projects]]
digest = "1:15dbe437d38eb2103f6b55348758958a6f85a400ecc16fcb53b3f271d38cd8ea" digest = "1:15dbe437d38eb2103f6b55348758958a6f85a400ecc16fcb53b3f271d38cd8ea"
...@@ -495,7 +495,7 @@ ...@@ -495,7 +495,7 @@
name = "google.golang.org/genproto" name = "google.golang.org/genproto"
packages = ["googleapis/rpc/status"] packages = ["googleapis/rpc/status"]
pruneopts = "NUT" pruneopts = "NUT"
revision = "fedd2861243fd1a8152376292b921b394c7bef7e" revision = "02b4e95473316948020af0b7a4f0f22c73929b0e"
[[projects]] [[projects]]
digest = "1:f778941d5c2e46da5e0f5d553d3e80bf70eb40d2e80bb4c649b625b9133f3d5f" digest = "1:f778941d5c2e46da5e0f5d553d3e80bf70eb40d2e80bb4c649b625b9133f3d5f"
...@@ -552,7 +552,9 @@ ...@@ -552,7 +552,9 @@
"github.com/go-kit/kit/log/term", "github.com/go-kit/kit/log/term",
"github.com/gogo/protobuf/gogoproto", "github.com/gogo/protobuf/gogoproto",
"github.com/gogo/protobuf/proto", "github.com/gogo/protobuf/proto",
"github.com/gogo/protobuf/types",
"github.com/golang/protobuf/proto", "github.com/golang/protobuf/proto",
"github.com/golang/protobuf/ptypes/timestamp",
"github.com/gorilla/websocket", "github.com/gorilla/websocket",
"github.com/howeyc/gopass", "github.com/howeyc/gopass",
"github.com/imdario/mergo", "github.com/imdario/mergo",
......
...@@ -78,7 +78,7 @@ protobuf_deps: ...@@ -78,7 +78,7 @@ protobuf_deps:
# Implicit compile rule for GRPC/proto files (note since pb.go files no longer generated # Implicit compile rule for GRPC/proto files (note since pb.go files no longer generated
# in same directory as proto file this just regenerates everything # in same directory as proto file this just regenerates everything
%.pb.go: %.proto %.pb.go: %.proto
protoc -I vendor -I protobuf $< --gogo_out=plugins=grpc:${GOPATH}/src protoc -I protobuf -I vendor $< --gogo_out=plugins=grpc:${GOPATH}/src
.PHONY: protobuf .PHONY: protobuf
protobuf: $(PROTO_GO_FILES) protobuf: $(PROTO_GO_FILES)
......
...@@ -44,7 +44,7 @@ func (ctx *PermissionsContext) Execute(txe *exec.TxExecution) error { ...@@ -44,7 +44,7 @@ func (ctx *PermissionsContext) Execute(txe *exec.TxExecution) error {
return fmt.Errorf("PermsTx received containing invalid PermArgs: %v", err) return fmt.Errorf("PermsTx received containing invalid PermArgs: %v", err)
} }
permFlag := ctx.tx.PermArgs.PermFlag permFlag := ctx.tx.PermArgs.Action
// check permission // check permission
if !HasPermission(ctx.StateWriter, inAcc, permFlag, ctx.Logger) { if !HasPermission(ctx.StateWriter, inAcc, permFlag, ctx.Logger) {
return fmt.Errorf("account %s does not have moderator permission %s (%b)", ctx.tx.Input.Address, return fmt.Errorf("account %s does not have moderator permission %s (%b)", ctx.tx.Input.Address,
...@@ -65,17 +65,17 @@ func (ctx *PermissionsContext) Execute(txe *exec.TxExecution) error { ...@@ -65,17 +65,17 @@ func (ctx *PermissionsContext) Execute(txe *exec.TxExecution) error {
"perm_args", ctx.tx.PermArgs.String()) "perm_args", ctx.tx.PermArgs.String())
var permAcc acm.Account var permAcc acm.Account
switch ctx.tx.PermArgs.PermFlag { switch ctx.tx.PermArgs.Action {
case permission.HasBase: case permission.HasBase:
// this one doesn't make sense from txs // this one doesn't make sense from txs
return fmt.Errorf("HasBase is for contracts, not humans. Just look at the blockchain") return fmt.Errorf("HasBase is for contracts, not humans. Just look at the blockchain")
case permission.SetBase: case permission.SetBase:
permAcc, err = mutatePermissions(ctx.StateWriter, *ctx.tx.PermArgs.Address, permAcc, err = mutatePermissions(ctx.StateWriter, *ctx.tx.PermArgs.Target,
func(perms *permission.AccountPermissions) error { func(perms *permission.AccountPermissions) error {
return perms.Base.Set(*ctx.tx.PermArgs.Permission, *ctx.tx.PermArgs.Value) return perms.Base.Set(*ctx.tx.PermArgs.Permission, *ctx.tx.PermArgs.Value)
}) })
case permission.UnsetBase: case permission.UnsetBase:
permAcc, err = mutatePermissions(ctx.StateWriter, *ctx.tx.PermArgs.Address, permAcc, err = mutatePermissions(ctx.StateWriter, *ctx.tx.PermArgs.Target,
func(perms *permission.AccountPermissions) error { func(perms *permission.AccountPermissions) error {
return perms.Base.Unset(*ctx.tx.PermArgs.Permission) return perms.Base.Unset(*ctx.tx.PermArgs.Permission)
}) })
...@@ -87,20 +87,20 @@ func (ctx *PermissionsContext) Execute(txe *exec.TxExecution) error { ...@@ -87,20 +87,20 @@ func (ctx *PermissionsContext) Execute(txe *exec.TxExecution) error {
case permission.HasRole: case permission.HasRole:
return fmt.Errorf("HasRole is for contracts, not humans. Just look at the blockchain") return fmt.Errorf("HasRole is for contracts, not humans. Just look at the blockchain")
case permission.AddRole: case permission.AddRole:
permAcc, err = mutatePermissions(ctx.StateWriter, *ctx.tx.PermArgs.Address, permAcc, err = mutatePermissions(ctx.StateWriter, *ctx.tx.PermArgs.Target,
func(perms *permission.AccountPermissions) error { func(perms *permission.AccountPermissions) error {
if !perms.AddRole(*ctx.tx.PermArgs.Role) { if !perms.AddRole(*ctx.tx.PermArgs.Role) {
return fmt.Errorf("role (%s) already exists for account %s", return fmt.Errorf("role (%s) already exists for account %s",
*ctx.tx.PermArgs.Role, *ctx.tx.PermArgs.Address) *ctx.tx.PermArgs.Role, *ctx.tx.PermArgs.Target)
} }
return nil return nil
}) })
case permission.RemoveRole: case permission.RemoveRole:
permAcc, err = mutatePermissions(ctx.StateWriter, *ctx.tx.PermArgs.Address, permAcc, err = mutatePermissions(ctx.StateWriter, *ctx.tx.PermArgs.Target,
func(perms *permission.AccountPermissions) error { func(perms *permission.AccountPermissions) error {
if !perms.RmRole(*ctx.tx.PermArgs.Role) { if !perms.RmRole(*ctx.tx.PermArgs.Role) {
return fmt.Errorf("role (%s) does not exist for account %s", return fmt.Errorf("role (%s) does not exist for account %s",
*ctx.tx.PermArgs.Role, *ctx.tx.PermArgs.Address) *ctx.tx.PermArgs.Role, *ctx.tx.PermArgs.Target)
} }
return nil return nil
}) })
......
...@@ -94,20 +94,23 @@ func (*BasePermissions) XXX_MessageName() string { ...@@ -94,20 +94,23 @@ func (*BasePermissions) XXX_MessageName() string {
} }
type PermArgs struct { type PermArgs struct {
PermFlag PermFlag `protobuf:"varint,1,opt,name=PermFlag,casttype=PermFlag" json:"PermFlag"` // The permission function
Address *github_com_hyperledger_burrow_crypto.Address `protobuf:"bytes,2,opt,name=Address,customtype=github.com/hyperledger/burrow/crypto.Address" json:"Address,omitempty"` Action PermFlag `protobuf:"varint,1,opt,name=Action,casttype=PermFlag" json:"Action"`
Permission *PermFlag `protobuf:"varint,3,opt,name=Permission,casttype=PermFlag" json:"Permission,omitempty"` // The target of the action
Role *string `protobuf:"bytes,4,opt,name=Role" json:"Role,omitempty"` Target *github_com_hyperledger_burrow_crypto.Address `protobuf:"bytes,2,opt,name=Target,customtype=github.com/hyperledger/burrow/crypto.Address" json:"Target,omitempty"`
Value *bool `protobuf:"varint,5,opt,name=Value" json:"Value,omitempty"` // Possible arguments
Permission *PermFlag `protobuf:"varint,3,opt,name=Permission,casttype=PermFlag" json:"Permission,omitempty"`
Role *string `protobuf:"bytes,4,opt,name=Role" json:"Role,omitempty"`
Value *bool `protobuf:"varint,5,opt,name=Value" json:"Value,omitempty"`
} }
func (m *PermArgs) Reset() { *m = PermArgs{} } func (m *PermArgs) Reset() { *m = PermArgs{} }
func (*PermArgs) ProtoMessage() {} func (*PermArgs) ProtoMessage() {}
func (*PermArgs) Descriptor() ([]byte, []int) { return fileDescriptorPermission, []int{2} } func (*PermArgs) Descriptor() ([]byte, []int) { return fileDescriptorPermission, []int{2} }
func (m *PermArgs) GetPermFlag() PermFlag { func (m *PermArgs) GetAction() PermFlag {
if m != nil { if m != nil {
return m.PermFlag return m.Action
} }
return 0 return 0
} }
...@@ -232,12 +235,12 @@ func (m *PermArgs) MarshalTo(dAtA []byte) (int, error) { ...@@ -232,12 +235,12 @@ func (m *PermArgs) MarshalTo(dAtA []byte) (int, error) {
_ = l _ = l
dAtA[i] = 0x8 dAtA[i] = 0x8
i++ i++
i = encodeVarintPermission(dAtA, i, uint64(m.PermFlag)) i = encodeVarintPermission(dAtA, i, uint64(m.Action))
if m.Address != nil { if m.Target != nil {
dAtA[i] = 0x12 dAtA[i] = 0x12
i++ i++
i = encodeVarintPermission(dAtA, i, uint64(m.Address.Size())) i = encodeVarintPermission(dAtA, i, uint64(m.Target.Size()))
n2, err := m.Address.MarshalTo(dAtA[i:]) n2, err := m.Target.MarshalTo(dAtA[i:])
if err != nil { if err != nil {
return 0, err return 0, err
} }
...@@ -307,9 +310,9 @@ func (m *BasePermissions) Size() (n int) { ...@@ -307,9 +310,9 @@ func (m *BasePermissions) Size() (n int) {
func (m *PermArgs) Size() (n int) { func (m *PermArgs) Size() (n int) {
var l int var l int
_ = l _ = l
n += 1 + sovPermission(uint64(m.PermFlag)) n += 1 + sovPermission(uint64(m.Action))
if m.Address != nil { if m.Target != nil {
l = m.Address.Size() l = m.Target.Size()
n += 1 + l + sovPermission(uint64(l)) n += 1 + l + sovPermission(uint64(l))
} }
if m.Permission != nil { if m.Permission != nil {
...@@ -568,9 +571,9 @@ func (m *PermArgs) Unmarshal(dAtA []byte) error { ...@@ -568,9 +571,9 @@ func (m *PermArgs) Unmarshal(dAtA []byte) error {
switch fieldNum { switch fieldNum {
case 1: case 1:
if wireType != 0 { if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field PermFlag", wireType) return fmt.Errorf("proto: wrong wireType = %d for field Action", wireType)
} }
m.PermFlag = 0 m.Action = 0
for shift := uint(0); ; shift += 7 { for shift := uint(0); ; shift += 7 {
if shift >= 64 { if shift >= 64 {
return ErrIntOverflowPermission return ErrIntOverflowPermission
...@@ -580,14 +583,14 @@ func (m *PermArgs) Unmarshal(dAtA []byte) error { ...@@ -580,14 +583,14 @@ func (m *PermArgs) Unmarshal(dAtA []byte) error {
} }
b := dAtA[iNdEx] b := dAtA[iNdEx]
iNdEx++ iNdEx++
m.PermFlag |= (PermFlag(b) & 0x7F) << shift m.Action |= (PermFlag(b) & 0x7F) << shift
if b < 0x80 { if b < 0x80 {
break break
} }
} }
case 2: case 2:
if wireType != 2 { if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) return fmt.Errorf("proto: wrong wireType = %d for field Target", wireType)
} }
var byteLen int var byteLen int
for shift := uint(0); ; shift += 7 { for shift := uint(0); ; shift += 7 {
...@@ -612,8 +615,8 @@ func (m *PermArgs) Unmarshal(dAtA []byte) error { ...@@ -612,8 +615,8 @@ func (m *PermArgs) Unmarshal(dAtA []byte) error {
return io.ErrUnexpectedEOF return io.ErrUnexpectedEOF
} }
var v github_com_hyperledger_burrow_crypto.Address var v github_com_hyperledger_burrow_crypto.Address
m.Address = &v m.Target = &v
if err := m.Address.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { if err := m.Target.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err return err
} }
iNdEx = postIndex iNdEx = postIndex
...@@ -818,27 +821,28 @@ func init() { proto.RegisterFile("permission.proto", fileDescriptorPermission) } ...@@ -818,27 +821,28 @@ func init() { proto.RegisterFile("permission.proto", fileDescriptorPermission) }
func init() { golang_proto.RegisterFile("permission.proto", fileDescriptorPermission) } func init() { golang_proto.RegisterFile("permission.proto", fileDescriptorPermission) }
var fileDescriptorPermission = []byte{ var fileDescriptorPermission = []byte{
// 351 bytes of a gzipped FileDescriptorProto // 355 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x51, 0x31, 0x4b, 0xc3, 0x40, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x51, 0xb1, 0x4b, 0xfb, 0x40,
0x14, 0xee, 0xb5, 0xa9, 0xb6, 0xcf, 0x82, 0xe5, 0x70, 0x08, 0x0a, 0x49, 0xe8, 0x20, 0x19, 0x6a, 0x14, 0xee, 0xb5, 0x69, 0x69, 0xdf, 0xaf, 0xf0, 0x2b, 0x87, 0x43, 0x50, 0x48, 0x42, 0x07, 0xc9,
0x22, 0x82, 0x4b, 0x07, 0xa1, 0x19, 0x1c, 0x9c, 0xe4, 0x04, 0x07, 0xb7, 0x34, 0x3d, 0xd3, 0x40, 0x50, 0x13, 0x11, 0x5c, 0x3a, 0x08, 0xc9, 0x20, 0x8e, 0x12, 0xc5, 0xc1, 0x2d, 0x4d, 0xcf, 0x6b,
0xda, 0x0b, 0x77, 0x17, 0xa4, 0xff, 0xc4, 0x51, 0xff, 0x89, 0x63, 0xc7, 0xce, 0x0e, 0x45, 0x5a, 0x20, 0xed, 0x85, 0xbb, 0x0b, 0xd2, 0xff, 0xc4, 0x51, 0xff, 0x13, 0xc7, 0x8e, 0x9d, 0x1d, 0x4a,
0xf0, 0x47, 0x38, 0xc9, 0x5d, 0x6a, 0x1b, 0x85, 0xba, 0xbd, 0xef, 0x7d, 0xdf, 0x7b, 0xdf, 0xbd, 0x69, 0xff, 0x0b, 0x27, 0xb9, 0x4b, 0xb1, 0x51, 0xa8, 0xdb, 0xfb, 0xde, 0xf7, 0x7d, 0xef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@@ import (
func (pa PermArgs) String() string { func (pa PermArgs) String() string {
body := make([]string, 0, 5) body := make([]string, 0, 5)
body = append(body, fmt.Sprintf("PermFlag: %v", String(pa.PermFlag))) body = append(body, fmt.Sprintf("PermFlag: %v", String(pa.Action)))
if pa.Address != nil { if pa.Target != nil {
body = append(body, fmt.Sprintf("Address: %s", *pa.Address)) body = append(body, fmt.Sprintf("Address: %s", *pa.Target))
} }
if pa.Permission != nil { if pa.Permission != nil {
body = append(body, fmt.Sprintf("Permission: %v", String(*pa.Permission))) body = append(body, fmt.Sprintf("Permission: %v", String(*pa.Permission)))
...@@ -43,9 +43,9 @@ func (pa PermArgs) String() string { ...@@ -43,9 +43,9 @@ func (pa PermArgs) String() string {
} }
func (pa PermArgs) EnsureValid() error { func (pa PermArgs) EnsureValid() error {
pf := pa.PermFlag pf := pa.Action
// Address // Address
if pa.Address == nil && pf != SetGlobal { if pa.Target == nil && pf != SetGlobal {
return fmt.Errorf("PermArgs for PermFlag %v requires Address to be provided but was nil", pf) return fmt.Errorf("PermArgs for PermFlag %v requires Address to be provided but was nil", pf)
} }
if pf == HasRole || pf == AddRole || pf == RemoveRole { if pf == HasRole || pf == AddRole || pf == RemoveRole {
...@@ -65,16 +65,16 @@ func (pa PermArgs) EnsureValid() error { ...@@ -65,16 +65,16 @@ func (pa PermArgs) EnsureValid() error {
func HasBaseArgs(address crypto.Address, permFlag PermFlag) PermArgs { func HasBaseArgs(address crypto.Address, permFlag PermFlag) PermArgs {
return PermArgs{ return PermArgs{
PermFlag: HasBase, Action: HasBase,
Address: &address, Target: &address,
Permission: &permFlag, Permission: &permFlag,
} }
} }
func SetBaseArgs(address crypto.Address, permFlag PermFlag, value bool) PermArgs { func SetBaseArgs(address crypto.Address, permFlag PermFlag, value bool) PermArgs {
return PermArgs{ return PermArgs{
PermFlag: SetBase, Action: SetBase,
Address: &address, Target: &address,
Permission: &permFlag, Permission: &permFlag,
Value: &value, Value: &value,
} }
...@@ -82,15 +82,15 @@ func SetBaseArgs(address crypto.Address, permFlag PermFlag, value bool) PermArgs ...@@ -82,15 +82,15 @@ func SetBaseArgs(address crypto.Address, permFlag PermFlag, value bool) PermArgs
func UnsetBaseArgs(address crypto.Address, permFlag PermFlag) PermArgs { func UnsetBaseArgs(address crypto.Address, permFlag PermFlag) PermArgs {
return PermArgs{ return PermArgs{
PermFlag: UnsetBase, Action: UnsetBase,
Address: &address, Target: &address,
Permission: &permFlag, Permission: &permFlag,
} }
} }
func SetGlobalArgs(permFlag PermFlag, value bool) PermArgs { func SetGlobalArgs(permFlag PermFlag, value bool) PermArgs {
return PermArgs{ return PermArgs{
PermFlag: SetGlobal, Action: SetGlobal,
Permission: &permFlag, Permission: &permFlag,
Value: &value, Value: &value,
} }
...@@ -98,24 +98,24 @@ func SetGlobalArgs(permFlag PermFlag, value bool) PermArgs { ...@@ -98,24 +98,24 @@ func SetGlobalArgs(permFlag PermFlag, value bool) PermArgs {
func HasRoleArgs(address crypto.Address, role string) PermArgs { func HasRoleArgs(address crypto.Address, role string) PermArgs {
return PermArgs{ return PermArgs{
PermFlag: HasRole, Action: HasRole,
Address: &address, Target: &address,
Role: &role, Role: &role,
} }
} }
func AddRoleArgs(address crypto.Address, role string) PermArgs { func AddRoleArgs(address crypto.Address, role string) PermArgs {
return PermArgs{ return PermArgs{
PermFlag: AddRole, Action: AddRole,
Address: &address, Target: &address,
Role: &role, Role: &role,
} }
} }
func RemoveRoleArgs(address crypto.Address, role string) PermArgs { func RemoveRoleArgs(address crypto.Address, role string) PermArgs {
return PermArgs{ return PermArgs{
PermFlag: RemoveRole, Action: RemoveRole,
Address: &address, Target: &address,
Role: &role, Role: &role,
} }
} }
...@@ -31,8 +31,11 @@ message BasePermissions { ...@@ -31,8 +31,11 @@ message BasePermissions {
message PermArgs { message PermArgs {
option (gogoproto.goproto_unrecognized) = false; option (gogoproto.goproto_unrecognized) = false;
option (gogoproto.goproto_stringer) = false; option (gogoproto.goproto_stringer) = false;
optional uint64 PermFlag = 1 [(gogoproto.casttype) = "PermFlag", (gogoproto.nullable) = false]; // The permission function
optional bytes Address = 2 [(gogoproto.customtype) = "github.com/hyperledger/burrow/crypto.Address"]; optional uint64 Action = 1 [(gogoproto.casttype) = "PermFlag", (gogoproto.nullable) = false];
// The target of the action
optional bytes Target = 2 [(gogoproto.customtype) = "github.com/hyperledger/burrow/crypto.Address"];
// Possible arguments
optional uint64 Permission = 3 [(gogoproto.casttype) = "PermFlag"]; optional uint64 Permission = 3 [(gogoproto.casttype) = "PermFlag"];
optional string Role = 4; optional string Role = 4;
optional bool Value = 5; optional bool Value = 5;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment