diff --git a/changelog/unreleased/improve-ocmd-error-logs.md b/changelog/unreleased/improve-ocmd-error-logs.md new file mode 100644 index 0000000000..5f6271cc15 --- /dev/null +++ b/changelog/unreleased/improve-ocmd-error-logs.md @@ -0,0 +1,5 @@ +Enhancement: Improve error logging in ocmd flow + +https://github.com/cs3org/reva/pull/3419 +https://github.com/cs3org/reva/issues/3365 +https://github.com/cs3org/reva/pull/3369 diff --git a/internal/grpc/services/ocminvitemanager/ocminvitemanager.go b/internal/grpc/services/ocminvitemanager/ocminvitemanager.go index 6821f7d29e..d2b374346a 100644 --- a/internal/grpc/services/ocminvitemanager/ocminvitemanager.go +++ b/internal/grpc/services/ocminvitemanager/ocminvitemanager.go @@ -119,7 +119,7 @@ func (s *service) ForwardInvite(ctx context.Context, req *invitepb.ForwardInvite err := s.im.ForwardInvite(ctx, req.InviteToken, req.OriginSystemProvider) if err != nil { return &invitepb.ForwardInviteResponse{ - Status: status.NewInternal(ctx, err, "error forwarding invite"), + Status: status.NewInternal(ctx, err, "error forwarding invite:"+err.Error()), }, nil } @@ -159,7 +159,7 @@ func (s *service) FindAcceptedUsers(ctx context.Context, req *invitepb.FindAccep acceptedUsers, err := s.im.FindAcceptedUsers(ctx, req.Filter) if err != nil { return &invitepb.FindAcceptedUsersResponse{ - Status: status.NewInternal(ctx, err, "error finding remote users"), + Status: status.NewInternal(ctx, err, "error finding remote users: "+err.Error()), }, nil } diff --git a/internal/http/services/ocmd/invites.go b/internal/http/services/ocmd/invites.go index 9f6d27bc07..7786fa4ffa 100644 --- a/internal/http/services/ocmd/invites.go +++ b/internal/http/services/ocmd/invites.go @@ -315,6 +315,7 @@ func (h *invitesHandler) findAcceptedUsers(w http.ResponseWriter, r *http.Reques indentedResponse, _ := json.MarshalIndent(response, "", " ") w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) + log.Debug().Msg("findAcceptedUsers json response: " + string(indentedResponse)) if _, err := w.Write(indentedResponse); err != nil { log.Err(err).Msg("Error writing to ResponseWriter") } diff --git a/internal/http/services/ocmd/send.go b/internal/http/services/ocmd/send.go index d0106abed3..5914a78e04 100644 --- a/internal/http/services/ocmd/send.go +++ b/internal/http/services/ocmd/send.go @@ -110,13 +110,13 @@ func (h *sendHandler) Handler() http.Handler { req := &provider.StatRequest{Ref: ref} res2, err := gatewayClient.Stat(authCtx, req) if err != nil { - log.Error().Msg("error sending: stat file/folder to share") + log.Error().Msg("gatewayClient.Stat operation failed; is the storage backend reachable?") w.WriteHeader(http.StatusInternalServerError) return } if res2.Status.Code != rpc.Code_CODE_OK { - log.Error().Msg("error returned: stat file/folder to share") + log.Error().Msgf("sourcePath %s does not exist on the storage backend", sourcePath) w.WriteHeader(http.StatusInternalServerError) return } diff --git a/pkg/auth/manager/nextcloud/nextcloud.go b/pkg/auth/manager/nextcloud/nextcloud.go index 5d01d264b1..6932b5a7b7 100644 --- a/pkg/auth/manager/nextcloud/nextcloud.go +++ b/pkg/auth/manager/nextcloud/nextcloud.go @@ -22,8 +22,10 @@ package nextcloud import ( "context" "encoding/json" + "fmt" "io" "net/http" + "strconv" "strings" authpb "github.com/cs3org/go-cs3apis/cs3/auth/provider/v1beta1" @@ -141,6 +143,9 @@ func (am *Manager) do(ctx context.Context, a Action) (int, []byte, error) { } log.Info().Msgf("am.do response %d %s", resp.StatusCode, body) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { + return 0, nil, fmt.Errorf("Unexpected response code from EFSS API: " + strconv.Itoa(resp.StatusCode)) + } return resp.StatusCode, body, nil } diff --git a/pkg/ocm/share/manager/nextcloud/nextcloud.go b/pkg/ocm/share/manager/nextcloud/nextcloud.go index 57ce41d7be..5dda9d70d1 100644 --- a/pkg/ocm/share/manager/nextcloud/nextcloud.go +++ b/pkg/ocm/share/manager/nextcloud/nextcloud.go @@ -22,15 +22,18 @@ package nextcloud import ( "context" "encoding/json" + "fmt" "io" "math/rand" "net/http" + "strconv" "strings" "time" userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" ctxpkg "github.com/cs3org/reva/pkg/ctx" "github.com/cs3org/reva/pkg/utils" + "github.com/google/uuid" ocmprovider "github.com/cs3org/go-cs3apis/cs3/ocm/provider/v1beta1" ocm "github.com/cs3org/go-cs3apis/cs3/sharing/ocm/v1beta1" @@ -62,6 +65,10 @@ func init() { registry.Register("nextcloud", New) } +func genID() string { + return uuid.New().String() +} + // Manager is the Nextcloud-based implementation of the share.Manager interface // see https://github.com/cs3org/reva/blob/v1.13.0/pkg/ocm/share/share.go#L30-L57 type Manager struct { @@ -210,6 +217,10 @@ func (sm *Manager) do(ctx context.Context, a Action, username string) (int, []by // curl -i -H 'application/json' -H 'X-Reva-Secret: shared-secret-1' -d '{"md":{"opaque_id":"fileid-/other/q/as"},"g":{"grantee":{"type":1,"Id":{"UserId":{"idp":"revanc2.docker","opaque_id":"marie"}}},"permissions":{"permissions":{"get_path":true,"initiate_file_download":true,"list_container":true,"list_file_versions":true,"stat":true}}},"provider_domain":"cern.ch","resource_type":"file","provider_id":2,"owner_opaque_id":"einstein","owner_display_name":"Albert Einstein","protocol":{"name":"webdav","options":{"sharedSecret":"secret","permissions":"webdav-property"}}}' https://nc1.docker/index.php/apps/sciencemesh/~/api/ocm/addSentShare log.Info().Msgf("am.do response %d %s", resp.StatusCode, body) + + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { + return 0, nil, fmt.Errorf("Unexpected response code from EFSS API: " + strconv.Itoa(resp.StatusCode)) + } return resp.StatusCode, body, nil } @@ -255,13 +266,26 @@ func (sm *Manager) Share(ctx context.Context, md *provider.ResourceId, g *ocm.Sh return nil, errors.New("nextcloud: user and grantee are the same") } + // fixme: this should come from the EFSS backend + id := genID() + now := time.Now().UnixNano() + ts := &typespb.Timestamp{ + Seconds: uint64(now / 1000000000), + Nanos: uint32(now % 1000000000), + } + s := &ocm.Share{ + Id: &ocm.ShareId{ + OpaqueId: id, + }, Name: name, ResourceId: md, Permissions: g.Permissions, Grantee: g.Grantee, Owner: userID, Creator: userID, + Ctime: ts, + Mtime: ts, ShareType: st, } @@ -311,16 +335,13 @@ func (sm *Manager) Share(ctx context.Context, md *provider.ResourceId, g *ocm.Sh } } - _, body, err := sm.do(ctx, Action{apiMethod, string(encShare)}, username) + _, _, err = sm.do(ctx, Action{apiMethod, string(encShare)}, username) + // FIXME: this should set the id of the share + // _, body, err := sm.do(ctx, Action{apiMethod, string(encShare)}, username) - s.Id = &ocm.ShareId{ - OpaqueId: string(body), - } - now := time.Now().UnixNano() - s.Ctime = &typespb.Timestamp{ - Seconds: uint64(now / 1000000000), - Nanos: uint32(now % 1000000000), - } + // s.Id = &ocm.ShareId{ + // OpaqueId: string(body), + // } if err != nil { return nil, err } diff --git a/pkg/storage/fs/nextcloud/nextcloud.go b/pkg/storage/fs/nextcloud/nextcloud.go index 71c3617373..5d69e2a6f8 100644 --- a/pkg/storage/fs/nextcloud/nextcloud.go +++ b/pkg/storage/fs/nextcloud/nextcloud.go @@ -25,6 +25,7 @@ import ( "io" "net/http" "net/url" + "strconv" "strings" user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" @@ -229,7 +230,9 @@ func (nc *StorageDriver) do(ctx context.Context, a Action) (int, []byte, error) return 0, nil, err } log.Info().Msgf("nc.do res %s %s", url, string(body)) - + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { + return 0, nil, fmt.Errorf("Unexpected response code from EFSS API: " + strconv.Itoa(resp.StatusCode)) + } return resp.StatusCode, body, nil } diff --git a/pkg/user/manager/nextcloud/nextcloud.go b/pkg/user/manager/nextcloud/nextcloud.go index f425fc3300..782681d08b 100644 --- a/pkg/user/manager/nextcloud/nextcloud.go +++ b/pkg/user/manager/nextcloud/nextcloud.go @@ -24,6 +24,7 @@ import ( "fmt" "io" "net/http" + "strconv" "strings" ctxpkg "github.com/cs3org/reva/pkg/ctx" @@ -141,6 +142,9 @@ func (um *Manager) do(ctx context.Context, a Action, username string) (int, []by defer resp.Body.Close() body, err := io.ReadAll(resp.Body) + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { + return 0, nil, fmt.Errorf("Unexpected response code from EFSS API: " + strconv.Itoa(resp.StatusCode)) + } return resp.StatusCode, body, err }