github.com/celestiaorg/celestia-node@v0.15.0-beta.1/nodebuilder/node/admin.go (about) 1 package node 2 3 import ( 4 "context" 5 6 "github.com/cristalhq/jwt" 7 "github.com/filecoin-project/go-jsonrpc/auth" 8 logging "github.com/ipfs/go-log/v2" 9 10 "github.com/celestiaorg/celestia-node/libs/authtoken" 11 ) 12 13 const APIVersion = "v0.11.0" 14 15 type module struct { 16 tp Type 17 signer jwt.Signer 18 } 19 20 func newModule(tp Type, signer jwt.Signer) Module { 21 return &module{ 22 tp: tp, 23 signer: signer, 24 } 25 } 26 27 // Info contains information related to the administrative 28 // node. 29 type Info struct { 30 Type Type `json:"type"` 31 APIVersion string `json:"api_version"` 32 } 33 34 func (m *module) Info(context.Context) (Info, error) { 35 return Info{ 36 Type: m.tp, 37 APIVersion: APIVersion, 38 }, nil 39 } 40 41 func (m *module) Ready(context.Context) (bool, error) { 42 // Because the node uses FX to provide the RPC last, all services' lifecycles have been started by 43 // the point this endpoint is available. It is not 100% guaranteed at this point that all services 44 // are fully ready, but it is very high probability and all endpoints are available at this point 45 // regardless. 46 return true, nil 47 } 48 49 func (m *module) LogLevelSet(_ context.Context, name, level string) error { 50 return logging.SetLogLevel(name, level) 51 } 52 53 func (m *module) AuthVerify(_ context.Context, token string) ([]auth.Permission, error) { 54 return authtoken.ExtractSignedPermissions(m.signer, token) 55 } 56 57 func (m *module) AuthNew(_ context.Context, permissions []auth.Permission) (string, error) { 58 return authtoken.NewSignedJWT(m.signer, permissions) 59 }