Skip to content

Commit 2026acd

Browse files
committed
ocm: simplified error handling (#4810)
1 parent bd28801 commit 2026acd

File tree

7 files changed

+26
-27
lines changed

7 files changed

+26
-27
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Bugfix: simplified error handling
2+
3+
Minor rewording and simplification, following cs3org/OCM-API#90 and cs3org/OCM-API#91
4+
5+
https://github.com/cs3org/reva/pull/4810

internal/grpc/services/ocminvitemanager/ocminvitemanager.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,7 @@ func (s *service) ForwardInvite(ctx context.Context, req *invitepb.ForwardInvite
174174
switch {
175175
case errors.Is(err, ocmd.ErrTokenInvalid):
176176
return &invitepb.ForwardInviteResponse{
177-
Status: status.NewInvalid(ctx, "token not valid"),
178-
}, nil
179-
case errors.Is(err, ocmd.ErrTokenNotFound):
180-
return &invitepb.ForwardInviteResponse{
181-
Status: status.NewNotFound(ctx, "token not found"),
177+
Status: status.NewInvalid(ctx, "token invalid or not found"),
182178
}, nil
183179
case errors.Is(err, ocmd.ErrUserAlreadyAccepted):
184180
return &invitepb.ForwardInviteResponse{
@@ -240,7 +236,7 @@ func (s *service) AcceptInvite(ctx context.Context, req *invitepb.AcceptInviteRe
240236
if err != nil {
241237
if errors.Is(err, invite.ErrTokenNotFound) {
242238
return &invitepb.AcceptInviteResponse{
243-
Status: status.NewNotFound(ctx, "token not found"),
239+
Status: status.NewInvalid(ctx, "token invalid or not found"),
244240
}, nil
245241
}
246242
return &invitepb.AcceptInviteResponse{
@@ -250,7 +246,7 @@ func (s *service) AcceptInvite(ctx context.Context, req *invitepb.AcceptInviteRe
250246

251247
if !isTokenValid(token) {
252248
return &invitepb.AcceptInviteResponse{
253-
Status: status.NewInvalid(ctx, "token is not valid"),
249+
Status: status.NewInvalid(ctx, "token invalid or not found"),
254250
}, nil
255251
}
256252

internal/http/services/experimental/sciencemesh/token.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,15 @@ func (h *tokenHandler) AcceptInvite(w http.ResponseWriter, r *http.Request) {
178178
if forwardInviteResponse.Status.Code != rpc.Code_CODE_OK {
179179
switch forwardInviteResponse.Status.Code {
180180
case rpc.Code_CODE_NOT_FOUND:
181-
reqres.WriteError(w, r, reqres.APIErrorNotFound, "token not found", nil)
182-
return
181+
fallthrough
183182
case rpc.Code_CODE_INVALID_ARGUMENT:
184-
reqres.WriteError(w, r, reqres.APIErrorInvalidParameter, "token has expired", nil)
183+
reqres.WriteError(w, r, reqres.APIErrorInvalidParameter, "invalid or non existing token", nil)
185184
return
186185
case rpc.Code_CODE_ALREADY_EXISTS:
187-
reqres.WriteError(w, r, reqres.APIErrorAlreadyExist, "user already known", nil)
186+
reqres.WriteError(w, r, reqres.APIErrorAlreadyExist, "invitation already accepted", nil)
188187
return
189188
case rpc.Code_CODE_PERMISSION_DENIED:
190-
reqres.WriteError(w, r, reqres.APIErrorUnauthenticated, "remove service not trusted", nil)
189+
reqres.WriteError(w, r, reqres.APIErrorUnauthenticated, "remote service not trusted", nil)
191190
return
192191
default:
193192
reqres.WriteError(w, r, reqres.APIErrorServerError, "unexpected error: "+forwardInviteResponse.Status.Message, errors.New(forwardInviteResponse.Status.Message))

internal/http/services/opencloudmesh/ocmd/client.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,16 @@ import (
3535
)
3636

3737
// ErrTokenInvalid is the error returned by the invite-accepted
38-
// endpoint when the token is not valid.
39-
var ErrTokenInvalid = errors.New("the invitation token is invalid")
38+
// endpoint when the token is not valid or not existing.
39+
var ErrTokenInvalid = errors.New("the invitation token is invalid or not found")
4040

4141
// ErrServiceNotTrusted is the error returned by the invite-accepted
4242
// endpoint when the service is not trusted to accept invitations.
4343
var ErrServiceNotTrusted = errors.New("service is not trusted to accept invitations")
4444

4545
// ErrUserAlreadyAccepted is the error returned by the invite-accepted
46-
// endpoint when a user is already know by the remote cloud.
47-
var ErrUserAlreadyAccepted = errors.New("user already accepted an invitation token")
48-
49-
// ErrTokenNotFound is the error returned by the invite-accepted
50-
// endpoint when the request is done using a not existing token.
51-
var ErrTokenNotFound = errors.New("token not found")
46+
// endpoint when a token was already used by a user in the remote cloud.
47+
var ErrUserAlreadyAccepted = errors.New("invitation already accepted")
5248

5349
// ErrInvalidParameters is the error returned by the shares endpoint
5450
// when the request does not contain required properties.
@@ -250,8 +246,6 @@ func (c *OCMClient) parseInviteAcceptedResponse(r *http.Response) (*User, error)
250246
return &u, nil
251247
case http.StatusBadRequest:
252248
return nil, ErrTokenInvalid
253-
case http.StatusNotFound:
254-
return nil, ErrTokenNotFound
255249
case http.StatusConflict:
256250
return nil, ErrUserAlreadyAccepted
257251
case http.StatusForbidden:

internal/http/services/opencloudmesh/ocmd/shares.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,15 @@ func getResourceTypeFromOCMRequest(t string) providerpb.ResourceType {
249249
}
250250

251251
func getOCMShareType(t string) ocm.ShareType {
252-
if t == "user" {
252+
switch t {
253+
case "user":
254+
return ocm.ShareType_SHARE_TYPE_USER
255+
case "group":
256+
return ocm.ShareType_SHARE_TYPE_GROUP
257+
default:
258+
// for now assume user share if not provided
253259
return ocm.ShareType_SHARE_TYPE_USER
254260
}
255-
return ocm.ShareType_SHARE_TYPE_GROUP
256261
}
257262

258263
func getAndResolveProtocols(p Protocols, r *http.Request) ([]*ocm.Protocol, error) {

tests/integration/grpc/ocm_invitation_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ var _ = Describe("ocm invitation workflow", func() {
262262
})
263263
})
264264

265-
Describe("marie accept a not existing token", func() {
265+
Describe("marie accept a non existing token", func() {
266266
var cleanup func()
267267
BeforeEach(func() {
268268
variables, cleanup, err = initData(driver, nil, nil)
@@ -276,12 +276,12 @@ var _ = Describe("ocm invitation workflow", func() {
276276
It("will not complete the invitation workflow", func() {
277277
forwardRes, err := cesnetgw.ForwardInvite(ctxMarie, &invitepb.ForwardInviteRequest{
278278
InviteToken: &invitepb.InviteToken{
279-
Token: "not-existing-token",
279+
Token: "non-existing-token",
280280
},
281281
OriginSystemProvider: cernbox,
282282
})
283283
Expect(err).ToNot(HaveOccurred())
284-
Expect(forwardRes.Status.Code).To(Equal(rpc.Code_CODE_NOT_FOUND))
284+
Expect(forwardRes.Status.Code).To(Equal(rpc.Code_CODE_INVALID_ARGUMENT))
285285
})
286286
})
287287

0 commit comments

Comments
 (0)