@@ -1603,7 +1603,50 @@ func (c *Client) ReadVersion(ctx context.Context, auth eosclient.Authorization,
1603
1603
1604
1604
// GenerateToken returns a token on behalf of the resource owner to be used by lightweight accounts.
1605
1605
func (c * Client ) GenerateToken (ctx context.Context , auth eosclient.Authorization , path string , a * acl.Entry ) (string , error ) {
1606
- return "" , errtypes .NotSupported ("TODO" )
1606
+ log := appctx .GetLogger (ctx )
1607
+ log .Info ().Str ("func" , "GenerateToken" ).Str ("uid,gid" , auth .Role .UID + "," + auth .Role .GID ).Str ("path" , path ).Msg ("" )
1608
+
1609
+ // Initialize the common fields of the NSReq
1610
+ rq , err := c .initNSRequest (ctx , auth , "" )
1611
+ if err != nil {
1612
+ log .Error ().Str ("func" , "GenerateToken" ).Str ("err" , err .Error ()).Msg ("Error on initNSRequest" )
1613
+ return "" , err
1614
+ }
1615
+
1616
+ msg := new (erpc.NSRequest_TokenRequest )
1617
+ msg .Token = & erpc.ShareToken {}
1618
+ msg .Token .Token = & erpc.ShareProto {}
1619
+ msg .Token .Token .Permission = a .Permissions
1620
+ // TODO(jgeens): right now hardcoded to 3600, but in binary client this was set to c.opt.TokenExpiry
1621
+ msg .Token .Token .Expires = uint64 (time .Now ().Add (time .Duration (3600 ) * time .Second ).Unix ())
1622
+ msg .Token .Token .Allowtree = true
1623
+ msg .Token .Token .Path = path
1624
+
1625
+ rq .Command = & erpc.NSRequest_Token {
1626
+ Token : msg ,
1627
+ }
1628
+
1629
+ // Now send the req and see what happens
1630
+ resp , err := c .cl .Exec (appctx .ContextGetClean (ctx ), rq )
1631
+ e := c .getRespError (resp , err )
1632
+ if e != nil {
1633
+ log .Error ().Str ("func" , "GenerateToken" ).Str ("err" , e .Error ()).Msg ("" )
1634
+ return "" , e
1635
+ }
1636
+
1637
+ if resp == nil {
1638
+ log .Error ().Str ("func" , "GenerateToken" ).Msg ("nil grpc response" )
1639
+ return "" , errtypes .InternalError (fmt .Sprintf ("nil response for uid: '%s' " , auth .Role .UID ))
1640
+ }
1641
+
1642
+ // For some reason, the token is embedded in the error, with error code 0
1643
+ if resp .GetError () != nil {
1644
+ if resp .GetError ().Code == 0 {
1645
+ return resp .GetError ().Msg , nil
1646
+ }
1647
+ }
1648
+ log .Error ().Str ("func" , "GenerateToken" ).Msg ("GenerateToken over gRPC expected an error but did not receive one" )
1649
+ return "" , err
1607
1650
}
1608
1651
1609
1652
func (c * Client ) getVersionFolderInode (ctx context.Context , auth eosclient.Authorization , p string ) (uint64 , error ) {
0 commit comments