pomerium/cache/grpc.go
Caleb Doxsey e4832cb4ed
authorize: add client mTLS support (#751)
* authorize: add client mtls support

* authorize: better error messages for envoy

* switch from function to input

* add TrustedCa to envoy config so that users are prompted for the correct client certificate

* update documentation

* fix invalid ClientCAFile

* regenerate cache protobuf

* avoid recursion, add test

* move comment line

* use http.StatusOK

* various fixes
2020-05-21 16:01:07 -06:00

35 lines
1.2 KiB
Go

//go:generate ../scripts/protoc -I ../internal/grpc/cache/ --go_out=plugins=grpc:../internal/grpc/cache/ ../internal/grpc/cache/cache.proto
package cache
import (
"context"
"github.com/pomerium/pomerium/internal/grpc/cache"
"github.com/pomerium/pomerium/internal/telemetry/trace"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// Get retrieves a key the cache store and returns the value, if found.
func (c *Cache) Get(ctx context.Context, in *cache.GetRequest) (*cache.GetReply, error) {
ctx, span := trace.StartSpan(ctx, "cache.grpc.Get")
defer span.End()
exists, value, err := c.cache.Get(ctx, in.GetKey())
if err != nil {
return nil, status.Errorf(codes.Unknown, "cache.grpc.Get error: %v", err)
}
return &cache.GetReply{Exists: exists, Value: value}, nil
}
// Set persists a key value pair in the cache store.
func (c *Cache) Set(ctx context.Context, in *cache.SetRequest) (*cache.SetReply, error) {
ctx, span := trace.StartSpan(ctx, "cache.grpc.Set")
defer span.End()
err := c.cache.Set(ctx, in.GetKey(), in.GetValue())
if err != nil {
return nil, status.Errorf(codes.Unknown, "cache.grpc.Set error: %v", err)
}
return &cache.SetReply{}, nil
}