Skip to content

Commit 08b2814

Browse files
committed
Merge remote-tracking branch 'origin/main' into pb-improvements
2 parents 6f914a4 + 60cec02 commit 08b2814

File tree

80 files changed

+1458
-476
lines changed

Some content is hidden

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

80 files changed

+1458
-476
lines changed

.github/workflows/typos.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ MacOS = "macOS"
99
doas = "doas"
1010
darcula = "darcula"
1111
Hashi = "Hashi"
12+
trialer = "trialer"
1213

1314
[files]
1415
extend-exclude = [

.golangci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ linters-settings:
123123

124124
misspell:
125125
locale: US
126+
ignore-words:
127+
- trialer
126128

127129
nestif:
128130
min-complexity: 4 # Min complexity of if statements (def 5, goal 4)

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"codersdk",
1818
"cronstrue",
1919
"databasefake",
20+
"dbtype",
2021
"DERP",
2122
"derphttp",
2223
"derpmap",
@@ -127,6 +128,7 @@
127128
"tfstate",
128129
"tios",
129130
"tparallel",
131+
"trialer",
130132
"trimprefix",
131133
"tsdial",
132134
"tslogger",

cli/deployment/config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func newConfig() *codersdk.DeploymentConfig {
143143
Name: "Cache Directory",
144144
Usage: "The directory to cache temporary files. If unspecified and $CACHE_DIRECTORY is set, it will be used for compatibility with systemd.",
145145
Flag: "cache-dir",
146-
Default: defaultCacheDir(),
146+
Default: DefaultCacheDir(),
147147
},
148148
InMemoryDatabase: &codersdk.DeploymentConfigField[bool]{
149149
Name: "In Memory Database",
@@ -529,9 +529,11 @@ func readSliceFromViper[T any](vip *viper.Viper, key string, value any) []T {
529529
newType := reflect.Indirect(reflect.New(elementType))
530530
instance = &newType
531531
}
532-
switch instance.Field(i).Type().String() {
532+
switch v := instance.Field(i).Type().String(); v {
533533
case "[]string":
534534
value = vip.GetStringSlice(configKey)
535+
case "bool":
536+
value = vip.GetBool(configKey)
535537
default:
536538
}
537539
instance.Field(i).Set(reflect.ValueOf(value))
@@ -672,7 +674,7 @@ func formatEnv(key string) string {
672674
return "CODER_" + strings.ToUpper(strings.NewReplacer("-", "_", ".", "_").Replace(key))
673675
}
674676

675-
func defaultCacheDir() string {
677+
func DefaultCacheDir() string {
676678
defaultCacheDir, err := os.UserCacheDir()
677679
if err != nil {
678680
defaultCacheDir = os.TempDir()

cli/deployment/config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ func TestConfig(t *testing.T) {
167167
"CODER_GITAUTH_0_TOKEN_URL": "https://token.com",
168168
"CODER_GITAUTH_0_REGEX": "github.com",
169169
"CODER_GITAUTH_0_SCOPES": "read write",
170+
"CODER_GITAUTH_0_NO_REFRESH": "true",
170171

171172
"CODER_GITAUTH_1_ID": "another",
172173
"CODER_GITAUTH_1_TYPE": "gitlab",
@@ -187,6 +188,7 @@ func TestConfig(t *testing.T) {
187188
TokenURL: "https://token.com",
188189
Regex: "github.com",
189190
Scopes: []string{"read", "write"},
191+
NoRefresh: true,
190192
}, {
191193
ID: "another",
192194
Type: "gitlab",

cli/gitaskpass.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func gitAskpass() *cobra.Command {
2626
RunE: func(cmd *cobra.Command, args []string) error {
2727
ctx := cmd.Context()
2828

29-
ctx, stop := signal.NotifyContext(ctx, interruptSignals...)
29+
ctx, stop := signal.NotifyContext(ctx, InterruptSignals...)
3030
defer stop()
3131

3232
user, host, err := gitauth.ParseAskpass(args[0])

cli/gitssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func gitssh() *cobra.Command {
2929

3030
// Catch interrupt signals to ensure the temporary private
3131
// key file is cleaned up on most cases.
32-
ctx, stop := signal.NotifyContext(ctx, interruptSignals...)
32+
ctx, stop := signal.NotifyContext(ctx, InterruptSignals...)
3333
defer stop()
3434

3535
// Early check so errors are reported immediately.

cli/login.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ func init() {
3838
}
3939

4040
func login() *cobra.Command {
41+
const firstUserTrialEnv = "CODER_FIRST_USER_TRIAL"
42+
4143
var (
4244
email string
4345
username string
4446
password string
47+
trial bool
4548
)
4649
cmd := &cobra.Command{
4750
Use: "login <url>",
@@ -162,11 +165,20 @@ func login() *cobra.Command {
162165
}
163166
}
164167

168+
if !cmd.Flags().Changed("first-user-trial") && os.Getenv(firstUserTrialEnv) == "" {
169+
v, _ := cliui.Prompt(cmd, cliui.PromptOptions{
170+
Text: "Start a 30-day trial of Enterprise?",
171+
IsConfirm: true,
172+
Default: "yes",
173+
})
174+
trial = v == "yes" || v == "y"
175+
}
176+
165177
_, err = client.CreateFirstUser(cmd.Context(), codersdk.CreateFirstUserRequest{
166-
Email: email,
167-
Username: username,
168-
OrganizationName: username,
169-
Password: password,
178+
Email: email,
179+
Username: username,
180+
Password: password,
181+
Trial: trial,
170182
})
171183
if err != nil {
172184
return xerrors.Errorf("create initial user: %w", err)
@@ -251,6 +263,7 @@ func login() *cobra.Command {
251263
cliflag.StringVarP(cmd.Flags(), &email, "first-user-email", "", "CODER_FIRST_USER_EMAIL", "", "Specifies an email address to use if creating the first user for the deployment.")
252264
cliflag.StringVarP(cmd.Flags(), &username, "first-user-username", "", "CODER_FIRST_USER_USERNAME", "", "Specifies a username to use if creating the first user for the deployment.")
253265
cliflag.StringVarP(cmd.Flags(), &password, "first-user-password", "", "CODER_FIRST_USER_PASSWORD", "", "Specifies a password to use if creating the first user for the deployment.")
266+
cliflag.BoolVarP(cmd.Flags(), &trial, "first-user-trial", "", firstUserTrialEnv, false, "Specifies whether a trial license should be provisioned for the Coder deployment or not.")
254267
return cmd
255268
}
256269

cli/login_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func TestLogin(t *testing.T) {
5656
"email", "user@coder.com",
5757
"password", "password",
5858
"password", "password", // Confirm.
59+
"trial", "yes",
5960
}
6061
for i := 0; i < len(matches); i += 2 {
6162
match := matches[i]
@@ -74,7 +75,7 @@ func TestLogin(t *testing.T) {
7475
// accurately detect Windows ptys when they are not attached to a process:
7576
// https://github.com/mattn/go-isatty/issues/59
7677
doneChan := make(chan struct{})
77-
root, _ := clitest.New(t, "login", client.URL.String(), "--first-user-username", "testuser", "--first-user-email", "user@coder.com", "--first-user-password", "password")
78+
root, _ := clitest.New(t, "login", client.URL.String(), "--first-user-username", "testuser", "--first-user-email", "user@coder.com", "--first-user-password", "password", "--first-user-trial")
7879
pty := ptytest.New(t)
7980
root.SetIn(pty.Input())
8081
root.SetOut(pty.Output())
@@ -127,6 +128,8 @@ func TestLogin(t *testing.T) {
127128
pty.WriteLine("pass")
128129
pty.ExpectMatch("Confirm")
129130
pty.WriteLine("pass")
131+
pty.ExpectMatch("trial")
132+
pty.WriteLine("yes")
130133
pty.ExpectMatch("Welcome to Coder")
131134
<-doneChan
132135
})

cli/resetpassword_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ func TestResetPassword(t *testing.T) {
6060
client := codersdk.New(accessURL)
6161

6262
_, err = client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{
63-
Email: email,
64-
Username: username,
65-
Password: oldPassword,
66-
OrganizationName: "example",
63+
Email: email,
64+
Username: username,
65+
Password: oldPassword,
6766
})
6867
require.NoError(t, err)
6968

0 commit comments

Comments
 (0)