Skip to content

Commit

Permalink
SpaceMembershipExpired event
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <[email protected]>
  • Loading branch information
kobergj committed Jan 10, 2023
1 parent eedd22c commit 64f47dc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/events/sharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (ShareUpdated) Unmarshal(v []byte) (interface{}, error) {
return e, err
}

// ShareExpired is emitted when a share is removed
// ShareExpired is emitted when a share expires
type ShareExpired struct {
ShareOwner *user.UserId
ItemID *provider.ResourceId
Expand Down
19 changes: 19 additions & 0 deletions pkg/events/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package events

import (
"encoding/json"
"time"

group "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1"
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
Expand Down Expand Up @@ -145,3 +146,21 @@ func (SpaceUpdated) Unmarshal(v []byte) (interface{}, error) {
err := json.Unmarshal(v, &e)
return e, err
}

// SpaceMembershipExpired is emitted when a space membership expires
type SpaceMembershipExpired struct {
SpaceOwner *user.UserId
SpaceID string
SpaceName string
ExpiredAt time.Time
// split the protobuf Grantee oneof so we can use stdlib encoding/json
GranteeUserID *user.UserId
GranteeGroupID *group.GroupId
}

// Unmarshal to fulfill umarshaller interface
func (SpaceMembershipExpired) Unmarshal(v []byte) (interface{}, error) {
e := ShareExpired{}
err := json.Unmarshal(v, &e)
return e, err
}
6 changes: 3 additions & 3 deletions pkg/utils/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func Impersonate(userID *user.UserId, gwc gateway.GatewayAPIClient, machineAuthA
}

// Get auth context
ownerCtx := revactx.ContextSetUser(context.Background(), getUserResponse.User)
authRes, err := gwc.Authenticate(ownerCtx, &gateway.AuthenticateRequest{
ctx := revactx.ContextSetUser(context.Background(), getUserResponse.User)
authRes, err := gwc.Authenticate(ctx, &gateway.AuthenticateRequest{
Type: "machine",
ClientId: "userid:" + userID.OpaqueId,
ClientSecret: machineAuthAPIKey,
Expand All @@ -37,5 +37,5 @@ func Impersonate(userID *user.UserId, gwc gateway.GatewayAPIClient, machineAuthA
return nil, nil, fmt.Errorf("error impersonating user: %s", authRes.Status.Message)
}

return metadata.AppendToOutgoingContext(context.Background(), revactx.TokenHeader, authRes.Token), authRes.GetUser(), nil
return metadata.AppendToOutgoingContext(ctx, revactx.TokenHeader, authRes.Token), authRes.GetUser(), nil
}

0 comments on commit 64f47dc

Please sign in to comment.