Tim Jones e6fba7d3bc
chore: update dependencies
Updates:
* pkgs v1.3.0-alpha.0-33-g8fe5cbc
* tools v1.3.0-alpha.0-20-g3b5f89a
* aws-sdk-go v1.44.120
* docker v20.10.20+incompatible
* fsnotify v1.6.0
* nftables v0.0.0-20221015190445-4f5cd5826fbd
* gen v0.4.0
* grpc-proxy v0.4.0
* spf13/cobra v1.6.0
* u-root v0.10.0
* x/net v0.1.0
* x/sync v0.1.0
* x/sys v0.1.0
* x/term v0.1.0
* x/time v0.1.0
* grpc v1.50.1
* genproto v0.0.0-20221018160656-63c7b68cfc55
* Linux kernel 5.15.74

Signed-off-by: Tim Jones <tim.jones@siderolabs.com>
2022-10-21 15:20:01 +04:00

79 lines
1.8 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package backend
import (
"context"
"sync"
"github.com/siderolabs/grpc-proxy/proxy"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
"github.com/talos-systems/talos/pkg/grpc/middleware/authz"
)
var _ proxy.Backend = (*Local)(nil)
// Local implements local backend (proxying one2one to local service).
type Local struct {
name string
socketPath string
mu sync.Mutex
conn *grpc.ClientConn
}
// NewLocal builds new Local backend.
func NewLocal(name, socketPath string) *Local {
return &Local{
name: name,
socketPath: socketPath,
}
}
func (l *Local) String() string {
return l.name
}
// GetConnection returns a grpc connection to the backend.
func (l *Local) GetConnection(ctx context.Context, fullMethodName string) (context.Context, *grpc.ClientConn, error) {
md, _ := metadata.FromIncomingContext(ctx)
md = md.Copy()
authz.SetMetadata(md, authz.GetRoles(ctx))
outCtx := metadata.NewOutgoingContext(ctx, md)
l.mu.Lock()
defer l.mu.Unlock()
if l.conn != nil {
return outCtx, l.conn, nil
}
var err error
l.conn, err = grpc.DialContext(
ctx,
"unix:"+l.socketPath,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithCodec(proxy.Codec()), //nolint:staticcheck
)
return outCtx, l.conn, err
}
// AppendInfo is called to enhance response from the backend with additional data.
func (l *Local) AppendInfo(streaming bool, resp []byte) ([]byte, error) {
return resp, nil
}
// BuildError is called to convert error from upstream into response field.
func (l *Local) BuildError(streaming bool, err error) ([]byte, error) {
return nil, nil
}