Skip to content

Commit

Permalink
propagate X-Disable-Versioning header through call chain
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Geens committed Sep 17, 2024
1 parent 122da0b commit 4653ae5
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 10 deletions.
7 changes: 7 additions & 0 deletions internal/http/services/owncloud/ocdav/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ func (s *svc) handlePut(ctx context.Context, w http.ResponseWriter, r *http.Requ
httpReq.Header.Set(HeaderLockHolder, lockholder)
}

// Propagate X-Disable-Versioning header
// Used to disable versioning for applications that do not expect this behaviour
// See CERNBOX-3610
if disableVersioning := r.Header.Get(HeaderDisableVersioning); disableVersioning != "" {
httpReq.Header.Set(HeaderDisableVersioning, strconv.FormatBool(true))
}

httpRes, err := s.client.Do(httpReq)
if err != nil {
log.Error().Err(err).Msg("error doing PUT request to data service")
Expand Down
1 change: 1 addition & 0 deletions internal/http/services/owncloud/ocdav/webdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const (
HeaderTransferAuth = "TransferHeaderAuthorization"
HeaderLockID = "X-Lock-Id"
HeaderLockHolder = "X-Lock-Holder"
HeaderDisableVersioning = "X-Disable-Versioning"
)

// WebDavHandler implements a dav endpoint.
Expand Down
9 changes: 6 additions & 3 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ func (c *Client) Read(ctx context.Context, auth eosclient.Authorization, path st
}

// Write writes a stream to the mgm.
func (c *Client) Write(ctx context.Context, auth eosclient.Authorization, path string, stream io.ReadCloser, app string) error {
func (c *Client) Write(ctx context.Context, auth eosclient.Authorization, path string, stream io.ReadCloser, app string, disableVersioning bool) error {
fd, err := os.CreateTemp(c.opt.CacheDirectory, "eoswrite-")
if err != nil {
return err
Expand All @@ -736,18 +736,21 @@ func (c *Client) Write(ctx context.Context, auth eosclient.Authorization, path s
if err != nil {
return err
}
return c.writeFile(ctx, auth, path, fd.Name(), app)
return c.writeFile(ctx, auth, path, fd.Name(), app, disableVersioning)
}

// WriteFile writes an existing file to the mgm.
func (c *Client) writeFile(ctx context.Context, auth eosclient.Authorization, path, source, app string) error {
func (c *Client) writeFile(ctx context.Context, auth eosclient.Authorization, path, source, app string, disableVersioning bool) error {
xrdPath := fmt.Sprintf("%s//%s", c.opt.URL, path)
args := []string{"--nopbar", "--silent", "-f", source, xrdPath}

if auth.Token != "" {
args[4] += "?authz=" + auth.Token
} else if auth.Role.UID != "" && auth.Role.GID != "" {
args = append(args, fmt.Sprintf("-ODeos.ruid=%s&eos.rgid=%s&eos.app=%s", auth.Role.UID, auth.Role.GID, app))
if disableVersioning {
args = append(args, "&eos.versioning=0")
}
}

_, _, err := c.executeXRDCopy(ctx, args)
Expand Down
2 changes: 1 addition & 1 deletion pkg/eosclient/eosclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type EOSClient interface {
Rename(ctx context.Context, auth Authorization, oldPath, newPath string) error
List(ctx context.Context, auth Authorization, path string) ([]*FileInfo, error)
Read(ctx context.Context, auth Authorization, path string) (io.ReadCloser, error)
Write(ctx context.Context, auth Authorization, path string, stream io.ReadCloser, app string) error
Write(ctx context.Context, auth Authorization, path string, stream io.ReadCloser, app string, disableVersioning bool) error
ListDeletedEntries(ctx context.Context, auth Authorization, maxentries int, from, to time.Time) ([]*DeletedEntry, error)
RestoreDeletedEntry(ctx context.Context, auth Authorization, key string) error
PurgeDeletedEntries(ctx context.Context, auth Authorization) error
Expand Down
6 changes: 3 additions & 3 deletions pkg/eosclient/eosgrpc/eosgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ func (c *Client) Read(ctx context.Context, auth eosclient.Authorization, path st

// Write writes a file to the mgm
// Somehow the same considerations as Read apply.
func (c *Client) Write(ctx context.Context, auth eosclient.Authorization, path string, stream io.ReadCloser, app string) error {
func (c *Client) Write(ctx context.Context, auth eosclient.Authorization, path string, stream io.ReadCloser, app string, disableVersioning bool) error {
log := appctx.GetLogger(ctx)
log.Info().Str("func", "Write").Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", path).Msg("")
var length int64
Expand Down Expand Up @@ -1354,10 +1354,10 @@ func (c *Client) Write(ctx context.Context, auth eosclient.Authorization, path s
defer wfd.Close()
defer os.RemoveAll(fd.Name())

return c.httpcl.PUTFile(ctx, u.Username, auth, path, wfd, length, app)
return c.httpcl.PUTFile(ctx, u.Username, auth, path, wfd, length, app, disableVersioning)
}

return c.httpcl.PUTFile(ctx, u.Username, auth, path, stream, length, app)
return c.httpcl.PUTFile(ctx, u.Username, auth, path, stream, length, app, disableVersioning)
}

// ListDeletedEntries returns a list of the deleted entries.
Expand Down
12 changes: 10 additions & 2 deletions pkg/eosclient/eosgrpc/eoshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,20 @@ func (c *EOSHTTPClient) GETFile(ctx context.Context, remoteuser string, auth eos
}

// PUTFile does an entire PUT to upload a full file, taking the data from a stream.
func (c *EOSHTTPClient) PUTFile(ctx context.Context, remoteuser string, auth eosclient.Authorization, urlpath string, stream io.ReadCloser, length int64, app string) error {
func (c *EOSHTTPClient) PUTFile(ctx context.Context, remoteuser string, auth eosclient.Authorization, urlpath string, stream io.ReadCloser, length int64, app string, disableVersioning bool) error {
log := appctx.GetLogger(ctx)
log.Info().Str("func", "PUTFile").Str("remoteuser", remoteuser).Str("uid,gid", auth.Role.UID+","+auth.Role.GID).Str("path", urlpath).Int64("length", length).Str("app", app).Msg("")

// Now send the req and see what happens
finalurl, err := c.buildFullURL(urlpath, auth)
tempUrl, err := c.buildFullURL(urlpath, auth)
parsedUrl, err := url.Parse(tempUrl)
queryValues := parsedUrl.Query()

if disableVersioning {
queryValues.Add("eos.versioning", strconv.Itoa(0))
}
finalurl := queryValues.Encode()

if err != nil {
log.Error().Str("func", "PUTFile").Str("url", finalurl).Str("err", err.Error()).Msg("can't create request")
return err
Expand Down
4 changes: 4 additions & 0 deletions pkg/rhttp/datatx/manager/simple/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func (m *manager) Handler(fs storage.FS) (http.Handler, error) {
metadata["lockholder"] = lockholder
}

if disableVersioning := r.Header.Get(ocdav.HeaderDisableVersioning); disableVersioning != "" {
metadata["disableVersioning"] = disableVersioning
}

err := fs.Upload(ctx, ref, r.Body, metadata)
switch v := err.(type) {
case nil:
Expand Down
9 changes: 8 additions & 1 deletion pkg/storage/utils/eosfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io"
"os"
"path"
"strconv"

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/errtypes"
Expand Down Expand Up @@ -86,7 +87,13 @@ func (fs *eosfs) Upload(ctx context.Context, ref *provider.Reference, r io.ReadC
// if we have a lock context, the app for EOS must match the lock holder
app = fs.EncodeAppName(app)
}
return fs.c.Write(ctx, auth, fn, r, app)

disableVersioning, err := strconv.ParseBool(metadata["disableVersioning"])
if err != nil {
disableVersioning = false
}

return fs.c.Write(ctx, auth, fn, r, app, disableVersioning)
}

func (fs *eosfs) InitiateUpload(ctx context.Context, ref *provider.Reference, uploadLength int64, metadata map[string]string) (map[string]string, error) {
Expand Down

0 comments on commit 4653ae5

Please sign in to comment.