2018-07-19 21:44:18 +00:00
|
|
|
package secrets
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/moby/buildkit/session"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SecretStore interface {
|
|
|
|
GetSecret(context.Context, string) ([]byte, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
var ErrNotFound = errors.Errorf("not found")
|
|
|
|
|
|
|
|
func GetSecret(ctx context.Context, c session.Caller, id string) ([]byte, error) {
|
|
|
|
client := NewSecretsClient(c.Conn())
|
|
|
|
resp, err := client.GetSecret(ctx, &GetSecretRequest{
|
|
|
|
ID: id,
|
|
|
|
})
|
|
|
|
if err != nil {
|
2019-06-02 00:55:52 +00:00
|
|
|
if st, ok := status.FromError(errors.Cause(err)); ok && (st.Code() == codes.Unimplemented || st.Code() == codes.NotFound) {
|
2018-07-19 21:44:18 +00:00
|
|
|
return nil, errors.Wrapf(ErrNotFound, "secret %s not found", id)
|
|
|
|
}
|
2019-06-01 23:52:35 +00:00
|
|
|
return nil, errors.WithStack(err)
|
2018-07-19 21:44:18 +00:00
|
|
|
}
|
|
|
|
return resp.Data, nil
|
|
|
|
}
|