mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-12 08:37:38 +02:00
fix redirect loop, remove user/session services, remove duplicate deleted_at fields (#1162)
* fix redirect loop, remove user/session services, remove duplicate deleted_at fields * change loop * reuse err variable * wrap errors, use cookie timeout * wrap error, duplicate if
This commit is contained in:
parent
714363fb07
commit
97f85481f8
16 changed files with 288 additions and 918 deletions
|
@ -3,12 +3,27 @@ package session
|
|||
|
||||
import (
|
||||
context "context"
|
||||
"fmt"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
|
||||
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
||||
)
|
||||
|
||||
// Delete deletes a session from the databroker.
|
||||
func Delete(ctx context.Context, client databroker.DataBrokerServiceClient, sessionID string) error {
|
||||
any, _ := ptypes.MarshalAny(new(Session))
|
||||
_, err := client.Delete(ctx, &databroker.DeleteRequest{
|
||||
Type: any.GetTypeUrl(),
|
||||
Id: sessionID,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("error deleting session: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get gets a session from the databroker.
|
||||
func Get(ctx context.Context, client databroker.DataBrokerServiceClient, sessionID string) (*Session, error) {
|
||||
any, _ := ptypes.MarshalAny(new(Session))
|
||||
|
@ -18,13 +33,27 @@ func Get(ctx context.Context, client databroker.DataBrokerServiceClient, session
|
|||
Id: sessionID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("error getting session from databroker: %w", err)
|
||||
}
|
||||
|
||||
var s Session
|
||||
err = ptypes.UnmarshalAny(res.GetRecord().GetData(), &s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("error unmarshaling session from databroker: %w", err)
|
||||
}
|
||||
return &s, nil
|
||||
}
|
||||
|
||||
// Set sets a session in the databroker.
|
||||
func Set(ctx context.Context, client databroker.DataBrokerServiceClient, s *Session) (*databroker.SetResponse, error) {
|
||||
any, _ := anypb.New(s)
|
||||
res, err := client.Set(ctx, &databroker.SetRequest{
|
||||
Type: any.GetTypeUrl(),
|
||||
Id: s.Id,
|
||||
Data: any,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error setting session in databroker: %w", err)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue