From 1dd442a6e8da682df20276d6474bdf94d4a1013f Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Fri, 9 Jun 2023 18:31:57 +0200 Subject: [PATCH 01/12] Use paths as opposed to full URIs in /ocm-provider --- changelog/unreleased/ocm-compat.md | 6 ++++++ .../http/services/ocmprovider/ocmprovider.go | 16 +++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 changelog/unreleased/ocm-compat.md diff --git a/changelog/unreleased/ocm-compat.md b/changelog/unreleased/ocm-compat.md new file mode 100644 index 0000000000..d3541f3421 --- /dev/null +++ b/changelog/unreleased/ocm-compat.md @@ -0,0 +1,6 @@ +Bugfix: only expose paths on /ocm-provider + +Following analysis of OC and NC code to access a remote share, +we must expose paths and not full URIs on the /ocm-provider endpoint. + +https://github.com/cs3org/reva/pull/3962 diff --git a/internal/http/services/ocmprovider/ocmprovider.go b/internal/http/services/ocmprovider/ocmprovider.go index a88f9e52a0..e11ea871ec 100644 --- a/internal/http/services/ocmprovider/ocmprovider.go +++ b/internal/http/services/ocmprovider/ocmprovider.go @@ -70,10 +70,16 @@ func (c *config) init() { c.Provider = "reva" } if c.WebdavRoot == "" { - c.WebdavRoot = "/remote.php/dav/ocm" + c.WebdavRoot = "/remote.php/dav/ocm/" + } + if c.WebdavRoot[len(c.WebdavRoot)-1:] != "/" { + c.WebdavRoot += "/" } if c.WebappRoot == "" { - c.WebappRoot = "/external/sciencemesh" + c.WebappRoot = "/external/sciencemesh/" + } + if c.WebappRoot[len(c.WebappRoot)-1:] != "/" { + c.WebappRoot += "/" } } @@ -99,12 +105,12 @@ func (c *config) prepare() *discoveryData { d.Provider = c.Provider rtProtos := map[string]string{} // webdav is always enabled - rtProtos["webdav"] = fmt.Sprintf("%s%s", c.Endpoint, c.WebdavRoot) + rtProtos["webdav"] = c.WebdavRoot if c.EnableWebapp { - rtProtos["webapp"] = fmt.Sprintf("%s%s", c.Endpoint, c.WebappRoot) + rtProtos["webapp"] = c.WebappRoot } if c.EnableDatatx { - rtProtos["datatx"] = fmt.Sprintf("%s%s", c.Endpoint, c.WebdavRoot) + rtProtos["datatx"] = c.WebdavRoot } d.ResourceTypes = []resourceTypes{{ Name: "file", // so far we only support `file` From b3ea1b87cfdd6c11682b218e0e039574b9800eac Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Mon, 12 Jun 2023 09:03:40 +0200 Subject: [PATCH 02/12] Removed superfluous route --- internal/http/services/ocmd/ocm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/http/services/ocmd/ocm.go b/internal/http/services/ocmd/ocm.go index fa92fb4121..6f997baf70 100644 --- a/internal/http/services/ocmd/ocm.go +++ b/internal/http/services/ocmd/ocm.go @@ -99,7 +99,7 @@ func (s *svc) Prefix() string { } func (s *svc) Unprotected() []string { - return []string{"/invite-accepted", "/shares", "/ocm-provider", "/notifications"} + return []string{"/invite-accepted", "/shares", "/notifications"} } func (s *svc) Handler() http.Handler { From 87c5ec015447c7c0562dec474d1e03e0689e86d8 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Mon, 12 Jun 2023 09:03:54 +0200 Subject: [PATCH 03/12] Added minimal /ocs-provider --- internal/http/services/loader/loader.go | 1 + .../http/services/ocsprovider/ocsprovider.go | 123 ++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 internal/http/services/ocsprovider/ocsprovider.go diff --git a/internal/http/services/loader/loader.go b/internal/http/services/loader/loader.go index adf1ad02da..0c1064547b 100644 --- a/internal/http/services/loader/loader.go +++ b/internal/http/services/loader/loader.go @@ -30,6 +30,7 @@ import ( _ "github.com/cs3org/reva/internal/http/services/metrics" _ "github.com/cs3org/reva/internal/http/services/ocmd" _ "github.com/cs3org/reva/internal/http/services/ocmprovider" + _ "github.com/cs3org/reva/internal/http/services/ocsprovider" _ "github.com/cs3org/reva/internal/http/services/owncloud/ocdav" _ "github.com/cs3org/reva/internal/http/services/owncloud/ocs" _ "github.com/cs3org/reva/internal/http/services/preferences" diff --git a/internal/http/services/ocsprovider/ocsprovider.go b/internal/http/services/ocsprovider/ocsprovider.go new file mode 100644 index 0000000000..0dac09b717 --- /dev/null +++ b/internal/http/services/ocsprovider/ocsprovider.go @@ -0,0 +1,123 @@ +// Copyright 2018-2023 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 ocsprovider + +import ( + "encoding/json" + "net/http" + + "github.com/cs3org/reva/pkg/appctx" + "github.com/cs3org/reva/pkg/rhttp/global" + "github.com/mitchellh/mapstructure" + "github.com/rs/zerolog" +) + +func init() { + global.Register("ocsprovider", New) +} + +type config struct { + WebdavRoot string `mapstructure:"webdav_root" docs:"/remote.php/dav/ocm;The root URL of the WebDAV endpoint to serve OCM shares."` +} + +type ocsDiscoveryData struct { + Version int `json:"version"` + Services ocsServices `json:"services"` +} + +type ocsServices struct { + PrivateData map[string]any `json:"PRIVATE_DATA"` + Sharing map[string]any `json:"SHARING"` + FederatedSharing map[string]any `json:"FEDERATED_SHARING"` + Provisioning map[string]any `json:"PROVISIONING"` +} + +type svc struct { + data *ocsDiscoveryData +} + +func (c *config) init() { + if c.WebdavRoot == "" { + // same default as for the /ocm-provider discovery service + c.WebdavRoot = "/remote.php/dav/ocm/" + } + if c.WebdavRoot[len(c.WebdavRoot)-1:] != "/" { + c.WebdavRoot += "/" + } +} + +func (c *config) prepare() *ocsDiscoveryData { + // generates the (static) data structure to be exposed by /ocs-provider: + // here we only populate the federated sharing part and leave the rest empty + var fedSharingData = map[string]any{ + "version": 1, + "endpoints": map[string]string{ + "webdav": c.WebdavRoot, + }, + } + d := &ocsDiscoveryData{} + d.Version = 2 + d.Services = ocsServices{ + PrivateData: map[string]any{}, + Sharing: map[string]any{}, + FederatedSharing: fedSharingData, + Provisioning: map[string]any{}, + } + return d +} + +// New returns a new ocsprovider object, that implements +// a minimal OCS discovery endpoint similar to OC10 or NC. +// OCS specs are defined at: +// https://www.freedesktop.org/wiki/Specifications/open-collaboration-services +func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error) { + conf := &config{} + if err := mapstructure.Decode(m, conf); err != nil { + return nil, err + } + + conf.init() + return &svc{data: conf.prepare()}, nil +} + +// Close performs cleanup. +func (s *svc) Close() error { + return nil +} + +func (s *svc) Prefix() string { + // this is hardcoded as per OCS specifications + return "/ocs-provider" +} + +func (s *svc) Unprotected() []string { + return []string{"/"} +} + +func (s *svc) Handler() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + log := appctx.GetLogger(r.Context()) + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + indented, _ := json.MarshalIndent(s.data, "", " ") + if _, err := w.Write(indented); err != nil { + log.Err(err).Msg("Error writing to ResponseWriter") + } + }) +} From 6d675e7b92eae487108106ade605f2391078ef68 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Tue, 13 Jun 2023 17:19:32 +0200 Subject: [PATCH 04/12] Updated reference examples --- examples/meshdirectory/meshdirectory.toml | 3 ++- examples/nextcloud-integration/revad.toml | 2 ++ examples/oc-phoenix/ocmd.toml | 4 +++- examples/ocmd/server-1/ocmd-server-1.toml | 6 ++++++ examples/ocmd/server-2/ocmd-server-2.toml | 6 ++++++ examples/oidc-mapping-tpc/server-1.toml | 1 + examples/oidc-mapping-tpc/server-2.toml | 1 + examples/standalone/standalone.toml | 1 + examples/storage-references/gateway.toml | 1 + examples/two-server-setup/gateway-1.toml | 1 + examples/two-server-setup/gateway-2.toml | 1 + 11 files changed, 25 insertions(+), 2 deletions(-) diff --git a/examples/meshdirectory/meshdirectory.toml b/examples/meshdirectory/meshdirectory.toml index 9711044416..8373cefcc6 100644 --- a/examples/meshdirectory/meshdirectory.toml +++ b/examples/meshdirectory/meshdirectory.toml @@ -25,6 +25,7 @@ file = "/var/tmp/reva/shares_server_1.json" [http.services.prometheus] [http.services.ocmd] [http.services.ocmprovider] +[http.services.ocsprovider] [http.services.ocdav] [http.services.ocs] @@ -65,4 +66,4 @@ timeout = 10 refresh = 900 [http.services.meshdirectory] -mesh_directory_url = 'http://localhost:19001/meshdir/' \ No newline at end of file +mesh_directory_url = 'http://localhost:19001/meshdir/' diff --git a/examples/nextcloud-integration/revad.toml b/examples/nextcloud-integration/revad.toml index b37faacdc8..2f51c0e461 100644 --- a/examples/nextcloud-integration/revad.toml +++ b/examples/nextcloud-integration/revad.toml @@ -134,6 +134,8 @@ webdav_root = "/remote.php/dav/ocm" enable_webapp = true enable_datatx = true +[http.services.ocsprovider] + [http.middlewares.providerauthorizer] driver = "json" diff --git a/examples/oc-phoenix/ocmd.toml b/examples/oc-phoenix/ocmd.toml index 0864d48b54..c1cb8b7533 100644 --- a/examples/oc-phoenix/ocmd.toml +++ b/examples/oc-phoenix/ocmd.toml @@ -38,10 +38,12 @@ prefix = "ocm" [http.services.ocmprovider] endpoint = "http://localhost:13001" +[http.services.ocsprovider] + [http.middlewares.providerauthorizer] driver = "json" [http.middlewares.providerauthorizer.drivers.json] providers = "providers.demo.json" -[http.middlewares.cors] \ No newline at end of file +[http.middlewares.cors] diff --git a/examples/ocmd/server-1/ocmd-server-1.toml b/examples/ocmd/server-1/ocmd-server-1.toml index 5ecf585745..2af28c3ce5 100644 --- a/examples/ocmd/server-1/ocmd-server-1.toml +++ b/examples/ocmd/server-1/ocmd-server-1.toml @@ -130,6 +130,8 @@ endpoint = "http://localhost:19001" enable_webapp = true enable_datatx = true +[http.services.ocsprovider] + [http.middlewares.providerauthorizer] driver = "json" @@ -144,3 +146,7 @@ prefix = "ocs" [http.services.appprovider] [http.middlewares.cors] + +[http.middlewares.auth] +credential_chain = ["publicshares", "ocmshares", "basic", "bearer"] + diff --git a/examples/ocmd/server-2/ocmd-server-2.toml b/examples/ocmd/server-2/ocmd-server-2.toml index 8ac94f9ba9..9e1555403b 100644 --- a/examples/ocmd/server-2/ocmd-server-2.toml +++ b/examples/ocmd/server-2/ocmd-server-2.toml @@ -119,6 +119,8 @@ endpoint = "http://localhost:17001" enable_webapp = true enable_datatx = true +[http.services.ocsprovider] + [http.middlewares.providerauthorizer] driver = "json" @@ -131,3 +133,7 @@ prefix = "ocs" [http.services.ocdav] [http.middlewares.cors] + +[http.middlewares.auth] +credential_chain = ["publicshares", "ocmshares", "basic", "bearer"] + diff --git a/examples/oidc-mapping-tpc/server-1.toml b/examples/oidc-mapping-tpc/server-1.toml index 61248b2a13..d0014316aa 100644 --- a/examples/oidc-mapping-tpc/server-1.toml +++ b/examples/oidc-mapping-tpc/server-1.toml @@ -63,6 +63,7 @@ driver = "localhome" [http.services.prometheus] [http.services.ocmd] [http.services.ocmprovider] +[http.services.ocsprovider] [http.services.ocs] [http.services.ocdav] enable_http_tpc = true diff --git a/examples/oidc-mapping-tpc/server-2.toml b/examples/oidc-mapping-tpc/server-2.toml index 02eaee63bc..07b1f32fc9 100644 --- a/examples/oidc-mapping-tpc/server-2.toml +++ b/examples/oidc-mapping-tpc/server-2.toml @@ -63,6 +63,7 @@ driver = "localhome" [http.services.prometheus] [http.services.ocmd] [http.services.ocmprovider] +[http.services.ocsprovider] [http.services.ocs] [http.services.ocdav] enable_http_tpc = true diff --git a/examples/standalone/standalone.toml b/examples/standalone/standalone.toml index 0b54edd841..5c06973275 100644 --- a/examples/standalone/standalone.toml +++ b/examples/standalone/standalone.toml @@ -18,5 +18,6 @@ [http.services.prometheus] [http.services.ocmd] [http.services.ocmprovider] +[http.services.ocsprovider] [http.services.ocdav] [http.services.ocs] diff --git a/examples/storage-references/gateway.toml b/examples/storage-references/gateway.toml index 3070078503..b0380103f9 100644 --- a/examples/storage-references/gateway.toml +++ b/examples/storage-references/gateway.toml @@ -45,6 +45,7 @@ mime_types = [ [http.services.prometheus] [http.services.ocmd] [http.services.ocmprovider] +[http.services.ocsprovider] [http.services.ocdav] [http.services.ocs] [http.services.appprovider] diff --git a/examples/two-server-setup/gateway-1.toml b/examples/two-server-setup/gateway-1.toml index 4a6990a42a..6c979d306e 100644 --- a/examples/two-server-setup/gateway-1.toml +++ b/examples/two-server-setup/gateway-1.toml @@ -60,6 +60,7 @@ endpoint = "http://localhost:19001" enable_webapp = true enable_datatx = true +[http.services.ocsprovider] [http.services.ocdav] [http.services.ocs] diff --git a/examples/two-server-setup/gateway-2.toml b/examples/two-server-setup/gateway-2.toml index 808ec4c9ed..84bae2d571 100644 --- a/examples/two-server-setup/gateway-2.toml +++ b/examples/two-server-setup/gateway-2.toml @@ -76,6 +76,7 @@ enable_webapp = true enable_datatx = true [http.services.ocdav] +[http.services.ocsprovider] [http.services.ocs] [http.middlewares.providerauthorizer.drivers.json] From 13f684c00973589ba51e42eafed923aa724781a9 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Wed, 14 Jun 2023 08:10:16 +0200 Subject: [PATCH 05/12] Also added the whole ownCloud structure to /ocs-provider Only the `share` and `webdav` endpoints are populated --- .../http/services/ocsprovider/ocsprovider.go | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/internal/http/services/ocsprovider/ocsprovider.go b/internal/http/services/ocsprovider/ocsprovider.go index 0dac09b717..162f7574c2 100644 --- a/internal/http/services/ocsprovider/ocsprovider.go +++ b/internal/http/services/ocsprovider/ocsprovider.go @@ -63,21 +63,29 @@ func (c *config) init() { } func (c *config) prepare() *ocsDiscoveryData { - // generates the (static) data structure to be exposed by /ocs-provider: - // here we only populate the federated sharing part and leave the rest empty - var fedSharingData = map[string]any{ - "version": 1, - "endpoints": map[string]string{ - "webdav": c.WebdavRoot, - }, - } + // generates a minimal static data structure to be exposed by /ocs-provider d := &ocsDiscoveryData{} d.Version = 2 d.Services = ocsServices{ - PrivateData: map[string]any{}, - Sharing: map[string]any{}, - FederatedSharing: fedSharingData, - Provisioning: map[string]any{}, + PrivateData: map[string]any{ + "version": 1, + "endpoints": map[string]any{}, + }, + Sharing: map[string]any{ + "version": 1, + "endpoints": map[string]any{}, + }, + FederatedSharing: map[string]any{ + "version": 1, + "endpoints": map[string]string{ + "share": c.WebdavRoot, + "webdav": c.WebdavRoot, + }, + }, + Provisioning: map[string]any{ + "version": 1, + "endpoints": map[string]any{}, + }, } return d } From 856fd1fa08b09315b579839f5ec643487e62a788 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Thu, 15 Jun 2023 11:39:04 +0200 Subject: [PATCH 06/12] Updated examples to reflect current master wrt OCM, sciencemesh, and apps --- examples/nextcloud-integration/revad.toml | 56 +++++++++++++---------- examples/oc-phoenix/ocmd.toml | 5 -- examples/ocmd/server-1/ocmd-server-1.toml | 33 +++++++++++-- examples/ocmd/server-2/ocmd-server-2.toml | 31 +++++++++++++ examples/oidc-mapping-tpc/server-1.toml | 2 - examples/oidc-mapping-tpc/server-2.toml | 2 - examples/storage-references/gateway.toml | 15 +++++- examples/two-server-setup/gateway-1.toml | 45 ++++++++++++++++++ examples/two-server-setup/gateway-2.toml | 31 +++++++++++++ 9 files changed, 181 insertions(+), 39 deletions(-) diff --git a/examples/nextcloud-integration/revad.toml b/examples/nextcloud-integration/revad.toml index 2f51c0e461..717ae0d09c 100644 --- a/examples/nextcloud-integration/revad.toml +++ b/examples/nextcloud-integration/revad.toml @@ -7,7 +7,7 @@ address = "0.0.0.0:19000" [grpc.services.gateway] authregistrysvc = "localhost:19000" appprovidersvc = "localhost:19000" -appregistry = "localhost:19000" +appregistrysvc = "localhost:19000" storageregistrysvc = "localhost:19000" preferencessvc = "localhost:19000" userprovidersvc = "localhost:19000" @@ -21,6 +21,29 @@ commit_share_to_storage_grant = false datagateway = "http://localhost:19001/data" transfer_expires = 6 # give it a moment +[grpc.services.appregistry] +driver = "static" + +[grpc.services.appregistry.drivers.static] +mime_types = [ + {"mime_type" = "text/plain", "extension" = "txt", "name" = "Text file", "description" = "Text file", "allow_creation" = true}, + {"mime_type" = "text/markdown", "extension" = "md", "name" = "Markdown file", "description" = "Markdown file", "allow_creation" = true}, + {"mime_type" = "application/vnd.oasis.opendocument.text", "extension" = "odt", "name" = "OpenDocument", "description" = "OpenDocument text document", "default_app" = "Collabora", "allow_creation" = true}, + {"mime_type" = "application/vnd.oasis.opendocument.spreadsheet", "extension" = "ods", "name" = "OpenSpreadsheet", "description" = "OpenDocument spreadsheet document", "default_app" = "Collabora", "allow_creation" = true}, + {"mime_type" = "application/vnd.oasis.opendocument.presentation", "extension" = "odp", "name" = "OpenPresentation", "description" = "OpenDocument presentation document", "default_app" = "Collabora", "allow_creation" = true}, + {"mime_type" = "application/vnd.jupyter", "extension" = "ipynb", "name" = "Jupyter Notebook", "description" = "Jupyter Notebook"} +] + +[grpc.services.appprovider] +driver = "wopi" +app_provider_url = "localhost:19000" + +[grpc.services.appprovider.drivers.wopi] +iop_secret = "shared-secret-with-wopiserver" +wopi_url = "http://0.0.0.0:8880/" +app_name = "Collabora" +app_url = "https://your-collabora-server.org:9980" + [grpc.services.authregistry] driver = "static" @@ -65,27 +88,6 @@ providers = "/etc/revad/providers.json" [grpc.services.publicshareprovider] driver = "memory" -[grpc.services.appprovider] -driver = "wopi" -custom_mime_types_json = "custom-mime-types-demo.json" - -[grpc.services.appprovider.drivers.wopi] -iop_secret = "hello" -wopi_url = "http://0.0.0.0:8880/" -app_name = "Collabora" -app_url = "https://your-collabora-server.org:9980" - -[grpc.services.appregistry] -driver = "static" - -[grpc.services.appregistry.static.rules] -"text/plain" = "localhost:19000" -"text/markdown" = "localhost:19000" -"application/compressed-markdown" = "localhost:19000" -"application/vnd.oasis.opendocument.text" = "localhost:19000" -"application/vnd.oasis.opendocument.spreadsheet" = "localhost:19000" -"application/vnd.oasis.opendocument.presentation" = "localhost:19000" - [grpc.services.storageprovider] driver = "nextcloud" mount_path = "/home" @@ -100,7 +102,6 @@ custom_mime_types_json = "custom-mime-types-demo.json" endpoint = "http://localhost/apps/sciencemesh/" user_layout = "{{.Username}}" - [grpc.services.authprovider] auth_manager = "nextcloud" [grpc.services.authprovider.drivers.nextcloud] @@ -112,10 +113,10 @@ driver = "nextcloud" endpoint = "http://localhost/apps/sciencemesh/" [http] -enabled_services = ["ocmd", "ocmprovider"] -enabled_middlewares = ["providerauthorizer", "cors"] address = "0.0.0.0:19001" +[http.services.appprovider] + [http.services.dataprovider] driver = "nextcloud" @@ -136,6 +137,11 @@ enable_datatx = true [http.services.ocsprovider] +[http.services.sciencemesh] +mesh_directory_url = 'https://sciencemesh.cesnet.cz/iop/meshdir' +provider_domain = 'your-domain.org' +ocm_mount_point = '/sciencemesh' + [http.middlewares.providerauthorizer] driver = "json" diff --git a/examples/oc-phoenix/ocmd.toml b/examples/oc-phoenix/ocmd.toml index c1cb8b7533..bd53def4ae 100644 --- a/examples/oc-phoenix/ocmd.toml +++ b/examples/oc-phoenix/ocmd.toml @@ -35,11 +35,6 @@ address = "0.0.0.0:13001" [http.services.ocmd] prefix = "ocm" -[http.services.ocmprovider] -endpoint = "http://localhost:13001" - -[http.services.ocsprovider] - [http.middlewares.providerauthorizer] driver = "json" diff --git a/examples/ocmd/server-1/ocmd-server-1.toml b/examples/ocmd/server-1/ocmd-server-1.toml index 2af28c3ce5..d2d70b26e7 100644 --- a/examples/ocmd/server-1/ocmd-server-1.toml +++ b/examples/ocmd/server-1/ocmd-server-1.toml @@ -6,8 +6,7 @@ address = "0.0.0.0:19000" [grpc.services.gateway] authregistrysvc = "localhost:19000" -appprovidersvc = "localhost:19000" -appregistry = "localhost:19000" +appregistrysvc = "localhost:19000" storageregistrysvc = "localhost:19000" preferencessvc = "localhost:19000" userprovidersvc = "localhost:19000" @@ -22,6 +21,29 @@ transfer_expires = 6 # give it a moment commit_share_to_storage_grant = true commit_share_to_storage_ref = true +[grpc.services.appregistry] +driver = "static" + +[grpc.services.appregistry.drivers.static] +mime_types = [ + {"mime_type" = "text/plain", "extension" = "txt", "name" = "Text file", "description" = "Text file", "allow_creation" = true}, + {"mime_type" = "text/markdown", "extension" = "md", "name" = "Markdown file", "description" = "Markdown file", "allow_creation" = true}, + {"mime_type" = "application/vnd.oasis.opendocument.text", "extension" = "odt", "name" = "OpenDocument", "description" = "OpenDocument text document", "default_app" = "Collabora", "allow_creation" = true}, + {"mime_type" = "application/vnd.oasis.opendocument.spreadsheet", "extension" = "ods", "name" = "OpenSpreadsheet", "description" = "OpenDocument spreadsheet document", "default_app" = "Collabora", "allow_creation" = true}, + {"mime_type" = "application/vnd.oasis.opendocument.presentation", "extension" = "odp", "name" = "OpenPresentation", "description" = "OpenDocument presentation document", "default_app" = "Collabora", "allow_creation" = true}, + {"mime_type" = "application/vnd.jupyter", "extension" = "ipynb", "name" = "Jupyter Notebook", "description" = "Jupyter Notebook"} +] + +[grpc.services.appprovider] +driver = "wopi" +appregistrysvc = "localhost:19000" + +[grpc.services.appprovider.drivers.wopi] +iop_secret = "shared-secret-with-wopiserver" +wopi_url = "http://0.0.0.0:8880/" +app_name = "Collabora" +app_url = "https://your-collabora-server.org:9980" + [grpc.services.authregistry] driver = "static" @@ -111,6 +133,8 @@ users = "users.demo.json" [http] address = "0.0.0.0:19001" +[http.services.appprovider] + [http.services.dataprovider] driver = "localhome" @@ -143,7 +167,10 @@ prefix = "ocs" [http.services.ocdav] -[http.services.appprovider] +[http.services.sciencemesh] +mesh_directory_url = 'https://sciencemesh.cesnet.cz/iop/meshdir' +provider_domain = 'your-domain-1.org' +ocm_mount_point = '/sciencemesh' [http.middlewares.cors] diff --git a/examples/ocmd/server-2/ocmd-server-2.toml b/examples/ocmd/server-2/ocmd-server-2.toml index 9e1555403b..3e859fffa2 100644 --- a/examples/ocmd/server-2/ocmd-server-2.toml +++ b/examples/ocmd/server-2/ocmd-server-2.toml @@ -6,6 +6,7 @@ address = "0.0.0.0:17000" [grpc.services.gateway] authregistrysvc = "localhost:17000" +appregistrysvc = "localhost:17000" storageregistrysvc = "localhost:17000" preferencessvc = "localhost:17000" userprovidersvc = "localhost:17000" @@ -20,6 +21,29 @@ transfer_expires = 6 # give it a moment commit_share_to_storage_grant = true commit_share_to_storage_ref = true +[grpc.services.appregistry] +driver = "static" + +[grpc.services.appregistry.drivers.static] +mime_types = [ + {"mime_type" = "text/plain", "extension" = "txt", "name" = "Text file", "description" = "Text file", "allow_creation" = true}, + {"mime_type" = "text/markdown", "extension" = "md", "name" = "Markdown file", "description" = "Markdown file", "allow_creation" = true}, + {"mime_type" = "application/vnd.oasis.opendocument.text", "extension" = "odt", "name" = "OpenDocument", "description" = "OpenDocument text document", "default_app" = "Collabora", "allow_creation" = true}, + {"mime_type" = "application/vnd.oasis.opendocument.spreadsheet", "extension" = "ods", "name" = "OpenSpreadsheet", "description" = "OpenDocument spreadsheet document", "default_app" = "Collabora", "allow_creation" = true}, + {"mime_type" = "application/vnd.oasis.opendocument.presentation", "extension" = "odp", "name" = "OpenPresentation", "description" = "OpenDocument presentation document", "default_app" = "Collabora", "allow_creation" = true}, + {"mime_type" = "application/vnd.jupyter", "extension" = "ipynb", "name" = "Jupyter Notebook", "description" = "Jupyter Notebook"} +] + +[grpc.services.appprovider] +driver = "wopi" +app_provider_url = "localhost:17000" + +[grpc.services.appprovider.drivers.wopi] +iop_secret = "shared-secret-with-wopiserver" +wopi_url = "http://0.0.0.0:8880/" +app_name = "Collabora" +app_url = "https://your-collabora-server.org:9980" + [grpc.services.authregistry] driver = "static" @@ -102,6 +126,8 @@ users = "users.demo.json" [http] address = "0.0.0.0:17001" +[http.services.appprovider] + [http.services.dataprovider] driver = "localhome" @@ -132,6 +158,11 @@ prefix = "ocs" [http.services.ocdav] +[http.services.sciencemesh] +mesh_directory_url = 'https://sciencemesh.cesnet.cz/iop/meshdir' +provider_domain = 'your-domain.org' +ocm_mount_point = '/sciencemesh' + [http.middlewares.cors] [http.middlewares.auth] diff --git a/examples/oidc-mapping-tpc/server-1.toml b/examples/oidc-mapping-tpc/server-1.toml index d0014316aa..c212892e59 100644 --- a/examples/oidc-mapping-tpc/server-1.toml +++ b/examples/oidc-mapping-tpc/server-1.toml @@ -62,8 +62,6 @@ driver = "localhome" [http.services.datagateway] [http.services.prometheus] [http.services.ocmd] -[http.services.ocmprovider] -[http.services.ocsprovider] [http.services.ocs] [http.services.ocdav] enable_http_tpc = true diff --git a/examples/oidc-mapping-tpc/server-2.toml b/examples/oidc-mapping-tpc/server-2.toml index 07b1f32fc9..259c4b77d8 100644 --- a/examples/oidc-mapping-tpc/server-2.toml +++ b/examples/oidc-mapping-tpc/server-2.toml @@ -62,8 +62,6 @@ driver = "localhome" [http.services.datagateway] [http.services.prometheus] [http.services.ocmd] -[http.services.ocmprovider] -[http.services.ocsprovider] [http.services.ocs] [http.services.ocdav] enable_http_tpc = true diff --git a/examples/storage-references/gateway.toml b/examples/storage-references/gateway.toml index b0380103f9..71be7f6e76 100644 --- a/examples/storage-references/gateway.toml +++ b/examples/storage-references/gateway.toml @@ -31,6 +31,8 @@ appauth = "localhost:15000" [grpc.services.ocmproviderauthorizer] [grpc.services.appregistry] +driver = "static" + [grpc.services.appregistry.drivers.static] mime_types = [ {"mime_type" = "text/plain", "extension" = "txt", "name" = "Text file", "description" = "Text file", "allow_creation" = true}, @@ -41,6 +43,17 @@ mime_types = [ {"mime_type" = "application/vnd.jupyter", "extension" = "ipynb", "name" = "Jupyter Notebook", "description" = "Jupyter Notebook"} ] +[grpc.services.appprovider] +driver = "wopi" +appregistrysvc = "localhost:19000" +custom_mime_types_json = "/etc/revad/custom-mime-types-demo.json" + +[grpc.services.appprovider.drivers.wopi] +iop_secret = "shared-secret-with-wopiserver" +wopi_url = "http://0.0.0.0:8880/" +app_name = "Collabora" +app_url = "https://your-collabora-server.org:9980" + [http.services.datagateway] [http.services.prometheus] [http.services.ocmd] @@ -48,7 +61,6 @@ mime_types = [ [http.services.ocsprovider] [http.services.ocdav] [http.services.ocs] -[http.services.appprovider] [http.services.sciencemesh] mesh_directory_url = 'https://sciencemesh.cesnet.cz/iop/meshdir' @@ -61,4 +73,3 @@ disable_auth = true sender_mail = "sciencemesh@your-domain.org" smtp_server = "your-smtp-server.your-domain.org" smtp_port = 25 - diff --git a/examples/two-server-setup/gateway-1.toml b/examples/two-server-setup/gateway-1.toml index 6c979d306e..f89a70de87 100644 --- a/examples/two-server-setup/gateway-1.toml +++ b/examples/two-server-setup/gateway-1.toml @@ -1,11 +1,51 @@ +[shared] +gatewaysvc = "localhost:19000" +datagateway = "http://localhost:19001/datagateway" + [grpc] address = "0.0.0.0:19000" # services to enable [grpc.services.gateway] +authregistrysvc = "localhost:19000" +appregistrysvc = "localhost:19000" +storageregistrysvc = "localhost:19000" +preferencessvc = "localhost:19000" +userprovidersvc = "localhost:19000" +groupprovidersvc = "localhost:19000" +usershareprovidersvc = "localhost:19000" +publicshareprovidersvc = "localhost:19000" +ocmcoresvc = "localhost:19000" +ocmshareprovidersvc = "localhost:19000" +ocminvitemanagersvc = "localhost:19000" +ocmproviderauthorizersvc = "localhost:19000" +datagateway = "http://localhost:19001/data" commit_share_to_storage_grant = true commit_share_to_storage_ref = true +[grpc.services.appregistry] +driver = "static" + +[grpc.services.appregistry.drivers.static] +mime_types = [ + {"mime_type" = "text/plain", "extension" = "txt", "name" = "Text file", "description" = "Text file", "allow_creation" = true}, + {"mime_type" = "text/markdown", "extension" = "md", "name" = "Markdown file", "description" = "Markdown file", "allow_creation" = true}, + {"mime_type" = "application/vnd.oasis.opendocument.text", "extension" = "odt", "name" = "OpenDocument", "description" = "OpenDocument text document", "default_app" = "Collabora", "allow_creation" = true}, + {"mime_type" = "application/vnd.oasis.opendocument.spreadsheet", "extension" = "ods", "name" = "OpenSpreadsheet", "description" = "OpenDocument spreadsheet document", "default_app" = "Collabora", "allow_creation" = true}, + {"mime_type" = "application/vnd.oasis.opendocument.presentation", "extension" = "odp", "name" = "OpenPresentation", "description" = "OpenDocument presentation document", "default_app" = "Collabora", "allow_creation" = true}, + {"mime_type" = "application/vnd.jupyter", "extension" = "ipynb", "name" = "Jupyter Notebook", "description" = "Jupyter Notebook"} +] + +[grpc.services.appprovider] +driver = "wopi" +app_provider_url = "localhost:19000" + +[grpc.services.appprovider.drivers.wopi] +iop_secret = "shared-secret-with-wopiserver" +wopi_url = "http://0.0.0.0:8880/" +app_name = "Collabora" +app_url = "https://your-collabora-server.org:9980" + [grpc.services.storageregistry] [grpc.services.storageregistry.drivers.static] home_provider = "/home" @@ -51,6 +91,7 @@ providers = "providers.demo.json" [http] address = "0.0.0.0:19001" +[http.services.appprovider] [http.services.datagateway] [http.services.prometheus] [http.services.ocmd] @@ -63,6 +104,10 @@ enable_datatx = true [http.services.ocsprovider] [http.services.ocdav] [http.services.ocs] +[http.services.sciencemesh] +mesh_directory_url = 'https://sciencemesh.cesnet.cz/iop/meshdir' +provider_domain = 'your-domain.org' +ocm_mount_point = '/sciencemesh' [http.middlewares.providerauthorizer.drivers.json] providers = "providers.demo.json" diff --git a/examples/two-server-setup/gateway-2.toml b/examples/two-server-setup/gateway-2.toml index 84bae2d571..098c36f139 100644 --- a/examples/two-server-setup/gateway-2.toml +++ b/examples/two-server-setup/gateway-2.toml @@ -8,6 +8,7 @@ address = "0.0.0.0:29000" # services to enable [grpc.services.gateway] authregistrysvc = "localhost:29000" +appregistrysvc = "localhost:29000" storageregistrysvc = "localhost:29000" preferencessvc = "localhost:29000" userprovidersvc = "localhost:29000" @@ -18,9 +19,33 @@ ocmcoresvc = "localhost:29000" ocmshareprovidersvc = "localhost:29000" ocminvitemanagersvc = "localhost:29000" ocmproviderauthorizersvc = "localhost:29000" +datagateway = "http://localhost:29001/data" commit_share_to_storage_grant = true commit_share_to_storage_ref = true +[grpc.services.appregistry] +driver = "static" + +[grpc.services.appregistry.drivers.static] +mime_types = [ + {"mime_type" = "text/plain", "extension" = "txt", "name" = "Text file", "description" = "Text file", "allow_creation" = true}, + {"mime_type" = "text/markdown", "extension" = "md", "name" = "Markdown file", "description" = "Markdown file", "allow_creation" = true}, + {"mime_type" = "application/vnd.oasis.opendocument.text", "extension" = "odt", "name" = "OpenDocument", "description" = "OpenDocument text document", "default_app" = "Collabora", "allow_creation" = true}, + {"mime_type" = "application/vnd.oasis.opendocument.spreadsheet", "extension" = "ods", "name" = "OpenSpreadsheet", "description" = "OpenDocument spreadsheet document", "default_app" = "Collabora", "allow_creation" = true}, + {"mime_type" = "application/vnd.oasis.opendocument.presentation", "extension" = "odp", "name" = "OpenPresentation", "description" = "OpenDocument presentation document", "default_app" = "Collabora", "allow_creation" = true}, + {"mime_type" = "application/vnd.jupyter", "extension" = "ipynb", "name" = "Jupyter Notebook", "description" = "Jupyter Notebook"} +] + +[grpc.services.appprovider] +driver = "wopi" +appregistrysvc = "localhost:29000" + +[grpc.services.appprovider.drivers.wopi] +iop_secret = "shared-secret-with-wopiserver" +wopi_url = "http://0.0.0.0:8880/" +app_name = "Collabora" +app_url = "https://your-collabora-server.org:9980" + [grpc.services.storageregistry] [grpc.services.storageregistry.drivers.static] home_provider = "/home" @@ -66,6 +91,7 @@ providers = "providers.demo.json" [http] address = "0.0.0.0:29001" +[http.services.appprovider] [http.services.datagateway] [http.services.prometheus] [http.services.ocmd] @@ -79,5 +105,10 @@ enable_datatx = true [http.services.ocsprovider] [http.services.ocs] +[http.services.sciencemesh] +mesh_directory_url = 'https://sciencemesh.cesnet.cz/iop/meshdir' +provider_domain = 'your-domain.org' +ocm_mount_point = '/sciencemesh' + [http.middlewares.providerauthorizer.drivers.json] providers = "providers.demo.json" From 8a4e0e690103a3c75d8f6fe0d0c3cca66c36e718 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Thu, 15 Jun 2023 15:34:05 +0200 Subject: [PATCH 07/12] Added hack for Nextcloud --- internal/http/services/ocmprovider/ocmprovider.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/http/services/ocmprovider/ocmprovider.go b/internal/http/services/ocmprovider/ocmprovider.go index e11ea871ec..8ed83cf116 100644 --- a/internal/http/services/ocmprovider/ocmprovider.go +++ b/internal/http/services/ocmprovider/ocmprovider.go @@ -154,6 +154,12 @@ func (s *svc) Handler() http.Handler { log := appctx.GetLogger(r.Context()) w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) + if r.UserAgent() == "Nextcloud Server Crawler" { + // TODO(lopresti) remove this hack once Nextcloud is able to talk OCM! + s.data.APIVersion = "1.0-proposal1" + } else { + s.data.APIVersion = "1.1.0" + } indented, _ := json.MarshalIndent(s.data, "", " ") if _, err := w.Write(indented); err != nil { log.Err(err).Msg("Error writing to ResponseWriter") From 06a07fc49b3ca31003133aec3afc62c562a08473 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Fri, 16 Jun 2023 18:51:14 +0200 Subject: [PATCH 08/12] Added skeleton /ocm/notifications service --- internal/http/services/ocmd/notifications.go | 106 +++++++++++++++++++ internal/http/services/ocmd/ocm.go | 5 + 2 files changed, 111 insertions(+) create mode 100644 internal/http/services/ocmd/notifications.go diff --git a/internal/http/services/ocmd/notifications.go b/internal/http/services/ocmd/notifications.go new file mode 100644 index 0000000000..7f2249f074 --- /dev/null +++ b/internal/http/services/ocmd/notifications.go @@ -0,0 +1,106 @@ +// Copyright 2018-2023 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 ocmd + +import ( + "io" + "mime" + "net/http" + + gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" + + "github.com/cs3org/reva/internal/http/services/reqres" + "github.com/cs3org/reva/pkg/appctx" + "github.com/cs3org/reva/pkg/rgrpc/todo/pool" +) + +// var validate = validator.New() + +type notifHandler struct { + gatewayClient gateway.GatewayAPIClient +} + +func (h *notifHandler) init(c *config) error { + var err error + h.gatewayClient, err = pool.GetGatewayServiceClient(pool.Endpoint(c.GatewaySvc)) + if err != nil { + return err + } + return nil +} + +// type notificationRequest struct { +// NotificationType string `json:"notificationType" validate:"required"` +// ResourceType string `json:"resourceType" validate:"required"` +// ProviderId string `json:"providerId" validate:"required"` +// Notification ... `json:"notification"` +//} + +// Example of payload from Nextcloud: +// { +// "notificationType": , +// "resourceType" : "file", +// "providerId" : , +// "notification" : { +// "sharedSecret" : , +// "message" : "human-readable message", +// "shareWith" : , +// "senderId" : , +// "shareType" : +// } +// } + +// Notifications dispatches any notifications received from remote OCM sites +// according to the specifications at: +// https://cs3org.github.io/OCM-API/docs.html?branch=v1.1.0&repo=OCM-API&user=cs3org#/paths/~1notifications/post +func (h *notifHandler) Notifications(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + log := appctx.GetLogger(ctx) + req, err := getNotification(r) + if err != nil { + reqres.WriteError(w, r, reqres.APIErrorInvalidParameter, err.Error(), nil) + return + } + + // TODO(lopresti) this is all to be implemented. For now we just log what we got + log.Debug().Msgf("Received OCM notification: %+v", req) + + // this is to please Nextcloud + w.WriteHeader(http.StatusCreated) +} + +func getNotification(r *http.Request) (string, error) { // (*notificationRequest, error) + // var req notificationRequest + contentType, _, err := mime.ParseMediaType(r.Header.Get("Content-Type")) + if err == nil && contentType == "application/json" { + bytes, _ := io.ReadAll(r.Body) + return string(bytes), nil + // if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + // return nil, err + //} + // } else { + // return nil, errors.New("body request not recognised") + } + return "", nil + // validate the request + // if err := validate.Struct(req); err != nil { + // return nil, err + //} + // return &req, nil +} diff --git a/internal/http/services/ocmd/ocm.go b/internal/http/services/ocmd/ocm.go index 6f997baf70..8cbb4821a0 100644 --- a/internal/http/services/ocmd/ocm.go +++ b/internal/http/services/ocmd/ocm.go @@ -76,6 +76,7 @@ func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error) func (s *svc) routerInit() error { sharesHandler := new(sharesHandler) invitesHandler := new(invitesHandler) + notifHandler := new(notifHandler) if err := sharesHandler.init(s.Conf); err != nil { return err @@ -83,9 +84,13 @@ func (s *svc) routerInit() error { if err := invitesHandler.init(s.Conf); err != nil { return err } + if err := notifHandler.init(s.Conf); err != nil { + return err + } s.router.Post("/shares", sharesHandler.CreateShare) s.router.Post("/invite-accepted", invitesHandler.AcceptInvite) + s.router.Post("/notifications", notifHandler.Notifications) return nil } From cf88e9a8ca87dd4cb2d4172ef969368125256e34 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Mon, 19 Jun 2023 14:36:13 +0200 Subject: [PATCH 09/12] wopi: added logging for apps over OCM + fixed lookup --- pkg/app/provider/wopi/wopi.go | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/pkg/app/provider/wopi/wopi.go b/pkg/app/provider/wopi/wopi.go index 640e0319f2..29d07a7e7c 100644 --- a/pkg/app/provider/wopi/wopi.go +++ b/pkg/app/provider/wopi/wopi.go @@ -29,6 +29,7 @@ import ( "os" "path" "path/filepath" + "reflect" "strconv" "strings" "time" @@ -51,6 +52,7 @@ import ( "github.com/cs3org/reva/pkg/rhttp" "github.com/cs3org/reva/pkg/sharedconf" "github.com/cs3org/reva/pkg/utils" + gomime "github.com/glpatcern/go-mime" "github.com/golang-jwt/jwt" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" @@ -192,7 +194,7 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc ut = anonymous rPath, pathErr = getPathForExternalLink(ctx, scopes, resource, publicLinkURLPrefix) if pathErr != nil { - log.Warn().Err(pathErr).Msg("wopi: failed to extract relative path from public link scope") + log.Warn().Interface("resId", resource.Id).Interface("path", resource.Path).Err(pathErr).Msg("wopi: failed to extract relative path from public link scope") } case ocmrole: // OCM users have no username: use displayname@Idp @@ -201,7 +203,21 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc // and resolve the folder rPath, pathErr = getPathForExternalLink(ctx, scopes, resource, ocmLinkURLPrefix) if pathErr != nil { - log.Warn().Err(pathErr).Msg("wopi: failed to extract relative path from ocm link scope") + log.Warn().Interface("resId", resource.Id).Interface("path", resource.Path).Err(pathErr).Msg("wopi: failed to extract relative path from ocm link scope") + } + if ext == "" { + // this is a single-file share, and we have to re-resolve the extension from the mime type + exts := gomime.ExtensionsByType(resource.MimeType) + for _, e := range exts { + if len(e) < len(ext) || len(ext) == 0 { + ext = e // heuristically we know we want the shortest file extension + } + } + ext = "." + ext + log.Debug().Interface("mime", resource.MimeType).Interface("ext", ext).Msg("wopi: resolved extension for single-file OCM share") + } + if ext == "" { + return nil, errors.New("wopi: failed to resolve extension from OCM file's mime type %s" + resource.MimeType) } default: // in all other cases use the resource's path @@ -246,7 +262,7 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc q.Add("appurl", viewAppURL) } if q.Get("appurl") == "" && q.Get("appviewurl") == "" { - return nil, errors.New("wopi: neither edit nor view app url found") + return nil, errors.New("wopi: neither edit nor view app url found for type " + ext) } if p.conf.AppIntURL != "" { q.Add("appinturl", p.conf.AppIntURL) @@ -532,17 +548,17 @@ func getPathForExternalLink(ctx context.Context, scopes map[string]*authpb.Scope return "", err } - if statRes.Info.Path == resource.Path { + if statRes.Info.Path == resource.Path || reflect.DeepEqual(statRes.Info.Id, resource.Id) { // this is a direct link to the resource return pathPrefix + token, nil } - // otherwise we are in a subfolder of the public link + // otherwise we are in a subfolder of the link relPath, err := filepath.Rel(statRes.Info.Path, resource.Path) if err != nil { return "", err } if strings.HasPrefix(relPath, "../") { - return "", errors.New("Scope path does not contain target resource") + return "", errors.New("Scope path does not contain target resource path " + statRes.Info.Path) } return path.Join(pathPrefix+token, path.Dir(relPath)), nil } From 89e0b510cfc8dc9ddd5ac0720e340517b9d02eae Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Mon, 19 Jun 2023 18:28:04 +0200 Subject: [PATCH 10/12] Updated changelog --- changelog/unreleased/ocm-compat.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog/unreleased/ocm-compat.md b/changelog/unreleased/ocm-compat.md index d3541f3421..4198ad3563 100644 --- a/changelog/unreleased/ocm-compat.md +++ b/changelog/unreleased/ocm-compat.md @@ -1,6 +1,7 @@ -Bugfix: only expose paths on /ocm-provider +Bugfix: OCM-related compatibility fixes Following analysis of OC and NC code to access a remote share, we must expose paths and not full URIs on the /ocm-provider endpoint. +Also we fix a lookup issue with apps over OCM and update examples. https://github.com/cs3org/reva/pull/3962 From 8def72817060dcbf54bf3d38d82d3188e15573ad Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Tue, 20 Jun 2023 08:58:39 +0200 Subject: [PATCH 11/12] Removed /ocs-provider http service This service was introduced to test Nextcloud but it's not needed --- examples/meshdirectory/meshdirectory.toml | 1 - examples/nextcloud-integration/revad.toml | 2 - examples/ocmd/server-1/ocmd-server-1.toml | 2 - examples/ocmd/server-2/ocmd-server-2.toml | 2 - examples/standalone/standalone.toml | 1 - examples/storage-references/gateway.toml | 1 - examples/two-server-setup/gateway-1.toml | 1 - examples/two-server-setup/gateway-2.toml | 1 - internal/http/services/loader/loader.go | 1 - .../http/services/ocsprovider/ocsprovider.go | 131 ------------------ 10 files changed, 143 deletions(-) delete mode 100644 internal/http/services/ocsprovider/ocsprovider.go diff --git a/examples/meshdirectory/meshdirectory.toml b/examples/meshdirectory/meshdirectory.toml index 8373cefcc6..1bea8c36e0 100644 --- a/examples/meshdirectory/meshdirectory.toml +++ b/examples/meshdirectory/meshdirectory.toml @@ -25,7 +25,6 @@ file = "/var/tmp/reva/shares_server_1.json" [http.services.prometheus] [http.services.ocmd] [http.services.ocmprovider] -[http.services.ocsprovider] [http.services.ocdav] [http.services.ocs] diff --git a/examples/nextcloud-integration/revad.toml b/examples/nextcloud-integration/revad.toml index 717ae0d09c..97288f5cf8 100644 --- a/examples/nextcloud-integration/revad.toml +++ b/examples/nextcloud-integration/revad.toml @@ -135,8 +135,6 @@ webdav_root = "/remote.php/dav/ocm" enable_webapp = true enable_datatx = true -[http.services.ocsprovider] - [http.services.sciencemesh] mesh_directory_url = 'https://sciencemesh.cesnet.cz/iop/meshdir' provider_domain = 'your-domain.org' diff --git a/examples/ocmd/server-1/ocmd-server-1.toml b/examples/ocmd/server-1/ocmd-server-1.toml index d2d70b26e7..0d9adbf513 100644 --- a/examples/ocmd/server-1/ocmd-server-1.toml +++ b/examples/ocmd/server-1/ocmd-server-1.toml @@ -154,8 +154,6 @@ endpoint = "http://localhost:19001" enable_webapp = true enable_datatx = true -[http.services.ocsprovider] - [http.middlewares.providerauthorizer] driver = "json" diff --git a/examples/ocmd/server-2/ocmd-server-2.toml b/examples/ocmd/server-2/ocmd-server-2.toml index 3e859fffa2..755d00116e 100644 --- a/examples/ocmd/server-2/ocmd-server-2.toml +++ b/examples/ocmd/server-2/ocmd-server-2.toml @@ -145,8 +145,6 @@ endpoint = "http://localhost:17001" enable_webapp = true enable_datatx = true -[http.services.ocsprovider] - [http.middlewares.providerauthorizer] driver = "json" diff --git a/examples/standalone/standalone.toml b/examples/standalone/standalone.toml index 5c06973275..0b54edd841 100644 --- a/examples/standalone/standalone.toml +++ b/examples/standalone/standalone.toml @@ -18,6 +18,5 @@ [http.services.prometheus] [http.services.ocmd] [http.services.ocmprovider] -[http.services.ocsprovider] [http.services.ocdav] [http.services.ocs] diff --git a/examples/storage-references/gateway.toml b/examples/storage-references/gateway.toml index 71be7f6e76..0cbed478ae 100644 --- a/examples/storage-references/gateway.toml +++ b/examples/storage-references/gateway.toml @@ -58,7 +58,6 @@ app_url = "https://your-collabora-server.org:9980" [http.services.prometheus] [http.services.ocmd] [http.services.ocmprovider] -[http.services.ocsprovider] [http.services.ocdav] [http.services.ocs] diff --git a/examples/two-server-setup/gateway-1.toml b/examples/two-server-setup/gateway-1.toml index f89a70de87..6421454da3 100644 --- a/examples/two-server-setup/gateway-1.toml +++ b/examples/two-server-setup/gateway-1.toml @@ -101,7 +101,6 @@ endpoint = "http://localhost:19001" enable_webapp = true enable_datatx = true -[http.services.ocsprovider] [http.services.ocdav] [http.services.ocs] [http.services.sciencemesh] diff --git a/examples/two-server-setup/gateway-2.toml b/examples/two-server-setup/gateway-2.toml index 098c36f139..65aa63a30f 100644 --- a/examples/two-server-setup/gateway-2.toml +++ b/examples/two-server-setup/gateway-2.toml @@ -102,7 +102,6 @@ enable_webapp = true enable_datatx = true [http.services.ocdav] -[http.services.ocsprovider] [http.services.ocs] [http.services.sciencemesh] diff --git a/internal/http/services/loader/loader.go b/internal/http/services/loader/loader.go index 0c1064547b..adf1ad02da 100644 --- a/internal/http/services/loader/loader.go +++ b/internal/http/services/loader/loader.go @@ -30,7 +30,6 @@ import ( _ "github.com/cs3org/reva/internal/http/services/metrics" _ "github.com/cs3org/reva/internal/http/services/ocmd" _ "github.com/cs3org/reva/internal/http/services/ocmprovider" - _ "github.com/cs3org/reva/internal/http/services/ocsprovider" _ "github.com/cs3org/reva/internal/http/services/owncloud/ocdav" _ "github.com/cs3org/reva/internal/http/services/owncloud/ocs" _ "github.com/cs3org/reva/internal/http/services/preferences" diff --git a/internal/http/services/ocsprovider/ocsprovider.go b/internal/http/services/ocsprovider/ocsprovider.go deleted file mode 100644 index 162f7574c2..0000000000 --- a/internal/http/services/ocsprovider/ocsprovider.go +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2018-2023 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 ocsprovider - -import ( - "encoding/json" - "net/http" - - "github.com/cs3org/reva/pkg/appctx" - "github.com/cs3org/reva/pkg/rhttp/global" - "github.com/mitchellh/mapstructure" - "github.com/rs/zerolog" -) - -func init() { - global.Register("ocsprovider", New) -} - -type config struct { - WebdavRoot string `mapstructure:"webdav_root" docs:"/remote.php/dav/ocm;The root URL of the WebDAV endpoint to serve OCM shares."` -} - -type ocsDiscoveryData struct { - Version int `json:"version"` - Services ocsServices `json:"services"` -} - -type ocsServices struct { - PrivateData map[string]any `json:"PRIVATE_DATA"` - Sharing map[string]any `json:"SHARING"` - FederatedSharing map[string]any `json:"FEDERATED_SHARING"` - Provisioning map[string]any `json:"PROVISIONING"` -} - -type svc struct { - data *ocsDiscoveryData -} - -func (c *config) init() { - if c.WebdavRoot == "" { - // same default as for the /ocm-provider discovery service - c.WebdavRoot = "/remote.php/dav/ocm/" - } - if c.WebdavRoot[len(c.WebdavRoot)-1:] != "/" { - c.WebdavRoot += "/" - } -} - -func (c *config) prepare() *ocsDiscoveryData { - // generates a minimal static data structure to be exposed by /ocs-provider - d := &ocsDiscoveryData{} - d.Version = 2 - d.Services = ocsServices{ - PrivateData: map[string]any{ - "version": 1, - "endpoints": map[string]any{}, - }, - Sharing: map[string]any{ - "version": 1, - "endpoints": map[string]any{}, - }, - FederatedSharing: map[string]any{ - "version": 1, - "endpoints": map[string]string{ - "share": c.WebdavRoot, - "webdav": c.WebdavRoot, - }, - }, - Provisioning: map[string]any{ - "version": 1, - "endpoints": map[string]any{}, - }, - } - return d -} - -// New returns a new ocsprovider object, that implements -// a minimal OCS discovery endpoint similar to OC10 or NC. -// OCS specs are defined at: -// https://www.freedesktop.org/wiki/Specifications/open-collaboration-services -func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error) { - conf := &config{} - if err := mapstructure.Decode(m, conf); err != nil { - return nil, err - } - - conf.init() - return &svc{data: conf.prepare()}, nil -} - -// Close performs cleanup. -func (s *svc) Close() error { - return nil -} - -func (s *svc) Prefix() string { - // this is hardcoded as per OCS specifications - return "/ocs-provider" -} - -func (s *svc) Unprotected() []string { - return []string{"/"} -} - -func (s *svc) Handler() http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - log := appctx.GetLogger(r.Context()) - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - indented, _ := json.MarshalIndent(s.data, "", " ") - if _, err := w.Write(indented); err != nil { - log.Err(err).Msg("Error writing to ResponseWriter") - } - }) -} From 85771961619f187fcb578fe84f08a787a2060612 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Tue, 20 Jun 2023 13:40:46 +0200 Subject: [PATCH 12/12] Addressed comment --- pkg/app/provider/wopi/wopi.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/app/provider/wopi/wopi.go b/pkg/app/provider/wopi/wopi.go index 29d07a7e7c..b3bfd46415 100644 --- a/pkg/app/provider/wopi/wopi.go +++ b/pkg/app/provider/wopi/wopi.go @@ -29,7 +29,6 @@ import ( "os" "path" "path/filepath" - "reflect" "strconv" "strings" "time" @@ -548,7 +547,7 @@ func getPathForExternalLink(ctx context.Context, scopes map[string]*authpb.Scope return "", err } - if statRes.Info.Path == resource.Path || reflect.DeepEqual(statRes.Info.Id, resource.Id) { + if statRes.Info.Path == resource.Path || utils.ResourceIDEqual(statRes.Info.Id, resource.Id) { // this is a direct link to the resource return pathPrefix + token, nil }