From 148c89ec7282ea3647f16208d49cea1eea6a0801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Wed, 12 Jan 2022 08:59:22 +0100 Subject: [PATCH] Fix linter and hound issues --- .../services/owncloud/ocdav/errors/error.go | 5 ++ .../services/owncloud/ocdav/net/context.go | 2 +- .../http/services/owncloud/ocdav/net/net.go | 14 ++-- .../owncloud/ocdav/ocdav_suite_test.go | 18 +++++ .../ocdav/propfind/mocks/GatewayClient.go | 18 +++++ .../owncloud/ocdav/propfind/propfind.go | 66 ++++++++++++------- .../ocdav/propfind/propfind_suite_test.go | 18 +++++ .../owncloud/ocdav/propfind/propfind_test.go | 8 +-- .../services/owncloud/ocdav/props/props.go | 5 +- .../http/services/owncloud/ocdav/report.go | 6 +- .../owncloud/ocdav/spacelookup/spacelookup.go | 4 ++ .../http/services/owncloud/ocdav/spaces.go | 2 +- .../http/services/owncloud/ocdav/trashbin.go | 4 +- .../http/services/owncloud/ocdav/webdav.go | 2 +- 14 files changed, 130 insertions(+), 42 deletions(-) diff --git a/internal/http/services/owncloud/ocdav/errors/error.go b/internal/http/services/owncloud/ocdav/errors/error.go index 3c915e87b7..bb395d2197 100644 --- a/internal/http/services/owncloud/ocdav/errors/error.go +++ b/internal/http/services/owncloud/ocdav/errors/error.go @@ -59,6 +59,7 @@ var ( } ) +// Exception represents a ocdav exception type Exception struct { Code code Message string @@ -80,6 +81,7 @@ func Marshal(code code, message string, header string) ([]byte, error) { return []byte(xml.Header + string(xmlstring)), err } +// ErrorXML holds the xml representation of an error // http://www.webdav.org/specs/rfc4918.html#ELEMENT_error type ErrorXML struct { XMLName xml.Name `xml:"d:error"` @@ -92,7 +94,10 @@ type ErrorXML struct { Header string `xml:"s:header,omitempty"` } +// ErrorInvalidPropfind is an invalid propfind error var ErrorInvalidPropfind = errors.New("webdav: invalid propfind") + +// ErrInvalidProppatch is an invalid proppatch error var ErrInvalidProppatch = errors.New("webdav: invalid proppatch") // HandleErrorStatus checks the status code, logs a Debug or Error level message diff --git a/internal/http/services/owncloud/ocdav/net/context.go b/internal/http/services/owncloud/ocdav/net/context.go index 34d7666950..d3069e8972 100644 --- a/internal/http/services/owncloud/ocdav/net/context.go +++ b/internal/http/services/owncloud/ocdav/net/context.go @@ -25,7 +25,7 @@ import ( ctxpkg "github.com/cs3org/reva/pkg/ctx" ) -// a file is only yours if you are the owner +// IsCurrentUserOwner returns whether the context user is the given owner or not func IsCurrentUserOwner(ctx context.Context, owner *userv1beta1.UserId) bool { contextUser, ok := ctxpkg.ContextGetUser(ctx) if ok && contextUser.Id != nil && owner != nil && diff --git a/internal/http/services/owncloud/ocdav/net/net.go b/internal/http/services/owncloud/ocdav/net/net.go index 2ab17223c4..e5f3ded8dc 100644 --- a/internal/http/services/owncloud/ocdav/net/net.go +++ b/internal/http/services/owncloud/ocdav/net/net.go @@ -27,17 +27,23 @@ import ( type ctxKey int const ( + // CtxKeyBaseURI is the key of the base URI context field CtxKeyBaseURI ctxKey = iota - NsDav = "DAV:" + // NsDav is the Dav ns + NsDav = "DAV:" + // NsOwncloud is the owncloud ns NsOwncloud = "http://owncloud.org/ns" - NsOCS = "http://open-collaboration-services.org/ns" + // NsOCS is the OCS ns + NsOCS = "http://open-collaboration-services.org/ns" // RFC1123 time that mimics oc10. time.RFC1123 would end in "UTC", see https://github.com/golang/go/issues/13781 RFC1123 = "Mon, 02 Jan 2006 15:04:05 GMT" + // PropQuotaUnknown is the quota unknown property PropQuotaUnknown = "-2" - PropOcFavorite = "http://owncloud.org/ns/favorite" + // PropOcFavorite is the favorite ns property + PropOcFavorite = "http://owncloud.org/ns/favorite" ) // replaceAllStringSubmatchFunc is taken from 'Go: Replace String with Regular Expression Callback' @@ -58,7 +64,7 @@ func replaceAllStringSubmatchFunc(re *regexp.Regexp, str string, repl func([]str var hrefre = regexp.MustCompile(`([^A-Za-z0-9_\-.~()/:@!$])`) -// encodePath encodes the path of a url. +// EncodePath encodes the path of a url. // // slashes (/) are treated as path-separators. // ported from https://github.com/sabre-io/http/blob/bb27d1a8c92217b34e778ee09dcf79d9a2936e84/lib/functions.php#L369-L379 diff --git a/internal/http/services/owncloud/ocdav/ocdav_suite_test.go b/internal/http/services/owncloud/ocdav/ocdav_suite_test.go index 043e3962e6..c31853b080 100644 --- a/internal/http/services/owncloud/ocdav/ocdav_suite_test.go +++ b/internal/http/services/owncloud/ocdav/ocdav_suite_test.go @@ -1,3 +1,21 @@ +// Copyright 2018-2021 CERN +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// In applying this license, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + package ocdav_test import ( diff --git a/internal/http/services/owncloud/ocdav/propfind/mocks/GatewayClient.go b/internal/http/services/owncloud/ocdav/propfind/mocks/GatewayClient.go index 45fb1a35d5..9d03625ddb 100644 --- a/internal/http/services/owncloud/ocdav/propfind/mocks/GatewayClient.go +++ b/internal/http/services/owncloud/ocdav/propfind/mocks/GatewayClient.go @@ -1,3 +1,21 @@ +// Copyright 2018-2021 CERN +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// In applying this license, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + // Code generated by mockery v1.0.0. DO NOT EDIT. package mocks diff --git a/internal/http/services/owncloud/ocdav/propfind/propfind.go b/internal/http/services/owncloud/ocdav/propfind/propfind.go index 3b92d42463..7d5a42c7b3 100644 --- a/internal/http/services/owncloud/ocdav/propfind/propfind.go +++ b/internal/http/services/owncloud/ocdav/propfind/propfind.go @@ -63,20 +63,24 @@ type GatewayClient interface { // GetGatewayServiceClientFunc is a callback used to pass in a StorageProviderClient during testing type GetGatewayServiceClientFunc func() (GatewayClient, error) -type PropfindHandler struct { + +// Handler handles propfind requests +type Handler struct { PublicURL string getClient GetGatewayServiceClientFunc } -func NewPropfindHandler(publicURL string, getClientFunc GetGatewayServiceClientFunc) *PropfindHandler { - return &PropfindHandler{ +// NewHandler returns a new PropfindHandler instance +func NewHandler(publicURL string, getClientFunc GetGatewayServiceClientFunc) *Handler { + return &Handler{ PublicURL: publicURL, getClient: getClientFunc, } } +// HandlePathPropfind handles a path based propfind request // ns is the namespace that is prefixed to the path in the cs3 namespace -func (p *PropfindHandler) HandlePathPropfind(w http.ResponseWriter, r *http.Request, ns string) { +func (p *Handler) HandlePathPropfind(w http.ResponseWriter, r *http.Request, ns string) { ctx, span := rtrace.Provider.Tracer("reva").Start(r.Context(), fmt.Sprintf("%s %v", r.Method, r.URL.Path)) defer span.End() @@ -121,7 +125,8 @@ func (p *PropfindHandler) HandlePathPropfind(w http.ResponseWriter, r *http.Requ p.propfindResponse(ctx, w, r, ns, pf, sendTusHeaders, resourceInfos, sublog) } -func (p *PropfindHandler) HandleSpacesPropfind(w http.ResponseWriter, r *http.Request, spaceID string) { +// HandleSpacesPropfind handles a spaces based propfind request +func (p *Handler) HandleSpacesPropfind(w http.ResponseWriter, r *http.Request, spaceID string) { ctx, span := rtrace.Provider.Tracer("ocdav").Start(r.Context(), "spaces_propfind") defer span.End() @@ -142,6 +147,11 @@ func (p *PropfindHandler) HandleSpacesPropfind(w http.ResponseWriter, r *http.Re // retrieve a specific storage space space, rpcStatus, err := spacelookup.LookUpStorageSpaceByID(ctx, client.(gateway.GatewayAPIClient), spaceID) + if err != nil { + sublog.Error().Err(err).Msg("error looking up the space by id") + w.WriteHeader(http.StatusInternalServerError) + return + } if rpcStatus.Code != rpc.Code_CODE_OK { errors.HandleErrorStatus(&sublog, w, rpcStatus) @@ -163,7 +173,7 @@ func (p *PropfindHandler) HandleSpacesPropfind(w http.ResponseWriter, r *http.Re } -func (p *PropfindHandler) propfindResponse(ctx context.Context, w http.ResponseWriter, r *http.Request, namespace string, pf PropfindXML, sendTusHeaders bool, resourceInfos []*provider.ResourceInfo, log zerolog.Logger) { +func (p *Handler) propfindResponse(ctx context.Context, w http.ResponseWriter, r *http.Request, namespace string, pf XML, sendTusHeaders bool, resourceInfos []*provider.ResourceInfo, log zerolog.Logger) { ctx, span := rtrace.Provider.Tracer("ocdav").Start(ctx, "propfind_response") defer span.End() @@ -214,7 +224,7 @@ func (p *PropfindHandler) propfindResponse(ctx context.Context, w http.ResponseW } // TODO this is just a stat -> rename -func (p *PropfindHandler) statSpace(ctx context.Context, client gateway.GatewayAPIClient, space *provider.StorageSpace, ref *provider.Reference, metadataKeys []string) (*provider.ResourceInfo, *rpc.Status, error) { +func (p *Handler) statSpace(ctx context.Context, client gateway.GatewayAPIClient, space *provider.StorageSpace, ref *provider.Reference, metadataKeys []string) (*provider.ResourceInfo, *rpc.Status, error) { req := &provider.StatRequest{ Ref: ref, ArbitraryMetadataKeys: metadataKeys, @@ -226,7 +236,7 @@ func (p *PropfindHandler) statSpace(ctx context.Context, client gateway.GatewayA return res.Info, res.Status, nil } -func (p *PropfindHandler) getResourceInfos(ctx context.Context, w http.ResponseWriter, r *http.Request, pf PropfindXML, spaces []*provider.StorageSpace, requestPath string, spacesPropfind bool, log zerolog.Logger) ([]*provider.ResourceInfo, bool, bool) { +func (p *Handler) getResourceInfos(ctx context.Context, w http.ResponseWriter, r *http.Request, pf XML, spaces []*provider.StorageSpace, requestPath string, spacesPropfind bool, log zerolog.Logger) ([]*provider.ResourceInfo, bool, bool) { depth := r.Header.Get(net.HeaderDepth) if depth == "" { depth = "1" @@ -503,38 +513,40 @@ func requiresExplicitFetching(n *xml.Name) bool { return true } +// ReadPropfind extracts and parses the propfind XML information from a Reader // from https://github.com/golang/net/blob/e514e69ffb8bc3c76a71ae40de0118d794855992/webdav/xml.go#L178-L205 -func ReadPropfind(r io.Reader) (pf PropfindXML, status int, err error) { +func ReadPropfind(r io.Reader) (pf XML, status int, err error) { c := countingReader{r: r} if err = xml.NewDecoder(&c).Decode(&pf); err != nil { if err == io.EOF { if c.n == 0 { // An empty body means to propfind allprop. // http://www.webdav.org/specs/rfc4918.html#METHOD_PROPFIND - return PropfindXML{Allprop: new(struct{})}, 0, nil + return XML{Allprop: new(struct{})}, 0, nil } err = errors.ErrorInvalidPropfind } - return PropfindXML{}, http.StatusBadRequest, err + return XML{}, http.StatusBadRequest, err } if pf.Allprop == nil && pf.Include != nil { - return PropfindXML{}, http.StatusBadRequest, errors.ErrorInvalidPropfind + return XML{}, http.StatusBadRequest, errors.ErrorInvalidPropfind } if pf.Allprop != nil && (pf.Prop != nil || pf.Propname != nil) { - return PropfindXML{}, http.StatusBadRequest, errors.ErrorInvalidPropfind + return XML{}, http.StatusBadRequest, errors.ErrorInvalidPropfind } if pf.Prop != nil && pf.Propname != nil { - return PropfindXML{}, http.StatusBadRequest, errors.ErrorInvalidPropfind + return XML{}, http.StatusBadRequest, errors.ErrorInvalidPropfind } if pf.Propname == nil && pf.Allprop == nil && pf.Prop == nil { // jfd: I think is perfectly valid ... treat it as allprop - return PropfindXML{Allprop: new(struct{})}, 0, nil + return XML{Allprop: new(struct{})}, 0, nil } return pf, 0, nil } -func MultistatusResponse(ctx context.Context, pf *PropfindXML, mds []*provider.ResourceInfo, publicURL, ns string, linkshares map[string]struct{}) (string, error) { +// MultistatusResponse converts a list of resource infos into a multistatus response string +func MultistatusResponse(ctx context.Context, pf *XML, mds []*provider.ResourceInfo, publicURL, ns string, linkshares map[string]struct{}) (string, error) { responses := make([]*ResponseXML, 0, len(mds)) for i := range mds { res, err := mdToPropResponse(ctx, pf, mds[i], publicURL, ns, linkshares) @@ -557,7 +569,7 @@ func MultistatusResponse(ctx context.Context, pf *PropfindXML, mds []*provider.R // mdToPropResponse converts the CS3 metadata into a webdav PropResponse // ns is the CS3 namespace that needs to be removed from the CS3 path before // prefixing it with the baseURI -func mdToPropResponse(ctx context.Context, pf *PropfindXML, md *provider.ResourceInfo, publicURL, ns string, linkshares map[string]struct{}) (*ResponseXML, error) { +func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, publicURL, ns string, linkshares map[string]struct{}) (*ResponseXML, error) { sublog := appctx.GetLogger(ctx).With().Interface("md", md).Str("ns", ns).Logger() md.Path = strings.TrimPrefix(md.Path, ns) @@ -1090,14 +1102,15 @@ func metadataKeyOf(n *xml.Name) string { } } +// Props represents properties related to a resource // http://www.webdav.org/specs/rfc4918.html#ELEMENT_prop (for propfind) -type PropfindProps []xml.Name +type Props []xml.Name // UnmarshalXML appends the property names enclosed within start to pn. // // It returns an error if start does not contain any properties or if // properties contain values. Character data between properties is ignored. -func (pn *PropfindProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { +func (pn *Props) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { for { t, err := props.Next(d) if err != nil { @@ -1125,15 +1138,17 @@ func (pn *PropfindProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) er } } +// XML holds the xml representation of a propfind // http://www.webdav.org/specs/rfc4918.html#ELEMENT_propfind -type PropfindXML struct { - XMLName xml.Name `xml:"DAV: propfind"` - Allprop *struct{} `xml:"DAV: allprop"` - Propname *struct{} `xml:"DAV: propname"` - Prop PropfindProps `xml:"DAV: prop"` - Include PropfindProps `xml:"DAV: include"` +type XML struct { + XMLName xml.Name `xml:"DAV: propfind"` + Allprop *struct{} `xml:"DAV: allprop"` + Propname *struct{} `xml:"DAV: propname"` + Prop Props `xml:"DAV: prop"` + Include Props `xml:"DAV: include"` } +// ResponseXML holds the xml representation of a propfind response type ResponseXML struct { XMLName xml.Name `xml:"d:response"` Href string `xml:"d:href"` @@ -1143,6 +1158,7 @@ type ResponseXML struct { ResponseDescription string `xml:"d:responsedescription,omitempty"` } +// PropstatXML holds the xml representation of a propfind response // http://www.webdav.org/specs/rfc4918.html#ELEMENT_propstat type PropstatXML struct { // Prop requires DAV: to be the default namespace in the enclosing diff --git a/internal/http/services/owncloud/ocdav/propfind/propfind_suite_test.go b/internal/http/services/owncloud/ocdav/propfind/propfind_suite_test.go index 044dcc4e29..d02dba936b 100644 --- a/internal/http/services/owncloud/ocdav/propfind/propfind_suite_test.go +++ b/internal/http/services/owncloud/ocdav/propfind/propfind_suite_test.go @@ -1,3 +1,21 @@ +// Copyright 2018-2021 CERN +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// In applying this license, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + package propfind_test import ( diff --git a/internal/http/services/owncloud/ocdav/propfind/propfind_test.go b/internal/http/services/owncloud/ocdav/propfind/propfind_test.go index 4ae00f890b..0109fb82a8 100644 --- a/internal/http/services/owncloud/ocdav/propfind/propfind_test.go +++ b/internal/http/services/owncloud/ocdav/propfind/propfind_test.go @@ -36,7 +36,7 @@ import ( var _ = Describe("Propfind", func() { var ( - handler *propfind.PropfindHandler + handler *propfind.Handler client *mocks.GatewayClient ctx context.Context ) @@ -44,13 +44,13 @@ var _ = Describe("Propfind", func() { JustBeforeEach(func() { ctx = context.Background() client = &mocks.GatewayClient{} - handler = propfind.NewPropfindHandler("127.0.0.1:3000", func() (propfind.GatewayClient, error) { + handler = propfind.NewHandler("127.0.0.1:3000", func() (propfind.GatewayClient, error) { return client, nil }) }) - Describe("NewPropfindHandler", func() { - It("returns a hanlder", func() { + Describe("NewHandler", func() { + It("returns a handler", func() { Expect(handler).ToNot(BeNil()) }) }) diff --git a/internal/http/services/owncloud/ocdav/props/props.go b/internal/http/services/owncloud/ocdav/props/props.go index 6b1bba693a..54142cbd97 100644 --- a/internal/http/services/owncloud/ocdav/props/props.go +++ b/internal/http/services/owncloud/ocdav/props/props.go @@ -23,7 +23,7 @@ import ( "encoding/xml" ) -// Property represents a single DAV resource property as defined in RFC 4918. +// PropertyXML represents a single DAV resource property as defined in RFC 4918. // http://www.webdav.org/specs/rfc4918.html#data.model.for.resource.properties type PropertyXML struct { // XMLName is the fully qualified name that identifies this property. @@ -49,6 +49,7 @@ func xmlEscaped(val string) []byte { return buf.Bytes() } +// NewPropNS returns a new PropertyXML instance func NewPropNS(namespace string, local string, val string) *PropertyXML { return &PropertyXML{ XMLName: xml.Name{Space: namespace, Local: local}, @@ -57,6 +58,7 @@ func NewPropNS(namespace string, local string, val string) *PropertyXML { } } +// NewProp returns a new PropertyXML instance while xml-escaping the value // TODO properly use the space func NewProp(key, val string) *PropertyXML { return &PropertyXML{ @@ -66,6 +68,7 @@ func NewProp(key, val string) *PropertyXML { } } +// NewPropRaw returns a new PropertyXML instance for the given key/value pair // TODO properly use the space func NewPropRaw(key, val string) *PropertyXML { return &PropertyXML{ diff --git a/internal/http/services/owncloud/ocdav/report.go b/internal/http/services/owncloud/ocdav/report.go index 9c2c9319cd..85feefb7d5 100644 --- a/internal/http/services/owncloud/ocdav/report.go +++ b/internal/http/services/owncloud/ocdav/report.go @@ -120,7 +120,7 @@ func (s *svc) doFilterFiles(w http.ResponseWriter, r *http.Request, ff *reportFi infos = append(infos, statRes.Info) } - responsesXML, err := propfind.MultistatusResponse(ctx, &propfind.PropfindXML{Prop: ff.Prop}, infos, s.c.PublicURL, namespace, nil) + responsesXML, err := propfind.MultistatusResponse(ctx, &propfind.XML{Prop: ff.Prop}, infos, s.c.PublicURL, namespace, nil) if err != nil { log.Error().Err(err).Msg("error formatting propfind") w.WriteHeader(http.StatusInternalServerError) @@ -143,7 +143,7 @@ type report struct { type reportSearchFiles struct { XMLName xml.Name `xml:"search-files"` Lang string `xml:"xml:lang,attr,omitempty"` - Prop propfind.PropfindProps `xml:"DAV: prop"` + Prop propfind.Props `xml:"DAV: prop"` Search reportSearchFilesSearch `xml:"search"` } type reportSearchFilesSearch struct { @@ -155,7 +155,7 @@ type reportSearchFilesSearch struct { type reportFilterFiles struct { XMLName xml.Name `xml:"filter-files"` Lang string `xml:"xml:lang,attr,omitempty"` - Prop propfind.PropfindProps `xml:"DAV: prop"` + Prop propfind.Props `xml:"DAV: prop"` Rules reportFilterFilesRules `xml:"filter-rules"` } diff --git a/internal/http/services/owncloud/ocdav/spacelookup/spacelookup.go b/internal/http/services/owncloud/ocdav/spacelookup/spacelookup.go index eb86620794..3be319bec2 100644 --- a/internal/http/services/owncloud/ocdav/spacelookup/spacelookup.go +++ b/internal/http/services/owncloud/ocdav/spacelookup/spacelookup.go @@ -93,6 +93,7 @@ func LookUpStorageSpacesForPathWithChildren(ctx context.Context, client gateway. return lSSRes.StorageSpaces, lSSRes.Status, nil } +// LookUpStorageSpaceByID find a space by ID func LookUpStorageSpaceByID(ctx context.Context, client gateway.GatewayAPIClient, spaceID string) (*storageProvider.StorageSpace, *rpc.Status, error) { // retrieve a specific storage space lSSReq := &storageProvider.ListStorageSpacesRequest{ @@ -123,6 +124,8 @@ func LookUpStorageSpaceByID(ctx context.Context, client gateway.GatewayAPIClient return nil, nil, fmt.Errorf("unexpected number of spaces %d", len(lSSRes.StorageSpaces)) } } + +// LookUpStorageSpaceReference find a space by id and returns a relative reference func LookUpStorageSpaceReference(ctx context.Context, client gateway.GatewayAPIClient, spaceID string, relativePath string, spacesDavRequest bool) (*storageProvider.Reference, *rpc.Status, error) { space, status, err := LookUpStorageSpaceByID(ctx, client, spaceID) if space == nil { @@ -131,6 +134,7 @@ func LookUpStorageSpaceReference(ctx context.Context, client gateway.GatewayAPIC return MakeRelativeReference(space, relativePath, spacesDavRequest), status, err } +// MakeRelativeReference returns a relative reference for the given space and path func MakeRelativeReference(space *storageProvider.StorageSpace, relativePath string, spacesDavRequest bool) *storageProvider.Reference { if space.Opaque == nil || space.Opaque.Map == nil || space.Opaque.Map["path"] == nil || space.Opaque.Map["path"].Decoder != "plain" { return nil // not mounted diff --git a/internal/http/services/owncloud/ocdav/spaces.go b/internal/http/services/owncloud/ocdav/spaces.go index 5af3fd2096..e633dc8477 100644 --- a/internal/http/services/owncloud/ocdav/spaces.go +++ b/internal/http/services/owncloud/ocdav/spaces.go @@ -64,7 +64,7 @@ func (h *SpacesHandler) Handler(s *svc) http.Handler { switch r.Method { case MethodPropfind: - p := propfind.NewPropfindHandler(config.PublicURL, func() (propfind.GatewayClient, error) { + p := propfind.NewHandler(config.PublicURL, func() (propfind.GatewayClient, error) { return pool.GetGatewayServiceClient(config.GatewaySvc) }) p.HandleSpacesPropfind(w, r, spaceID) diff --git a/internal/http/services/owncloud/ocdav/trashbin.go b/internal/http/services/owncloud/ocdav/trashbin.go index 5d66b316ba..dd58d7b22a 100644 --- a/internal/http/services/owncloud/ocdav/trashbin.go +++ b/internal/http/services/owncloud/ocdav/trashbin.go @@ -312,7 +312,7 @@ func (h *TrashbinHandler) listTrashbin(w http.ResponseWriter, r *http.Request, s } } -func (h *TrashbinHandler) formatTrashPropfind(ctx context.Context, s *svc, u *userpb.User, pf *propfind.PropfindXML, items []*provider.RecycleItem) (string, error) { +func (h *TrashbinHandler) formatTrashPropfind(ctx context.Context, s *svc, u *userpb.User, pf *propfind.XML, items []*provider.RecycleItem) (string, error) { responses := make([]*propfind.ResponseXML, 0, len(items)+1) // add trashbin dir . entry responses = append(responses, &propfind.ResponseXML{ @@ -357,7 +357,7 @@ func (h *TrashbinHandler) formatTrashPropfind(ctx context.Context, s *svc, u *us // itemToPropResponse needs to create a listing that contains a key and destination // the key is the name of an entry in the trash listing // for now we need to limit trash to the users home, so we can expect all trash keys to have the home storage as the opaque id -func (h *TrashbinHandler) itemToPropResponse(ctx context.Context, s *svc, u *userpb.User, pf *propfind.PropfindXML, item *provider.RecycleItem) (*propfind.ResponseXML, error) { +func (h *TrashbinHandler) itemToPropResponse(ctx context.Context, s *svc, u *userpb.User, pf *propfind.XML, item *provider.RecycleItem) (*propfind.ResponseXML, error) { baseURI := ctx.Value(net.CtxKeyBaseURI).(string) ref := path.Join(baseURI, u.Username, item.Key) diff --git a/internal/http/services/owncloud/ocdav/webdav.go b/internal/http/services/owncloud/ocdav/webdav.go index 596c73dbc5..fcb24b6a17 100644 --- a/internal/http/services/owncloud/ocdav/webdav.go +++ b/internal/http/services/owncloud/ocdav/webdav.go @@ -68,7 +68,7 @@ func (h *WebDavHandler) Handler(s *svc) http.Handler { r.URL.Path = newPath switch r.Method { case MethodPropfind: - p := propfind.NewPropfindHandler(config.PublicURL, func() (propfind.GatewayClient, error) { + p := propfind.NewHandler(config.PublicURL, func() (propfind.GatewayClient, error) { return pool.GetGatewayServiceClient(config.GatewaySvc) }) p.HandlePathPropfind(w, r, ns)