Skip to content

Commit 2cf5fc2

Browse files
committed
Merge branch 'main' of https://github.com/coder/coder into bq/support-weekly
2 parents 6d33f90 + 70a4e56 commit 2cf5fc2

File tree

75 files changed

+1475
-1089
lines changed

Some content is hidden

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

75 files changed

+1475
-1089
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=""

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/server.go

Lines changed: 103 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -98,85 +98,6 @@ import (
9898
"github.com/coder/wgtunnel/tunnelsdk"
9999
)
100100

101-
// ReadGitAuthProvidersFromEnv is provided for compatibility purposes with the
102-
// viper CLI.
103-
// DEPRECATED
104-
func ReadGitAuthProvidersFromEnv(environ []string) ([]codersdk.GitAuthConfig, error) {
105-
// The index numbers must be in-order.
106-
sort.Strings(environ)
107-
108-
var providers []codersdk.GitAuthConfig
109-
for _, v := range clibase.ParseEnviron(environ, "CODER_GITAUTH_") {
110-
tokens := strings.SplitN(v.Name, "_", 2)
111-
if len(tokens) != 2 {
112-
return nil, xerrors.Errorf("invalid env var: %s", v.Name)
113-
}
114-
115-
providerNum, err := strconv.Atoi(tokens[0])
116-
if err != nil {
117-
return nil, xerrors.Errorf("parse number: %s", v.Name)
118-
}
119-
120-
var provider codersdk.GitAuthConfig
121-
switch {
122-
case len(providers) < providerNum:
123-
return nil, xerrors.Errorf(
124-
"provider num %v skipped: %s",
125-
len(providers),
126-
v.Name,
127-
)
128-
case len(providers) == providerNum:
129-
// At the next next provider.
130-
providers = append(providers, provider)
131-
case len(providers) == providerNum+1:
132-
// At the current provider.
133-
provider = providers[providerNum]
134-
}
135-
136-
key := tokens[1]
137-
switch key {
138-
case "ID":
139-
provider.ID = v.Value
140-
case "TYPE":
141-
provider.Type = v.Value
142-
case "CLIENT_ID":
143-
provider.ClientID = v.Value
144-
case "CLIENT_SECRET":
145-
provider.ClientSecret = v.Value
146-
case "AUTH_URL":
147-
provider.AuthURL = v.Value
148-
case "TOKEN_URL":
149-
provider.TokenURL = v.Value
150-
case "VALIDATE_URL":
151-
provider.ValidateURL = v.Value
152-
case "REGEX":
153-
provider.Regex = v.Value
154-
case "DEVICE_FLOW":
155-
b, err := strconv.ParseBool(v.Value)
156-
if err != nil {
157-
return nil, xerrors.Errorf("parse bool: %s", v.Value)
158-
}
159-
provider.DeviceFlow = b
160-
case "DEVICE_CODE_URL":
161-
provider.DeviceCodeURL = v.Value
162-
case "NO_REFRESH":
163-
b, err := strconv.ParseBool(v.Value)
164-
if err != nil {
165-
return nil, xerrors.Errorf("parse bool: %s", v.Value)
166-
}
167-
provider.NoRefresh = b
168-
case "SCOPES":
169-
provider.Scopes = strings.Split(v.Value, " ")
170-
case "APP_INSTALL_URL":
171-
provider.AppInstallURL = v.Value
172-
case "APP_INSTALLATIONS_URL":
173-
provider.AppInstallationsURL = v.Value
174-
}
175-
providers[providerNum] = provider
176-
}
177-
return providers, nil
178-
}
179-
180101
func createOIDCConfig(ctx context.Context, vals *codersdk.DeploymentValues) (*coderd.OIDCConfig, error) {
181102
if vals.OIDC.ClientID == "" {
182103
return nil, xerrors.Errorf("OIDC client ID must be set!")
@@ -568,14 +489,14 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
568489
}
569490
}
570491

571-
gitAuthEnv, err := ReadGitAuthProvidersFromEnv(os.Environ())
492+
extAuthEnv, err := ReadExternalAuthProvidersFromEnv(os.Environ())
572493
if err != nil {
573-
return xerrors.Errorf("read git auth providers from env: %w", err)
494+
return xerrors.Errorf("read external auth providers from env: %w", err)
574495
}
575496

576-
vals.GitAuthProviders.Value = append(vals.GitAuthProviders.Value, gitAuthEnv...)
497+
vals.ExternalAuthConfigs.Value = append(vals.ExternalAuthConfigs.Value, extAuthEnv...)
577498
externalAuthConfigs, err := externalauth.ConvertConfig(
578-
vals.GitAuthProviders.Value,
499+
vals.ExternalAuthConfigs.Value,
579500
vals.AccessURL.Value(),
580501
)
581502
if err != nil {
@@ -816,7 +737,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
816737
if vals.Telemetry.Enable {
817738
gitAuth := make([]telemetry.GitAuth, 0)
818739
// TODO:
819-
var gitAuthConfigs []codersdk.GitAuthConfig
740+
var gitAuthConfigs []codersdk.ExternalAuthConfig
820741
for _, cfg := range gitAuthConfigs {
821742
gitAuth = append(gitAuth, telemetry.GitAuth{
822743
Type: cfg.Type,
@@ -2242,3 +2163,101 @@ func ConfigureHTTPServers(inv *clibase.Invocation, cfg *codersdk.DeploymentValue
22422163

22432164
return httpServers, nil
22442165
}
2166+
2167+
// ReadExternalAuthProvidersFromEnv is provided for compatibility purposes with
2168+
// the viper CLI.
2169+
func ReadExternalAuthProvidersFromEnv(environ []string) ([]codersdk.ExternalAuthConfig, error) {
2170+
providers, err := parseExternalAuthProvidersFromEnv("CODER_EXTERNAL_AUTH_", environ)
2171+
if err != nil {
2172+
return nil, err
2173+
}
2174+
// Deprecated: To support legacy git auth!
2175+
gitProviders, err := parseExternalAuthProvidersFromEnv("CODER_GITAUTH_", environ)
2176+
if err != nil {
2177+
return nil, err
2178+
}
2179+
return append(providers, gitProviders...), nil
2180+
}
2181+
2182+
// parseExternalAuthProvidersFromEnv consumes environment variables to parse
2183+
// external auth providers. A prefix is provided to support the legacy
2184+
// parsing of `GITAUTH` environment variables.
2185+
func parseExternalAuthProvidersFromEnv(prefix string, environ []string) ([]codersdk.ExternalAuthConfig, error) {
2186+
// The index numbers must be in-order.
2187+
sort.Strings(environ)
2188+
2189+
var providers []codersdk.ExternalAuthConfig
2190+
for _, v := range clibase.ParseEnviron(environ, prefix) {
2191+
tokens := strings.SplitN(v.Name, "_", 2)
2192+
if len(tokens) != 2 {
2193+
return nil, xerrors.Errorf("invalid env var: %s", v.Name)
2194+
}
2195+
2196+
providerNum, err := strconv.Atoi(tokens[0])
2197+
if err != nil {
2198+
return nil, xerrors.Errorf("parse number: %s", v.Name)
2199+
}
2200+
2201+
var provider codersdk.ExternalAuthConfig
2202+
switch {
2203+
case len(providers) < providerNum:
2204+
return nil, xerrors.Errorf(
2205+
"provider num %v skipped: %s",
2206+
len(providers),
2207+
v.Name,
2208+
)
2209+
case len(providers) == providerNum:
2210+
// At the next next provider.
2211+
providers = append(providers, provider)
2212+
case len(providers) == providerNum+1:
2213+
// At the current provider.
2214+
provider = providers[providerNum]
2215+
}
2216+
2217+
key := tokens[1]
2218+
switch key {
2219+
case "ID":
2220+
provider.ID = v.Value
2221+
case "TYPE":
2222+
provider.Type = v.Value
2223+
case "CLIENT_ID":
2224+
provider.ClientID = v.Value
2225+
case "CLIENT_SECRET":
2226+
provider.ClientSecret = v.Value
2227+
case "AUTH_URL":
2228+
provider.AuthURL = v.Value
2229+
case "TOKEN_URL":
2230+
provider.TokenURL = v.Value
2231+
case "VALIDATE_URL":
2232+
provider.ValidateURL = v.Value
2233+
case "REGEX":
2234+
provider.Regex = v.Value
2235+
case "DEVICE_FLOW":
2236+
b, err := strconv.ParseBool(v.Value)
2237+
if err != nil {
2238+
return nil, xerrors.Errorf("parse bool: %s", v.Value)
2239+
}
2240+
provider.DeviceFlow = b
2241+
case "DEVICE_CODE_URL":
2242+
provider.DeviceCodeURL = v.Value
2243+
case "NO_REFRESH":
2244+
b, err := strconv.ParseBool(v.Value)
2245+
if err != nil {
2246+
return nil, xerrors.Errorf("parse bool: %s", v.Value)
2247+
}
2248+
provider.NoRefresh = b
2249+
case "SCOPES":
2250+
provider.Scopes = strings.Split(v.Value, " ")
2251+
case "APP_INSTALL_URL":
2252+
provider.AppInstallURL = v.Value
2253+
case "APP_INSTALLATIONS_URL":
2254+
provider.AppInstallationsURL = v.Value
2255+
case "DISPLAY_NAME":
2256+
provider.DisplayName = v.Value
2257+
case "DISPLAY_ICON":
2258+
provider.DisplayIcon = v.Value
2259+
}
2260+
providers[providerNum] = provider
2261+
}
2262+
return providers, nil
2263+
}

0 commit comments

Comments
 (0)