@@ -125,6 +125,10 @@ type Options struct {
125
125
// SecProtocol is the comma separated list of security protocols used by xrootd.
126
126
// For example: "sss, unix"
127
127
SecProtocol string
128
+
129
+ // TokenExpiry stores in seconds the time after which generated tokens will expire
130
+ // Default is 3600
131
+ TokenExpiry int
128
132
}
129
133
130
134
func getUser (ctx context.Context ) (* userpb.User , error ) {
@@ -1612,7 +1616,49 @@ func (c *Client) ReadVersion(ctx context.Context, auth eosclient.Authorization,
1612
1616
1613
1617
// GenerateToken returns a token on behalf of the resource owner to be used by lightweight accounts.
1614
1618
func (c * Client ) GenerateToken (ctx context.Context , auth eosclient.Authorization , path string , a * acl.Entry ) (string , error ) {
1615
- return "" , errtypes .NotSupported ("TODO" )
1619
+ log := appctx .GetLogger (ctx )
1620
+ log .Info ().Str ("func" , "GenerateToken" ).Str ("uid,gid" , auth .Role .UID + "," + auth .Role .GID ).Str ("path" , path ).Msg ("" )
1621
+
1622
+ // Initialize the common fields of the NSReq
1623
+ rq , err := c .initNSRequest (ctx , auth , "" )
1624
+ if err != nil {
1625
+ log .Error ().Str ("func" , "GenerateToken" ).Str ("err" , err .Error ()).Msg ("Error on initNSRequest" )
1626
+ return "" , err
1627
+ }
1628
+
1629
+ msg := new (erpc.NSRequest_TokenRequest )
1630
+ msg .Token = & erpc.ShareToken {}
1631
+ msg .Token .Token = & erpc.ShareProto {}
1632
+ msg .Token .Token .Permission = a .Permissions
1633
+ msg .Token .Token .Expires = uint64 (time .Now ().Add (time .Duration (c .opt .TokenExpiry ) * time .Second ).Unix ())
1634
+ msg .Token .Token .Allowtree = true
1635
+ msg .Token .Token .Path = path
1636
+
1637
+ rq .Command = & erpc.NSRequest_Token {
1638
+ Token : msg ,
1639
+ }
1640
+
1641
+ // Now send the req and see what happens
1642
+ resp , err := c .cl .Exec (appctx .ContextGetClean (ctx ), rq )
1643
+ e := c .getRespError (resp , err )
1644
+ if e != nil {
1645
+ log .Error ().Str ("func" , "GenerateToken" ).Str ("err" , e .Error ()).Msg ("" )
1646
+ return "" , e
1647
+ }
1648
+
1649
+ if resp == nil {
1650
+ log .Error ().Str ("func" , "GenerateToken" ).Msg ("nil grpc response" )
1651
+ return "" , errtypes .InternalError (fmt .Sprintf ("nil response for uid: '%s' " , auth .Role .UID ))
1652
+ }
1653
+
1654
+ // For some reason, the token is embedded in the error, with error code 0
1655
+ if resp .GetError () != nil {
1656
+ if resp .GetError ().Code == 0 {
1657
+ return resp .GetError ().Msg , nil
1658
+ }
1659
+ }
1660
+ log .Error ().Str ("func" , "GenerateToken" ).Msg ("GenerateToken over gRPC expected an error but did not receive one" )
1661
+ return "" , err
1616
1662
}
1617
1663
1618
1664
func (c * Client ) getVersionFolderInode (ctx context.Context , auth eosclient.Authorization , p string ) (uint64 , error ) {
0 commit comments