Skip to content

Commit

Permalink
Future implementation for passing app in eos-grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Mar 7, 2024
1 parent 848fd71 commit f2854e1
Showing 1 changed file with 23 additions and 27 deletions.
50 changes: 23 additions & 27 deletions pkg/eosclient/eosgrpc/eosgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (c *Client) getRespError(rsp *erpc.NSResponse, err error) error {
}

// Common code to create and initialize a NSRequest.
func (c *Client) initNSRequest(ctx context.Context, auth eosclient.Authorization) (*erpc.NSRequest, error) {
func (c *Client) initNSRequest(ctx context.Context, auth eosclient.Authorization, app string) (*erpc.NSRequest, error) {
// Stuff filename, uid, gid into the MDRequest type

log := appctx.GetLogger(ctx)
Expand All @@ -223,12 +223,15 @@ func (c *Client) initNSRequest(ctx context.Context, auth eosclient.Authorization
}
rq.Role.Uid = uidInt
rq.Role.Gid = gidInt
if app != "" {
rq.Role.Groupname = app // FIXME this is going to be rq.Role.App once the GRPC interface is updated
}
rq.Authkey = c.opt.Authkey

return rq, nil
}

// Common code to create and initialize a NSRequest.
// Common code to create and initialize a MDRequest.
func (c *Client) initMDRequest(ctx context.Context, auth eosclient.Authorization) (*erpc.MDRequest, error) {
// Stuff filename, uid, gid into the MDRequest type

Expand Down Expand Up @@ -260,7 +263,7 @@ func (c *Client) AddACL(ctx context.Context, auth, rootAuth eosclient.Authorizat
log.Info().Str("func", "AddACL").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")

// Init a new NSRequest
rq, err := c.initNSRequest(ctx, rootAuth)
rq, err := c.initNSRequest(ctx, rootAuth, "")
if err != nil {
return err
}
Expand Down Expand Up @@ -311,7 +314,7 @@ func (c *Client) RemoveACL(ctx context.Context, auth, rootAuth eosclient.Authori
sysACL := acls.Serialize()

// Init a new NSRequest
rq, err := c.initNSRequest(ctx, auth)
rq, err := c.initNSRequest(ctx, auth, "")
if err != nil {
return err
}
Expand Down Expand Up @@ -388,7 +391,7 @@ func (c *Client) getACLForPath(ctx context.Context, auth eosclient.Authorization
log.Info().Str("func", "GetACLForPath").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, auth)
rq, err := c.initNSRequest(ctx, auth, "")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -512,7 +515,7 @@ func (c *Client) SetAttr(ctx context.Context, auth eosclient.Authorization, attr
log.Info().Str("func", "SetAttr").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, auth)
rq, err := c.initNSRequest(ctx, auth, app)
if err != nil {
return err
}
Expand All @@ -531,9 +534,6 @@ func (c *Client) SetAttr(ctx context.Context, auth eosclient.Authorization, attr
}

rq.Command = &erpc.NSRequest_Xattr{Xattr: msg}
// if app != "" {
// rq.Header.Set("app", app)
// }

// Now send the req and see what happens
resp, err := c.cl.Exec(appctx.ContextGetClean(ctx), rq)
Expand Down Expand Up @@ -565,7 +565,7 @@ func (c *Client) UnsetAttr(ctx context.Context, auth eosclient.Authorization, at
log.Info().Str("func", "UnsetAttr").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, auth)
rq, err := c.initNSRequest(ctx, auth, app)
if err != nil {
return err
}
Expand All @@ -575,14 +575,10 @@ func (c *Client) UnsetAttr(ctx context.Context, auth eosclient.Authorization, at
var ktd = []string{attr.GetKey()}
msg.Keystodelete = ktd
msg.Recursive = recursive

msg.Id = new(erpc.MDId)
msg.Id.Path = []byte(path)

rq.Command = &erpc.NSRequest_Xattr{Xattr: msg}
// if app != "" {
// rq.Header.Set("app", app)
// }

// Now send the req and see what happens
resp, err := c.cl.Exec(appctx.ContextGetClean(ctx), rq)
Expand Down Expand Up @@ -731,7 +727,7 @@ func (c *Client) GetQuota(ctx context.Context, username string, rootAuth eosclie
log.Info().Str("func", "GetQuota").Str("rootuid,rootgid", rootAuth.Role.UID+","+rootAuth.Role.GID).Str("username", username).Str("path", path).Msg("")

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, rootAuth)
rq, err := c.initNSRequest(ctx, rootAuth, "")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -807,7 +803,7 @@ func (c *Client) SetQuota(ctx context.Context, rootAuth eosclient.Authorization,
// return errtypes.NotSupported("eosgrpc: SetQuota not implemented")

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, rootAuth)
rq, err := c.initNSRequest(ctx, rootAuth, "")
if err != nil {
return err
}
Expand Down Expand Up @@ -865,7 +861,7 @@ func (c *Client) Touch(ctx context.Context, auth eosclient.Authorization, path s
log.Info().Str("func", "Touch").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, auth)
rq, err := c.initNSRequest(ctx, auth, "")
if err != nil {
return err
}
Expand Down Expand Up @@ -900,7 +896,7 @@ func (c *Client) Chown(ctx context.Context, auth, chownAuth eosclient.Authorizat
log.Info().Str("func", "Chown").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("chownuid,chowngid", chownAuth.Role.UID+","+chownAuth.Role.GID).Str("path", path).Msg("")

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, auth)
rq, err := c.initNSRequest(ctx, auth, "")
if err != nil {
return err
}
Expand Down Expand Up @@ -944,7 +940,7 @@ func (c *Client) Chmod(ctx context.Context, auth eosclient.Authorization, mode,
log.Info().Str("func", "Chmod").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("mode", mode).Str("path", path).Msg("")

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, auth)
rq, err := c.initNSRequest(ctx, auth, "")
if err != nil {
return err
}
Expand Down Expand Up @@ -985,7 +981,7 @@ func (c *Client) CreateDir(ctx context.Context, auth eosclient.Authorization, pa
log.Info().Str("func", "Createdir").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, auth)
rq, err := c.initNSRequest(ctx, auth, "")
if err != nil {
return err
}
Expand Down Expand Up @@ -1026,7 +1022,7 @@ func (c *Client) rm(ctx context.Context, auth eosclient.Authorization, path stri
log.Info().Str("func", "rm").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, auth)
rq, err := c.initNSRequest(ctx, auth, "")
if err != nil {
return err
}
Expand Down Expand Up @@ -1061,7 +1057,7 @@ func (c *Client) rmdir(ctx context.Context, auth eosclient.Authorization, path s
log.Info().Str("func", "rmdir").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, auth)
rq, err := c.initNSRequest(ctx, auth, "")
if err != nil {
return err
}
Expand Down Expand Up @@ -1116,7 +1112,7 @@ func (c *Client) Rename(ctx context.Context, auth eosclient.Authorization, oldPa
log.Info().Str("func", "Rename").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("oldPath", oldPath).Str("newPath", newPath).Msg("")

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, auth)
rq, err := c.initNSRequest(ctx, auth, "")
if err != nil {
return err
}
Expand Down Expand Up @@ -1387,7 +1383,7 @@ func (c *Client) ListDeletedEntries(ctx context.Context, auth eosclient.Authoriz
log.Info().Str("func", "ListDeletedEntries").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Msg("")

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, auth)
rq, err := c.initNSRequest(ctx, auth, "")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1455,7 +1451,7 @@ func (c *Client) RestoreDeletedEntry(ctx context.Context, auth eosclient.Authori
log.Info().Str("func", "RestoreDeletedEntries").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("key", key).Msg("")

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, auth)
rq, err := c.initNSRequest(ctx, auth, "")
if err != nil {
return err
}
Expand Down Expand Up @@ -1493,7 +1489,7 @@ func (c *Client) PurgeDeletedEntries(ctx context.Context, auth eosclient.Authori
log.Info().Str("func", "PurgeDeletedEntries").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Msg("")

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, auth)
rq, err := c.initNSRequest(ctx, auth, "")
if err != nil {
return err
}
Expand Down Expand Up @@ -1540,7 +1536,7 @@ func (c *Client) RollbackToVersion(ctx context.Context, auth eosclient.Authoriza
log.Info().Str("func", "RollbackToVersion").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Str("version", version).Msg("")

// Initialize the common fields of the NSReq
rq, err := c.initNSRequest(ctx, auth)
rq, err := c.initNSRequest(ctx, auth, "")
if err != nil {
return err
}
Expand Down

0 comments on commit f2854e1

Please sign in to comment.