mirror of
https://github.com/getsops/sops.git
synced 2026-02-05 12:45:21 +01:00
This allows for easier injection of your own (local) key service server implementation, in situations where e.g. you do not want to rely on environment variables or other runtime defaults. It is not of impact to end-users, but improves the experience of developers making use of SOPS as an SDK to e.g. provide decryption services to users. As they will now in many cases end up copying this bit of code to make this precise change. Signed-off-by: Hidde Beydals <hello@hidde.co>
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package keyservice
|
|
|
|
import (
|
|
"golang.org/x/net/context"
|
|
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
// LocalClient is a key service client that performs all operations locally
|
|
type LocalClient struct {
|
|
Server KeyServiceServer
|
|
}
|
|
|
|
// NewLocalClient creates a new local client
|
|
func NewLocalClient() LocalClient {
|
|
return LocalClient{Server{}}
|
|
}
|
|
|
|
// NewCustomLocalClient creates a new local client with a non-default backing
|
|
// KeyServiceServer implementation
|
|
func NewCustomLocalClient(server KeyServiceServer) LocalClient {
|
|
return LocalClient{Server: server}
|
|
}
|
|
|
|
// Decrypt processes a decrypt request locally
|
|
// See keyservice/server.go for more details
|
|
func (c LocalClient) Decrypt(ctx context.Context,
|
|
req *DecryptRequest, opts ...grpc.CallOption) (*DecryptResponse, error) {
|
|
return c.Server.Decrypt(ctx, req)
|
|
}
|
|
|
|
// Encrypt processes an encrypt request locally
|
|
// See keyservice/server.go for more details
|
|
func (c LocalClient) Encrypt(ctx context.Context,
|
|
req *EncryptRequest, opts ...grpc.CallOption) (*EncryptResponse, error) {
|
|
return c.Server.Encrypt(ctx, req)
|
|
}
|