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:
Caleb Doxsey 2020-07-30 09:41:57 -06:00 committed by GitHub
parent 714363fb07
commit 97f85481f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 288 additions and 918 deletions

View file

@ -3,8 +3,10 @@ package user
import (
context "context"
"fmt"
"github.com/golang/protobuf/ptypes"
"google.golang.org/protobuf/types/known/anypb"
"github.com/pomerium/pomerium/internal/protoutil"
"github.com/pomerium/pomerium/pkg/grpc/databroker"
@ -19,13 +21,13 @@ func Get(ctx context.Context, client databroker.DataBrokerServiceClient, userID
Id: userID,
})
if err != nil {
return nil, err
return nil, fmt.Errorf("error getting user from databroker: %w", err)
}
var u User
err = ptypes.UnmarshalAny(res.GetRecord().GetData(), &u)
if err != nil {
return nil, err
return nil, fmt.Errorf("error unmarshaling user from databroker: %w", err)
}
return &u, nil
}
@ -34,3 +36,17 @@ func Get(ctx context.Context, client databroker.DataBrokerServiceClient, userID
func (user *User) GetClaim(claim string) interface{} {
return protoutil.AnyToInterface(user.GetClaims()[claim])
}
// Set sets a user in the databroker.
func Set(ctx context.Context, client databroker.DataBrokerServiceClient, u *User) (*databroker.Record, error) {
any, _ := anypb.New(u)
res, err := client.Set(ctx, &databroker.SetRequest{
Type: any.GetTypeUrl(),
Id: u.Id,
Data: any,
})
if err != nil {
return nil, fmt.Errorf("error setting user in databroker: %w", err)
}
return res.GetRecord(), nil
}