Skip to content

Commit 7d8d1fe

Browse files
committed
Merge branch 'main' into AwaitTemplateVersionJobCompleted
2 parents e8b84eb + 70a4e56 commit 7d8d1fe

File tree

98 files changed

+2093
-1526
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+2093
-1526
lines changed

.github/workflows/ci.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ jobs:
234234
run: ./scripts/check_unstaged.sh
235235

236236
test-go:
237-
runs-on: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'buildjet-4vcpu-ubuntu-2204' || matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'macos-latest-xl' || matrix.os == 'windows-2022' && github.repository_owner == 'coder' && 'windows-latest-16-cores' || matrix.os }}
237+
runs-on: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'buildjet-4vcpu-ubuntu-2204' || matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'macos-latest-xlarge' || matrix.os == 'windows-2022' && github.repository_owner == 'coder' && 'windows-latest-16-cores' || matrix.os }}
238238
needs: changes
239239
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
240240
timeout-minutes: 20
@@ -271,6 +271,13 @@ jobs:
271271
echo "cover=false" >> $GITHUB_OUTPUT
272272
fi
273273
274+
# if macOS, install google-chrome for scaletests. As another concern,
275+
# should we really have this kind of external dependency requirement
276+
# on standard CI?
277+
if [ "${{ matrix.os }}" == "macos-latest" ]; then
278+
brew install google-chrome
279+
fi
280+
274281
# By default Go will use the number of logical CPUs, which
275282
# is a fine default.
276283
PARALLEL_FLAG=""

.golangci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ linters-settings:
1010
include:
1111
# Gradually extend to cover more of the codebase.
1212
- 'httpmw\.\w+'
13+
# We want to enforce all values are specified when inserting or updating
14+
# a database row. Ref: #9936
15+
- 'github.com/coder/coder/v2/coderd/database\.[^G][^e][^t]\w+Params'
1316
gocognit:
1417
min-complexity: 300
1518

cli/cliui/gitauth.go renamed to cli/cliui/externalauth.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import (
1111
"github.com/coder/coder/v2/codersdk"
1212
)
1313

14-
type GitAuthOptions struct {
14+
type ExternalAuthOptions struct {
1515
Fetch func(context.Context) ([]codersdk.TemplateVersionExternalAuth, error)
1616
FetchInterval time.Duration
1717
}
1818

19-
func GitAuth(ctx context.Context, writer io.Writer, opts GitAuthOptions) error {
19+
func ExternalAuth(ctx context.Context, writer io.Writer, opts ExternalAuthOptions) error {
2020
if opts.FetchInterval == 0 {
2121
opts.FetchInterval = 500 * time.Millisecond
2222
}
@@ -38,7 +38,7 @@ func GitAuth(ctx context.Context, writer io.Writer, opts GitAuthOptions) error {
3838
return nil
3939
}
4040

41-
_, _ = fmt.Fprintf(writer, "You must authenticate with %s to create a workspace with this template. Visit:\n\n\t%s\n\n", auth.Type.Pretty(), auth.AuthenticateURL)
41+
_, _ = fmt.Fprintf(writer, "You must authenticate with %s to create a workspace with this template. Visit:\n\n\t%s\n\n", auth.DisplayName, auth.AuthenticateURL)
4242

4343
ticker.Reset(opts.FetchInterval)
4444
spin.Start()
@@ -66,7 +66,7 @@ func GitAuth(ctx context.Context, writer io.Writer, opts GitAuthOptions) error {
6666
}
6767
}
6868
spin.Stop()
69-
_, _ = fmt.Fprintf(writer, "Successfully authenticated with %s!\n\n", auth.Type.Pretty())
69+
_, _ = fmt.Fprintf(writer, "Successfully authenticated with %s!\n\n", auth.DisplayName)
7070
}
7171
return nil
7272
}

cli/cliui/gitauth_test.go renamed to cli/cliui/externalauth_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/coder/coder/v2/testutil"
1616
)
1717

18-
func TestGitAuth(t *testing.T) {
18+
func TestExternalAuth(t *testing.T) {
1919
t.Parallel()
2020

2121
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
@@ -25,12 +25,13 @@ func TestGitAuth(t *testing.T) {
2525
cmd := &clibase.Cmd{
2626
Handler: func(inv *clibase.Invocation) error {
2727
var fetched atomic.Bool
28-
return cliui.GitAuth(inv.Context(), inv.Stdout, cliui.GitAuthOptions{
28+
return cliui.ExternalAuth(inv.Context(), inv.Stdout, cliui.ExternalAuthOptions{
2929
Fetch: func(ctx context.Context) ([]codersdk.TemplateVersionExternalAuth, error) {
3030
defer fetched.Store(true)
3131
return []codersdk.TemplateVersionExternalAuth{{
3232
ID: "github",
33-
Type: codersdk.ExternalAuthProviderGitHub,
33+
DisplayName: "GitHub",
34+
Type: codersdk.EnhancedExternalAuthProviderGitHub.String(),
3435
Authenticated: fetched.Load(),
3536
AuthenticateURL: "https://example.com/gitauth/github",
3637
}}, nil

cli/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func prepWorkspaceBuild(inv *clibase.Invocation, client *codersdk.Client, args p
265265
return nil, err
266266
}
267267

268-
err = cliui.GitAuth(ctx, inv.Stdout, cliui.GitAuthOptions{
268+
err = cliui.ExternalAuth(ctx, inv.Stdout, cliui.ExternalAuthOptions{
269269
Fetch: func(ctx context.Context) ([]codersdk.TemplateVersionExternalAuth, error) {
270270
return client.TemplateVersionExternalAuth(ctx, templateVersion.ID)
271271
},

cli/create_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,8 @@ func TestCreateWithGitAuth(t *testing.T) {
613613
OAuth2Config: &testutil.OAuth2Config{},
614614
ID: "github",
615615
Regex: regexp.MustCompile(`github\.com`),
616-
Type: codersdk.ExternalAuthProviderGitHub,
616+
Type: codersdk.EnhancedExternalAuthProviderGitHub.String(),
617+
DisplayName: "GitHub",
617618
}},
618619
IncludeProvisionerDaemon: true,
619620
})

cli/exp_scaletest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !slim
2+
13
package cli
24

35
import (

cli/exp_scaletest_slim.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//go:build slim
2+
3+
package cli
4+
5+
import "github.com/coder/coder/v2/cli/clibase"
6+
7+
func (r *RootCmd) scaletestCmd() *clibase.Cmd {
8+
cmd := &clibase.Cmd{
9+
Use: "scaletest",
10+
Short: "Run a scale test against the Coder API",
11+
Handler: func(inv *clibase.Invocation) error {
12+
SlimUnsupported(inv.Stderr, "exp scaletest")
13+
return nil
14+
},
15+
}
16+
17+
return cmd
18+
}

cli/remoteforward.go

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"net"
8+
"os"
89
"regexp"
910
"strconv"
1011

@@ -23,15 +24,24 @@ type cookieAddr struct {
2324

2425
// Format:
2526
// remote_port:local_address:local_port
26-
var remoteForwardRegex = regexp.MustCompile(`^(\d+):(.+):(\d+)$`)
27+
var remoteForwardRegexTCP = regexp.MustCompile(`^(\d+):(.+):(\d+)$`)
2728

28-
func validateRemoteForward(flag string) bool {
29-
return remoteForwardRegex.MatchString(flag)
29+
// remote_socket_path:local_socket_path (both absolute paths)
30+
var remoteForwardRegexUnixSocket = regexp.MustCompile(`^(\/.+):(\/.+)$`)
31+
32+
func isRemoteForwardTCP(flag string) bool {
33+
return remoteForwardRegexTCP.MatchString(flag)
3034
}
3135

32-
func parseRemoteForward(flag string) (net.Addr, net.Addr, error) {
33-
matches := remoteForwardRegex.FindStringSubmatch(flag)
36+
func isRemoteForwardUnixSocket(flag string) bool {
37+
return remoteForwardRegexUnixSocket.MatchString(flag)
38+
}
39+
40+
func validateRemoteForward(flag string) bool {
41+
return isRemoteForwardTCP(flag) || isRemoteForwardUnixSocket(flag)
42+
}
3443

44+
func parseRemoteForwardTCP(matches []string) (net.Addr, net.Addr, error) {
3545
remotePort, err := strconv.Atoi(matches[1])
3646
if err != nil {
3747
return nil, nil, xerrors.Errorf("remote port is invalid: %w", err)
@@ -57,6 +67,46 @@ func parseRemoteForward(flag string) (net.Addr, net.Addr, error) {
5767
return localAddr, remoteAddr, nil
5868
}
5969

70+
func parseRemoteForwardUnixSocket(matches []string) (net.Addr, net.Addr, error) {
71+
remoteSocket := matches[1]
72+
localSocket := matches[2]
73+
74+
fileInfo, err := os.Stat(localSocket)
75+
if err != nil {
76+
return nil, nil, err
77+
}
78+
79+
if fileInfo.Mode()&os.ModeSocket == 0 {
80+
return nil, nil, xerrors.New("File is not a Unix domain socket file")
81+
}
82+
83+
remoteAddr := &net.UnixAddr{
84+
Name: remoteSocket,
85+
Net: "unix",
86+
}
87+
88+
localAddr := &net.UnixAddr{
89+
Name: localSocket,
90+
Net: "unix",
91+
}
92+
return localAddr, remoteAddr, nil
93+
}
94+
95+
func parseRemoteForward(flag string) (net.Addr, net.Addr, error) {
96+
tcpMatches := remoteForwardRegexTCP.FindStringSubmatch(flag)
97+
98+
if len(tcpMatches) > 0 {
99+
return parseRemoteForwardTCP(tcpMatches)
100+
}
101+
102+
unixSocketMatches := remoteForwardRegexUnixSocket.FindStringSubmatch(flag)
103+
if len(unixSocketMatches) > 0 {
104+
return parseRemoteForwardUnixSocket(unixSocketMatches)
105+
}
106+
107+
return nil, nil, xerrors.New("Could not match forward arguments")
108+
}
109+
60110
// sshRemoteForward starts forwarding connections from a remote listener to a
61111
// local address via SSH in a goroutine.
62112
//

0 commit comments

Comments
 (0)