Skip to content

Commit

Permalink
link accessed and access failed events
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <[email protected]>
  • Loading branch information
kobergj committed Mar 10, 2022
1 parent e395e77 commit bfa4b8a
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 4 deletions.
25 changes: 25 additions & 0 deletions internal/grpc/interceptors/eventsmiddleware/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,31 @@ func LinkUpdated(r *link.UpdatePublicShareResponse, req *link.UpdatePublicShareR
}
}

// LinkAccessed converts the response to an event
func LinkAccessed(r *link.GetPublicShareByTokenResponse) events.LinkAccessed {
return events.LinkAccessed{
ShareID: r.Share.Id,
Sharer: r.Share.Creator,
ItemID: r.Share.ResourceId,
Permissions: r.Share.Permissions,
DisplayName: r.Share.DisplayName,
Expiration: r.Share.Expiration,
PasswordProtected: r.Share.PasswordProtected,
CTime: r.Share.Ctime,
Token: r.Share.Token,
}
}

// LinkAccessFailed converts the response to an event
func LinkAccessFailed(r *link.GetPublicShareByTokenResponse, req *link.GetPublicShareByTokenRequest) events.LinkAccessFailed {
return events.LinkAccessFailed{
ShareID: r.Share.Id,
Token: r.Share.Token,
Status: r.Status.Code,
Message: r.Status.Message,
}
}

// LinkRemoved converts the response to an event
func LinkRemoved(r *link.RemovePublicShareResponse, req *link.RemovePublicShareRequest) events.LinkRemoved {
return events.LinkRemoved{
Expand Down
17 changes: 17 additions & 0 deletions internal/grpc/interceptors/eventsmiddleware/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error
if isSuccess(v) {
ev = LinkRemoved(v, req.(*link.RemovePublicShareRequest))
}
case *link.GetPublicShareByTokenResponse:
switch v.Status.Code {
case rpc.Code_CODE_OK:
ev = LinkAccessed(v)
case rpc.Code_CODE_NOT_FOUND:
// in this case the URL from the link is misspelled. Do we want to track this?
case rpc.Code_CODE_PERMISSION_DENIED:
// clients are currently checking for password protection by sending a request without password
// so logging this would spam the event bus unneccessarily
// as soon as clients have a better way to make this check we can remove this case
if v.Status.Message == "wrong password" {
ev = LinkAccessFailed(v, req.(*link.GetPublicShareByTokenRequest))
}
default:
ev = LinkAccessFailed(v, req.(*link.GetPublicShareByTokenRequest))

}
}

if ev != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/events/example/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func Example(c events.Consumer) {
events.LinkCreated{},
events.LinkUpdated{},
events.LinkRemoved{},
events.LinkAccessed{},
}

// Step 3 - create event channel
Expand Down
41 changes: 37 additions & 4 deletions pkg/events/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

group "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1"
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
Expand Down Expand Up @@ -112,10 +113,7 @@ type LinkCreated struct {
Expiration *types.Timestamp
PasswordProtected bool
CTime *types.Timestamp

// TODO: are we sure we want to send the token via event-bus? Imho this is a major security issue:
// Eveybody who has access to the event bus can access the file
Token string
Token string
}

// Unmarshal to fulfill umarshaller interface
Expand Down Expand Up @@ -147,6 +145,41 @@ func (LinkUpdated) Unmarshal(v []byte) (interface{}, error) {
return e, err
}

// LinkAccessed is emitted when a public link is accessed successfully (by token)
type LinkAccessed struct {
ShareID *link.PublicShareId
Sharer *user.UserId
ItemID *provider.ResourceId
Permissions *link.PublicSharePermissions
DisplayName string
Expiration *types.Timestamp
PasswordProtected bool
CTime *types.Timestamp
Token string
}

// Unmarshal to fulfill umarshaller interface
func (LinkAccessed) Unmarshal(v []byte) (interface{}, error) {
e := LinkAccessed{}
err := json.Unmarshal(v, &e)
return e, err
}

// LinkAccessFailed is emitted when an access to a public link has resulted in an error (by token)
type LinkAccessFailed struct {
ShareID *link.PublicShareId
Token string
Status rpc.Code
Message string
}

// Unmarshal to fulfill umarshaller interface
func (LinkAccessFailed) Unmarshal(v []byte) (interface{}, error) {
e := LinkAccessFailed{}
err := json.Unmarshal(v, &e)
return e, err
}

// LinkRemoved is emitted when a share is removed
type LinkRemoved struct {
// split protobuf Ref
Expand Down

0 comments on commit bfa4b8a

Please sign in to comment.