mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-04 10:03:42 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			31 lines
		
	
	
		
			714 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			714 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package secrets
 | 
						|
 | 
						|
import (
 | 
						|
	"context"
 | 
						|
 | 
						|
	"github.com/moby/buildkit/session"
 | 
						|
	"github.com/moby/buildkit/util/grpcerrors"
 | 
						|
	"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 {
 | 
						|
		if code := grpcerrors.Code(err); code == codes.Unimplemented || code == codes.NotFound {
 | 
						|
			return nil, errors.Wrapf(ErrNotFound, "secret %s", id)
 | 
						|
		}
 | 
						|
		return nil, err
 | 
						|
	}
 | 
						|
	return resp.Data, nil
 | 
						|
}
 |