mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-25 14:08:09 +02:00
grpc: rename internal/grpc to pkg/grpc (#1010)
* grpc: rename internal/grpc to pkg/grpc * don't ignore pkg dir * remove debug line
This commit is contained in:
parent
a98d39c5af
commit
091b71f12e
59 changed files with 247 additions and 927 deletions
36
pkg/grpc/user/user.go
Normal file
36
pkg/grpc/user/user.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Package user contains protobuf types for users.
|
||||
package user
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
|
||||
"github.com/pomerium/pomerium/internal/protoutil"
|
||||
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
||||
)
|
||||
|
||||
// Get gets a user from the databroker.
|
||||
func Get(ctx context.Context, client databroker.DataBrokerServiceClient, userID string) (*User, error) {
|
||||
any, _ := ptypes.MarshalAny(new(User))
|
||||
|
||||
res, err := client.Get(ctx, &databroker.GetRequest{
|
||||
Type: any.GetTypeUrl(),
|
||||
Id: userID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var u User
|
||||
err = ptypes.UnmarshalAny(res.GetRecord().GetData(), &u)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &u, nil
|
||||
}
|
||||
|
||||
// GetClaim gets a claim.
|
||||
func (user *User) GetClaim(claim string) interface{} {
|
||||
return protoutil.AnyToInterface(user.GetClaims()[claim])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue