From b85fbde28571f2c17a72a685d711b84139ace155 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Thu, 6 Jul 2023 17:44:41 +0200 Subject: [PATCH] Added /app/notify endpoint for logging/tracking apps (#4044) --- changelog/unreleased/app-notif.md | 7 ++++ .../http/services/appprovider/appprovider.go | 37 +++++++++++++++++++ pkg/app/provider/wopi/wopi.go | 1 - 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/app-notif.md diff --git a/changelog/unreleased/app-notif.md b/changelog/unreleased/app-notif.md new file mode 100644 index 0000000000..f40064a213 --- /dev/null +++ b/changelog/unreleased/app-notif.md @@ -0,0 +1,7 @@ +Enhancement: added an /app/notify endpoint for logging/tracking apps + +The new endpoint serves to probe the health state of apps such as +Microsoft Office Online, and it is expected to be called by the frontend +upon successful loading of the document by the underlying app + +https://github.com/cs3org/reva/pull/4044 diff --git a/internal/http/services/appprovider/appprovider.go b/internal/http/services/appprovider/appprovider.go index c57d9fbc78..c094b11b39 100644 --- a/internal/http/services/appprovider/appprovider.go +++ b/internal/http/services/appprovider/appprovider.go @@ -29,6 +29,7 @@ import ( provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" "github.com/cs3org/reva/internal/http/services/datagateway" + "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/rgrpc/status" "github.com/cs3org/reva/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/pkg/rhttp" @@ -91,6 +92,7 @@ func (s *svc) routerInit() error { s.router.Get("/list", s.handleList) s.router.Post("/new", s.handleNew) s.router.Post("/open", s.handleOpen) + s.router.Post("/notify", s.handleNotify) return nil } @@ -419,6 +421,9 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) { return } + log := appctx.GetLogger(ctx) + log.Info().Str("url", openRes.AppUrl.AppUrl).Interface("resource", fileRef).Msg("returning app URL for file") + w.Header().Set("Content-Type", "application/json") if _, err = w.Write(js); err != nil { writeError(w, r, appErrorServerError, "Internal error with JSON payload", @@ -427,6 +432,38 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) { } } +func (s *svc) handleNotify(w http.ResponseWriter, r *http.Request) { + err := r.ParseForm() + if err != nil { + writeError(w, r, appErrorInvalidParameter, "parameters could not be parsed", nil) + } + + fileID := r.Form.Get("file_id") + var fileRef provider.Reference + if fileID == "" { + path := r.Form.Get("path") + if path == "" { + writeError(w, r, appErrorInvalidParameter, "missing file ID or path", nil) + return + } + fileRef.Path = path + } else { + resourceID := resourceid.OwnCloudResourceIDUnwrap(fileID) + if resourceID == nil { + writeError(w, r, appErrorInvalidParameter, "invalid file ID", nil) + return + } + fileRef.ResourceId = resourceID + } + + // log the fileid for later correlation / monitoring + ctx := r.Context() + log := appctx.GetLogger(ctx) + log.Info().Interface("resource", fileRef).Msg("file successfully opened in app") + + w.WriteHeader(http.StatusOK) +} + func filterAppsByUserAgent(mimeTypes []*appregistry.MimeTypeInfo, userAgent string) []*appregistry.MimeTypeInfo { ua := ua.Parse(userAgent) res := []*appregistry.MimeTypeInfo{} diff --git a/pkg/app/provider/wopi/wopi.go b/pkg/app/provider/wopi/wopi.go index b3bfd46415..d4bbc58778 100644 --- a/pkg/app/provider/wopi/wopi.go +++ b/pkg/app/provider/wopi/wopi.go @@ -338,7 +338,6 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc } } - log.Info().Str("url", appFullURL).Str("resource", resource.Path).Msg("wopi: returning URL for file") return &appprovider.OpenInAppURL{ AppUrl: appFullURL, Method: method,