-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refact: add permssion check 1. go-jsonrpc support field reflect 2. go-ipfs-cmds support auth check in hanlder 3. venus client support dynamically specifies whether to expose to external calls 4. venus client code can generate by tools
- Loading branch information
Showing
117 changed files
with
2,393 additions
and
1,617 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 was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,71 @@ | ||
package funcrule | ||
|
||
import ( | ||
"context" | ||
"github.com/filecoin-project/go-jsonrpc/auth" | ||
"golang.org/x/xerrors" | ||
"reflect" | ||
) | ||
|
||
type MethodName = string | ||
|
||
// Rule[perm:admin,ignore:true] | ||
// Used by Client to generate rule comments | ||
type Rule struct { | ||
Perm auth.Permission | ||
Ignore bool | ||
} | ||
|
||
var AllPermissions = []auth.Permission{"read", "write", "sign", "admin"} | ||
var defaultPerms = []auth.Permission{"read"} | ||
|
||
func defaultRule() *Rule { | ||
return &Rule{ | ||
Perm: "read", | ||
} | ||
} | ||
|
||
//permissionVerify the scheduler between API and internal business | ||
func PermissionProxy(in interface{}, out interface{}) { | ||
ra := reflect.ValueOf(in) | ||
rint := reflect.ValueOf(out).Elem() | ||
for i := 0; i < ra.NumMethod(); i++ { | ||
methodName := ra.Type().Method(i).Name | ||
field, exists := rint.Type().FieldByName(methodName) | ||
if !exists { | ||
//log.Printf("exclude method %s from fullNode", methodName) | ||
continue | ||
} | ||
|
||
requiredPerm := field.Tag.Get("perm") | ||
if requiredPerm == "" { | ||
panic("missing 'perm' tag on " + field.Name) // ok | ||
} | ||
curule := defaultRule() | ||
curule.Perm = requiredPerm | ||
|
||
fn := ra.Method(i) | ||
rint.FieldByName(methodName).Set(reflect.MakeFunc(field.Type, func(args []reflect.Value) (results []reflect.Value) { | ||
ctx := args[0].Interface().(context.Context) | ||
errNum := 0 | ||
if !auth.HasPerm(ctx, defaultPerms, curule.Perm) { | ||
errNum++ | ||
goto ABORT | ||
} | ||
return fn.Call(args) | ||
ABORT: | ||
err := xerrors.Errorf("missing permission to invoke '%s'", methodName) | ||
if errNum&1 == 1 { | ||
err = xerrors.Errorf("%s (need '%s')", err, curule.Perm) | ||
} | ||
rerr := reflect.ValueOf(&err).Elem() | ||
if fn.Type().NumOut() == 2 { | ||
return []reflect.Value{ | ||
reflect.Zero(fn.Type().Out(0)), | ||
rerr, | ||
} | ||
} | ||
return []reflect.Value{rerr} | ||
})) | ||
} | ||
} |
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
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
Oops, something went wrong.