github.com/celestiaorg/celestia-node@v0.15.0-beta.1/nodebuilder/node/node.go (about) 1 package node 2 3 import ( 4 "context" 5 6 "github.com/filecoin-project/go-jsonrpc/auth" 7 ) 8 9 // Module defines the API related to interacting with the "administrative" 10 // node. 11 // 12 //go:generate mockgen -destination=mocks/api.go -package=mocks . Module 13 type Module interface { 14 // Info returns administrative information about the node. 15 Info(context.Context) (Info, error) 16 17 // Ready returns true once the node's RPC is ready to accept requests. 18 Ready(context.Context) (bool, error) 19 20 // LogLevelSet sets the given component log level to the given level. 21 LogLevelSet(ctx context.Context, name, level string) error 22 23 // AuthVerify returns the permissions assigned to the given token. 24 AuthVerify(ctx context.Context, token string) ([]auth.Permission, error) 25 // AuthNew signs and returns a new token with the given permissions. 26 AuthNew(ctx context.Context, perms []auth.Permission) (string, error) 27 } 28 29 var _ Module = (*API)(nil) 30 31 type API struct { 32 Internal struct { 33 Info func(context.Context) (Info, error) `perm:"admin"` 34 Ready func(context.Context) (bool, error) `perm:"read"` 35 LogLevelSet func(ctx context.Context, name, level string) error `perm:"admin"` 36 AuthVerify func(ctx context.Context, token string) ([]auth.Permission, error) `perm:"admin"` 37 AuthNew func(ctx context.Context, perms []auth.Permission) (string, error) `perm:"admin"` 38 } 39 } 40 41 func (api *API) Info(ctx context.Context) (Info, error) { 42 return api.Internal.Info(ctx) 43 } 44 45 func (api *API) Ready(ctx context.Context) (bool, error) { 46 return api.Internal.Ready(ctx) 47 } 48 49 func (api *API) LogLevelSet(ctx context.Context, name, level string) error { 50 return api.Internal.LogLevelSet(ctx, name, level) 51 } 52 53 func (api *API) AuthVerify(ctx context.Context, token string) ([]auth.Permission, error) { 54 return api.Internal.AuthVerify(ctx, token) 55 } 56 57 func (api *API) AuthNew(ctx context.Context, perms []auth.Permission) (string, error) { 58 return api.Internal.AuthNew(ctx, perms) 59 }