mirror of
https://github.com/coder/coder.git
synced 2026-06-03 21:18:24 +00:00
bddb808b25
Fixes all our Go file imports to match the preferred spec that we've _mostly_ been using. For example: ``` import ( "context" "time" "github.com/prometheus/client_golang/prometheus" "golang.org/x/xerrors" "gopkg.in/natefinch/lumberjack.v2" "cdr.dev/slog/v3" "github.com/coder/coder/v2/codersdk/agentsdk" "github.com/coder/serpent" ) ``` 3 groups: standard library, 3rd partly libs, Coder libs. This PR makes the change across the codebase. The PR in the stack above modifies our formatting to maintain this state of affairs, and is a separate PR so it's possible to review that one in detail.
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package tailnet
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"cdr.dev/slog/v3"
|
|
"github.com/coder/coder/v2/apiversion"
|
|
agpl "github.com/coder/coder/v2/tailnet"
|
|
)
|
|
|
|
type ClientService struct {
|
|
*agpl.ClientService
|
|
}
|
|
|
|
// NewClientService returns a ClientService based on the given Coordinator pointer. The pointer is
|
|
// loaded on each processed connection.
|
|
func NewClientService(options agpl.ClientServiceOptions) (*ClientService, error) {
|
|
s, err := agpl.NewClientService(options)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &ClientService{ClientService: s}, nil
|
|
}
|
|
|
|
func (s *ClientService) ServeMultiAgentClient(ctx context.Context, version string, conn net.Conn, id uuid.UUID) error {
|
|
major, _, err := apiversion.Parse(version)
|
|
if err != nil {
|
|
s.Logger.Warn(ctx, "serve client called with unparsable version", slog.Error(err))
|
|
return err
|
|
}
|
|
switch major {
|
|
case 2:
|
|
auth := agpl.SingleTailnetCoordinateeAuth{}
|
|
streamID := agpl.StreamID{
|
|
Name: id.String(),
|
|
ID: id,
|
|
Auth: auth,
|
|
}
|
|
return s.ServeConnV2(ctx, conn, streamID)
|
|
default:
|
|
s.Logger.Warn(ctx, "serve client called with unsupported version", slog.F("version", version))
|
|
return agpl.ErrUnsupportedVersion
|
|
}
|
|
}
|