mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-10 05:27:07 +08:00
vendor: update buildkit with typed errors support
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
33
vendor/github.com/moby/buildkit/session/auth/auth.go
generated
vendored
33
vendor/github.com/moby/buildkit/session/auth/auth.go
generated
vendored
@ -4,24 +4,33 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/moby/buildkit/session"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/moby/buildkit/util/grpcerrors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func CredentialsFunc(ctx context.Context, c session.Caller) func(string) (string, string, error) {
|
||||
return func(host string) (string, string, error) {
|
||||
client := NewAuthClient(c.Conn())
|
||||
func CredentialsFunc(sm *session.Manager, g session.Group) func(string) (session, username, secret string, err error) {
|
||||
return func(host string) (string, string, string, error) {
|
||||
var sessionID, user, secret string
|
||||
err := sm.Any(context.TODO(), g, func(ctx context.Context, id string, c session.Caller) error {
|
||||
client := NewAuthClient(c.Conn())
|
||||
|
||||
resp, err := client.Credentials(ctx, &CredentialsRequest{
|
||||
Host: host,
|
||||
resp, err := client.Credentials(ctx, &CredentialsRequest{
|
||||
Host: host,
|
||||
})
|
||||
if err != nil {
|
||||
if grpcerrors.Code(err) == codes.Unimplemented {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
sessionID = id
|
||||
user = resp.Username
|
||||
secret = resp.Secret
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
if st, ok := status.FromError(errors.Cause(err)); ok && st.Code() == codes.Unimplemented {
|
||||
return "", "", nil
|
||||
}
|
||||
return "", "", errors.WithStack(err)
|
||||
return "", "", "", err
|
||||
}
|
||||
return resp.Username, resp.Secret, nil
|
||||
return sessionID, user, secret, nil
|
||||
}
|
||||
}
|
||||
|
22
vendor/github.com/moby/buildkit/session/context.go
generated
vendored
22
vendor/github.com/moby/buildkit/session/context.go
generated
vendored
@ -1,22 +0,0 @@
|
||||
package session
|
||||
|
||||
import "context"
|
||||
|
||||
type contextKeyT string
|
||||
|
||||
var contextKey = contextKeyT("buildkit/session-id")
|
||||
|
||||
func NewContext(ctx context.Context, id string) context.Context {
|
||||
if id != "" {
|
||||
return context.WithValue(ctx, contextKey, id)
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
func FromContext(ctx context.Context) string {
|
||||
v := ctx.Value(contextKey)
|
||||
if v == nil {
|
||||
return ""
|
||||
}
|
||||
return v.(string)
|
||||
}
|
19
vendor/github.com/moby/buildkit/session/filesync/diffcopy.go
generated
vendored
19
vendor/github.com/moby/buildkit/session/filesync/diffcopy.go
generated
vendored
@ -2,6 +2,7 @@ package filesync
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
io "io"
|
||||
"os"
|
||||
"time"
|
||||
@ -13,7 +14,13 @@ import (
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func sendDiffCopy(stream grpc.Stream, fs fsutil.FS, progress progressCb) error {
|
||||
type Stream interface {
|
||||
Context() context.Context
|
||||
SendMsg(m interface{}) error
|
||||
RecvMsg(m interface{}) error
|
||||
}
|
||||
|
||||
func sendDiffCopy(stream Stream, fs fsutil.FS, progress progressCb) error {
|
||||
return errors.WithStack(fsutil.Send(stream.Context(), stream, fs, progress))
|
||||
}
|
||||
|
||||
@ -41,7 +48,7 @@ type streamWriterCloser struct {
|
||||
func (wc *streamWriterCloser) Write(dt []byte) (int, error) {
|
||||
if err := wc.ClientStream.SendMsg(&BytesMessage{Data: dt}); err != nil {
|
||||
// SendMsg return EOF on remote errors
|
||||
if errors.Cause(err) == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
if err := errors.WithStack(wc.ClientStream.RecvMsg(struct{}{})); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@ -63,7 +70,7 @@ func (wc *streamWriterCloser) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func recvDiffCopy(ds grpc.Stream, dest string, cu CacheUpdater, progress progressCb, filter func(string, *fstypes.Stat) bool) error {
|
||||
func recvDiffCopy(ds grpc.ClientStream, dest string, cu CacheUpdater, progress progressCb, filter func(string, *fstypes.Stat) bool) error {
|
||||
st := time.Now()
|
||||
defer func() {
|
||||
logrus.Debugf("diffcopy took: %v", time.Since(st))
|
||||
@ -83,7 +90,7 @@ func recvDiffCopy(ds grpc.Stream, dest string, cu CacheUpdater, progress progres
|
||||
}))
|
||||
}
|
||||
|
||||
func syncTargetDiffCopy(ds grpc.Stream, dest string) error {
|
||||
func syncTargetDiffCopy(ds grpc.ServerStream, dest string) error {
|
||||
if err := os.MkdirAll(dest, 0700); err != nil {
|
||||
return errors.Wrapf(err, "failed to create synctarget dest dir %s", dest)
|
||||
}
|
||||
@ -101,11 +108,11 @@ func syncTargetDiffCopy(ds grpc.Stream, dest string) error {
|
||||
}))
|
||||
}
|
||||
|
||||
func writeTargetFile(ds grpc.Stream, wc io.WriteCloser) error {
|
||||
func writeTargetFile(ds grpc.ServerStream, wc io.WriteCloser) error {
|
||||
for {
|
||||
bm := BytesMessage{}
|
||||
if err := ds.RecvMsg(&bm); err != nil {
|
||||
if errors.Cause(err) == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
return nil
|
||||
}
|
||||
return errors.WithStack(err)
|
||||
|
4
vendor/github.com/moby/buildkit/session/filesync/filesync.go
generated
vendored
4
vendor/github.com/moby/buildkit/session/filesync/filesync.go
generated
vendored
@ -129,8 +129,8 @@ type progressCb func(int, bool)
|
||||
|
||||
type protocol struct {
|
||||
name string
|
||||
sendFn func(stream grpc.Stream, fs fsutil.FS, progress progressCb) error
|
||||
recvFn func(stream grpc.Stream, destDir string, cu CacheUpdater, progress progressCb, mapFunc func(string, *fstypes.Stat) bool) error
|
||||
sendFn func(stream Stream, fs fsutil.FS, progress progressCb) error
|
||||
recvFn func(stream grpc.ClientStream, destDir string, cu CacheUpdater, progress progressCb, mapFunc func(string, *fstypes.Stat) bool) error
|
||||
}
|
||||
|
||||
func isProtoSupported(p string) bool {
|
||||
|
88
vendor/github.com/moby/buildkit/session/group.go
generated
vendored
Normal file
88
vendor/github.com/moby/buildkit/session/group.go
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Group interface {
|
||||
SessionIterator() Iterator
|
||||
}
|
||||
type Iterator interface {
|
||||
NextSession() string
|
||||
}
|
||||
|
||||
func NewGroup(ids ...string) Group {
|
||||
return &group{ids: ids}
|
||||
}
|
||||
|
||||
type group struct {
|
||||
ids []string
|
||||
}
|
||||
|
||||
func (g *group) SessionIterator() Iterator {
|
||||
return &group{ids: g.ids}
|
||||
}
|
||||
|
||||
func (g *group) NextSession() string {
|
||||
if len(g.ids) == 0 {
|
||||
return ""
|
||||
}
|
||||
v := g.ids[0]
|
||||
g.ids = g.ids[1:]
|
||||
return v
|
||||
}
|
||||
|
||||
func AllSessionIDs(g Group) (out []string) {
|
||||
if g == nil {
|
||||
return nil
|
||||
}
|
||||
it := g.SessionIterator()
|
||||
if it == nil {
|
||||
return nil
|
||||
}
|
||||
for {
|
||||
v := it.NextSession()
|
||||
if v == "" {
|
||||
return
|
||||
}
|
||||
out = append(out, v)
|
||||
}
|
||||
}
|
||||
|
||||
func (sm *Manager) Any(ctx context.Context, g Group, f func(context.Context, string, Caller) error) error {
|
||||
if g == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
iter := g.SessionIterator()
|
||||
if iter == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var lastErr error
|
||||
for {
|
||||
id := iter.NextSession()
|
||||
if id == "" {
|
||||
if lastErr != nil {
|
||||
return lastErr
|
||||
}
|
||||
return errors.Errorf("no active sessions")
|
||||
}
|
||||
|
||||
timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
c, err := sm.Get(timeoutCtx, id, false)
|
||||
if err != nil {
|
||||
lastErr = err
|
||||
continue
|
||||
}
|
||||
if err := f(ctx, id, c); err != nil {
|
||||
lastErr = err
|
||||
continue
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
28
vendor/github.com/moby/buildkit/session/grpc.go
generated
vendored
28
vendor/github.com/moby/buildkit/session/grpc.go
generated
vendored
@ -6,7 +6,9 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
||||
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
|
||||
"github.com/moby/buildkit/util/grpcerrors"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -25,8 +27,11 @@ func serve(ctx context.Context, grpcServer *grpc.Server, conn net.Conn) {
|
||||
}
|
||||
|
||||
func grpcClientConn(ctx context.Context, conn net.Conn) (context.Context, *grpc.ClientConn, error) {
|
||||
var unary []grpc.UnaryClientInterceptor
|
||||
var stream []grpc.StreamClientInterceptor
|
||||
|
||||
var dialCount int64
|
||||
dialer := grpc.WithDialer(func(addr string, d time.Duration) (net.Conn, error) {
|
||||
dialer := grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
||||
if c := atomic.AddInt64(&dialCount, 1); c > 1 {
|
||||
return nil, errors.Errorf("only one connection allowed")
|
||||
}
|
||||
@ -40,10 +45,23 @@ func grpcClientConn(ctx context.Context, conn net.Conn) (context.Context, *grpc.
|
||||
|
||||
if span := opentracing.SpanFromContext(ctx); span != nil {
|
||||
tracer := span.Tracer()
|
||||
dialOpts = append(dialOpts,
|
||||
grpc.WithUnaryInterceptor(otgrpc.OpenTracingClientInterceptor(tracer, traceFilter())),
|
||||
grpc.WithStreamInterceptor(otgrpc.OpenTracingStreamClientInterceptor(tracer, traceFilter())),
|
||||
)
|
||||
unary = append(unary, otgrpc.OpenTracingClientInterceptor(tracer, traceFilter()))
|
||||
stream = append(stream, otgrpc.OpenTracingStreamClientInterceptor(tracer, traceFilter()))
|
||||
}
|
||||
|
||||
unary = append(unary, grpcerrors.UnaryClientInterceptor)
|
||||
stream = append(stream, grpcerrors.StreamClientInterceptor)
|
||||
|
||||
if len(unary) == 1 {
|
||||
dialOpts = append(dialOpts, grpc.WithUnaryInterceptor(unary[0]))
|
||||
} else if len(unary) > 1 {
|
||||
dialOpts = append(dialOpts, grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(unary...)))
|
||||
}
|
||||
|
||||
if len(stream) == 1 {
|
||||
dialOpts = append(dialOpts, grpc.WithStreamInterceptor(stream[0]))
|
||||
} else if len(stream) > 1 {
|
||||
dialOpts = append(dialOpts, grpc.WithStreamInterceptor(grpc_middleware.ChainStreamClient(stream...)))
|
||||
}
|
||||
|
||||
cc, err := grpc.DialContext(ctx, "", dialOpts...)
|
||||
|
11
vendor/github.com/moby/buildkit/session/grpchijack/dial.go
generated
vendored
11
vendor/github.com/moby/buildkit/session/grpchijack/dial.go
generated
vendored
@ -33,21 +33,26 @@ func Dialer(api controlapi.ControlClient) session.Dialer {
|
||||
}
|
||||
}
|
||||
|
||||
func streamToConn(stream grpc.Stream) (net.Conn, <-chan struct{}) {
|
||||
type stream interface {
|
||||
Context() context.Context
|
||||
SendMsg(m interface{}) error
|
||||
RecvMsg(m interface{}) error
|
||||
}
|
||||
|
||||
func streamToConn(stream stream) (net.Conn, <-chan struct{}) {
|
||||
closeCh := make(chan struct{})
|
||||
c := &conn{stream: stream, buf: make([]byte, 32*1<<10), closeCh: closeCh}
|
||||
return c, closeCh
|
||||
}
|
||||
|
||||
type conn struct {
|
||||
stream grpc.Stream
|
||||
stream stream
|
||||
buf []byte
|
||||
lastBuf []byte
|
||||
|
||||
closedOnce sync.Once
|
||||
readMu sync.Mutex
|
||||
writeMu sync.Mutex
|
||||
err error
|
||||
closeCh chan struct{}
|
||||
}
|
||||
|
||||
|
8
vendor/github.com/moby/buildkit/session/manager.go
generated
vendored
8
vendor/github.com/moby/buildkit/session/manager.go
generated
vendored
@ -149,7 +149,7 @@ func (sm *Manager) handleConn(ctx context.Context, conn net.Conn, opts map[strin
|
||||
}
|
||||
|
||||
// Get returns a session by ID
|
||||
func (sm *Manager) Get(ctx context.Context, id string) (Caller, error) {
|
||||
func (sm *Manager) Get(ctx context.Context, id string, noWait bool) (Caller, error) {
|
||||
// session prefix is used to identify vertexes with different contexts so
|
||||
// they would not collide, but for lookup we don't need the prefix
|
||||
if p := strings.SplitN(id, ":", 2); len(p) == 2 && len(p[1]) > 0 {
|
||||
@ -180,7 +180,7 @@ func (sm *Manager) Get(ctx context.Context, id string) (Caller, error) {
|
||||
}
|
||||
var ok bool
|
||||
c, ok = sm.sessions[id]
|
||||
if !ok || c.closed() {
|
||||
if (!ok || c.closed()) && !noWait {
|
||||
sm.updateCondition.Wait()
|
||||
continue
|
||||
}
|
||||
@ -188,6 +188,10 @@ func (sm *Manager) Get(ctx context.Context, id string) (Caller, error) {
|
||||
break
|
||||
}
|
||||
|
||||
if c == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
|
6
vendor/github.com/moby/buildkit/session/secrets/secrets.go
generated
vendored
6
vendor/github.com/moby/buildkit/session/secrets/secrets.go
generated
vendored
@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/moby/buildkit/session"
|
||||
"github.com/moby/buildkit/util/grpcerrors"
|
||||
"github.com/pkg/errors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type SecretStore interface {
|
||||
@ -21,10 +21,10 @@ func GetSecret(ctx context.Context, c session.Caller, id string) ([]byte, error)
|
||||
ID: id,
|
||||
})
|
||||
if err != nil {
|
||||
if st, ok := status.FromError(errors.Cause(err)); ok && (st.Code() == codes.Unimplemented || st.Code() == codes.NotFound) {
|
||||
if code := grpcerrors.Code(err); code == codes.Unimplemented || code == codes.NotFound {
|
||||
return nil, errors.Wrapf(ErrNotFound, "secret %s not found", id)
|
||||
}
|
||||
return nil, errors.WithStack(err)
|
||||
return nil, err
|
||||
}
|
||||
return resp.Data, nil
|
||||
}
|
||||
|
54
vendor/github.com/moby/buildkit/session/secrets/secretsprovider/file.go
generated
vendored
54
vendor/github.com/moby/buildkit/session/secrets/secretsprovider/file.go
generated
vendored
@ -1,54 +0,0 @@
|
||||
package secretsprovider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/moby/buildkit/session/secrets"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type FileSource struct {
|
||||
ID string
|
||||
FilePath string
|
||||
}
|
||||
|
||||
func NewFileStore(files []FileSource) (secrets.SecretStore, error) {
|
||||
m := map[string]FileSource{}
|
||||
for _, f := range files {
|
||||
if f.ID == "" {
|
||||
return nil, errors.Errorf("secret missing ID")
|
||||
}
|
||||
if f.FilePath == "" {
|
||||
f.FilePath = f.ID
|
||||
}
|
||||
fi, err := os.Stat(f.FilePath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to stat %s", f.FilePath)
|
||||
}
|
||||
if fi.Size() > MaxSecretSize {
|
||||
return nil, errors.Errorf("secret %s too big. max size 500KB", f.ID)
|
||||
}
|
||||
m[f.ID] = f
|
||||
}
|
||||
return &fileStore{
|
||||
m: m,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type fileStore struct {
|
||||
m map[string]FileSource
|
||||
}
|
||||
|
||||
func (fs *fileStore) GetSecret(ctx context.Context, id string) ([]byte, error) {
|
||||
v, ok := fs.m[id]
|
||||
if !ok {
|
||||
return nil, errors.WithStack(secrets.ErrNotFound)
|
||||
}
|
||||
dt, err := ioutil.ReadFile(v.FilePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dt, nil
|
||||
}
|
2
vendor/github.com/moby/buildkit/session/secrets/secretsprovider/secretsprovider.go
generated
vendored
2
vendor/github.com/moby/buildkit/session/secrets/secretsprovider/secretsprovider.go
generated
vendored
@ -31,7 +31,7 @@ func (sp *secretProvider) Register(server *grpc.Server) {
|
||||
func (sp *secretProvider) GetSecret(ctx context.Context, req *secrets.GetSecretRequest) (*secrets.GetSecretResponse, error) {
|
||||
dt, err := sp.store.GetSecret(ctx, req.ID)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == secrets.ErrNotFound {
|
||||
if errors.Is(err, secrets.ErrNotFound) {
|
||||
return nil, status.Errorf(codes.NotFound, err.Error())
|
||||
}
|
||||
return nil, err
|
||||
|
65
vendor/github.com/moby/buildkit/session/secrets/secretsprovider/store.go
generated
vendored
Normal file
65
vendor/github.com/moby/buildkit/session/secrets/secretsprovider/store.go
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
package secretsprovider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/moby/buildkit/session/secrets"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tonistiigi/units"
|
||||
)
|
||||
|
||||
type Source struct {
|
||||
ID string
|
||||
FilePath string
|
||||
Env string
|
||||
}
|
||||
|
||||
func NewStore(files []Source) (secrets.SecretStore, error) {
|
||||
m := map[string]Source{}
|
||||
for _, f := range files {
|
||||
if f.ID == "" {
|
||||
return nil, errors.Errorf("secret missing ID")
|
||||
}
|
||||
if f.Env == "" && f.FilePath == "" {
|
||||
if _, ok := os.LookupEnv(f.ID); ok {
|
||||
f.Env = f.ID
|
||||
} else {
|
||||
f.FilePath = f.ID
|
||||
}
|
||||
}
|
||||
if f.FilePath != "" {
|
||||
fi, err := os.Stat(f.FilePath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to stat %s", f.FilePath)
|
||||
}
|
||||
if fi.Size() > MaxSecretSize {
|
||||
return nil, errors.Errorf("secret %s too big. max size %#.f", f.ID, MaxSecretSize*units.B)
|
||||
}
|
||||
}
|
||||
m[f.ID] = f
|
||||
}
|
||||
return &fileStore{
|
||||
m: m,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type fileStore struct {
|
||||
m map[string]Source
|
||||
}
|
||||
|
||||
func (fs *fileStore) GetSecret(ctx context.Context, id string) ([]byte, error) {
|
||||
v, ok := fs.m[id]
|
||||
if !ok {
|
||||
return nil, errors.WithStack(secrets.ErrNotFound)
|
||||
}
|
||||
if v.Env != "" {
|
||||
return []byte(os.Getenv(v.Env)), nil
|
||||
}
|
||||
dt, err := ioutil.ReadFile(v.FilePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dt, nil
|
||||
}
|
26
vendor/github.com/moby/buildkit/session/session.go
generated
vendored
26
vendor/github.com/moby/buildkit/session/session.go
generated
vendored
@ -5,8 +5,10 @@ import (
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
||||
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
|
||||
"github.com/moby/buildkit/identity"
|
||||
"github.com/moby/buildkit/util/grpcerrors"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/pkg/errors"
|
||||
"google.golang.org/grpc"
|
||||
@ -45,13 +47,29 @@ type Session struct {
|
||||
func NewSession(ctx context.Context, name, sharedKey string) (*Session, error) {
|
||||
id := identity.NewID()
|
||||
|
||||
var unary []grpc.UnaryServerInterceptor
|
||||
var stream []grpc.StreamServerInterceptor
|
||||
|
||||
serverOpts := []grpc.ServerOption{}
|
||||
if span := opentracing.SpanFromContext(ctx); span != nil {
|
||||
tracer := span.Tracer()
|
||||
serverOpts = []grpc.ServerOption{
|
||||
grpc.StreamInterceptor(otgrpc.OpenTracingStreamServerInterceptor(span.Tracer(), traceFilter())),
|
||||
grpc.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer, traceFilter())),
|
||||
}
|
||||
unary = append(unary, otgrpc.OpenTracingServerInterceptor(tracer, traceFilter()))
|
||||
stream = append(stream, otgrpc.OpenTracingStreamServerInterceptor(span.Tracer(), traceFilter()))
|
||||
}
|
||||
|
||||
unary = append(unary, grpcerrors.UnaryServerInterceptor)
|
||||
stream = append(stream, grpcerrors.StreamServerInterceptor)
|
||||
|
||||
if len(unary) == 1 {
|
||||
serverOpts = append(serverOpts, grpc.UnaryInterceptor(unary[0]))
|
||||
} else if len(unary) > 1 {
|
||||
serverOpts = append(serverOpts, grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(unary...)))
|
||||
}
|
||||
|
||||
if len(stream) == 1 {
|
||||
serverOpts = append(serverOpts, grpc.StreamInterceptor(stream[0]))
|
||||
} else if len(stream) > 1 {
|
||||
serverOpts = append(serverOpts, grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(stream...)))
|
||||
}
|
||||
|
||||
s := &Session{
|
||||
|
8
vendor/github.com/moby/buildkit/session/sshforward/copy.go
generated
vendored
8
vendor/github.com/moby/buildkit/session/sshforward/copy.go
generated
vendored
@ -6,10 +6,14 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
context "golang.org/x/net/context"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func Copy(ctx context.Context, conn io.ReadWriteCloser, stream grpc.Stream, closeStream func() error) error {
|
||||
type Stream interface {
|
||||
SendMsg(m interface{}) error
|
||||
RecvMsg(m interface{}) error
|
||||
}
|
||||
|
||||
func Copy(ctx context.Context, conn io.ReadWriteCloser, stream Stream, closeStream func() error) error {
|
||||
g, ctx := errgroup.WithContext(ctx)
|
||||
|
||||
g.Go(func() (retErr error) {
|
||||
|
Reference in New Issue
Block a user