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