authenticate: save oauth2 tokens to cache (#698)

Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
This commit is contained in:
Bobby DeSimone 2020-05-18 10:45:07 -07:00 committed by Travis Groth
parent ef399380b7
commit 666fd6aa35
31 changed files with 1127 additions and 1061 deletions

View file

@ -3,6 +3,7 @@ package client
import (
"context"
"errors"
"github.com/pomerium/pomerium/internal/grpc/cache"
"github.com/pomerium/pomerium/internal/telemetry/trace"
@ -10,12 +11,7 @@ import (
"google.golang.org/grpc"
)
// Cacher specifies an interface for remote clients connecting to the cache service.
type Cacher interface {
Get(ctx context.Context, key string) (keyExists bool, value []byte, err error)
Set(ctx context.Context, key string, value []byte) error
Close() error
}
var errKeyNotFound = errors.New("cache/client: key not found")
// Client represents a gRPC cache service client.
type Client struct {
@ -29,15 +25,18 @@ func New(conn *grpc.ClientConn) (p *Client) {
}
// Get retrieves a value from the cache service.
func (a *Client) Get(ctx context.Context, key string) (keyExists bool, value []byte, err error) {
func (a *Client) Get(ctx context.Context, key string) (value []byte, err error) {
ctx, span := trace.StartSpan(ctx, "grpc.cache.client.Get")
defer span.End()
response, err := a.client.Get(ctx, &cache.GetRequest{Key: key})
if err != nil {
return false, nil, err
return nil, err
}
return response.GetExists(), response.GetValue(), nil
if !response.GetExists() {
return nil, errKeyNotFound
}
return response.GetValue(), nil
}
// Set stores a key value pair in the cache service.