2018-07-19 21:44:18 +00:00
|
|
|
package secrets
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/moby/buildkit/session"
|
2020-04-23 04:46:43 +00:00
|
|
|
"github.com/moby/buildkit/util/grpcerrors"
|
2018-07-19 21:44:18 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
2020-04-23 04:46:43 +00:00
|
|
|
if code := grpcerrors.Code(err); code == codes.Unimplemented || code == codes.NotFound {
|
2021-03-29 11:17:06 +00:00
|
|
|
return nil, errors.Wrapf(ErrNotFound, "secret %s", id)
|
2018-07-19 21:44:18 +00:00
|
|
|
}
|
2020-04-23 04:46:43 +00:00
|
|
|
return nil, err
|
2018-07-19 21:44:18 +00:00
|
|
|
}
|
|
|
|
return resp.Data, nil
|
|
|
|
}
|