From 10ccce1bd99210095895c27b21f04dda8d90cc30 Mon Sep 17 00:00:00 2001 From: joobisb Date: Mon, 14 Oct 2024 11:09:01 +0530 Subject: [PATCH 1/5] feat: expose 30d trial form via CLI --- cli/login.go | 176 +++++++++++++++++++++++++ cli/login_test.go | 90 ++++++++++++- cli/testdata/coder_login_--help.golden | 21 +++ coderd/coderdtest/coderdtest.go | 10 ++ docs/reference/cli/login.md | 63 +++++++++ 5 files changed, 359 insertions(+), 1 deletion(-) diff --git a/cli/login.go b/cli/login.go index 484de69fdf1b5..3e08b052115c6 100644 --- a/cli/login.go +++ b/cli/login.go @@ -149,6 +149,14 @@ func (r *RootCmd) login() *serpent.Command { password string trial bool useTokenForSession bool + + firstName string + lastName string + phoneNumber string + jobTitle string + companyName string + country string + developers string ) cmd := &serpent.Command{ Use: "login []", @@ -267,12 +275,66 @@ func (r *RootCmd) login() *serpent.Command { trial = v == "yes" || v == "y" } + if trial { + if firstName == "" { + firstName, err = promptTrialInfo(inv, "firstName") + if err != nil { + return err + } + } + if lastName == "" { + lastName, err = promptTrialInfo(inv, "lastName") + if err != nil { + return err + } + } + if phoneNumber == "" { + phoneNumber, err = promptTrialInfo(inv, "phoneNumber") + if err != nil { + return err + } + } + if jobTitle == "" { + jobTitle, err = promptTrialInfo(inv, "jobTitle") + if err != nil { + return err + } + } + if companyName == "" { + companyName, err = promptTrialInfo(inv, "companyName") + if err != nil { + return err + } + } + if country == "" { + country, err = promptCountry(inv) + if err != nil { + return err + } + } + if developers == "" { + developers, err = promptDevelopers(inv) + if err != nil { + return err + } + } + } + _, err = client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{ Email: email, Username: username, Name: name, Password: password, Trial: trial, + TrialInfo: codersdk.CreateFirstUserTrialInfo{ + FirstName: firstName, + LastName: lastName, + PhoneNumber: phoneNumber, + JobTitle: jobTitle, + CompanyName: companyName, + Country: country, + Developers: developers, + }, }) if err != nil { return xerrors.Errorf("create initial user: %w", err) @@ -398,6 +460,48 @@ func (r *RootCmd) login() *serpent.Command { Description: "By default, the CLI will generate a new session token when logging in. This flag will instead use the provided token as the session token.", Value: serpent.BoolOf(&useTokenForSession), }, + { + Flag: "first-user-first-name", + Env: "CODER_FIRST_USER_FIRST_NAME", + Description: "Specifies the first name of the user.", + Value: serpent.StringOf(&firstName), + }, + { + Flag: "first-user-last-name", + Env: "CODER_FIRST_USER_LAST_NAME", + Description: "Specifies the last name of the user.", + Value: serpent.StringOf(&lastName), + }, + { + Flag: "first-user-phone-number", + Env: "CODER_FIRST_USER_PHONE_NUMBER", + Description: "Specifies the phone number of the user.", + Value: serpent.StringOf(&phoneNumber), + }, + { + Flag: "first-user-job-title", + Env: "CODER_FIRST_USER_JOB_TITLE", + Description: "Specifies the job title of the user.", + Value: serpent.StringOf(&jobTitle), + }, + { + Flag: "first-user-company-name", + Env: "CODER_FIRST_USER_COMPANY_NAME", + Description: "Specifies the company name of the user.", + Value: serpent.StringOf(&companyName), + }, + { + Flag: "first-user-country", + Env: "CODER_FIRST_USER_COUNTRY", + Description: "Specifies the country of the user.", + Value: serpent.StringOf(&country), + }, + { + Flag: "first-user-developers", + Env: "CODER_FIRST_USER_DEVELOPERS", + Description: "Specifies the number of developers.", + Value: serpent.StringOf(&developers), + }, } return cmd } @@ -449,3 +553,75 @@ func openURL(inv *serpent.Invocation, urlToOpen string) error { return browser.OpenURL(urlToOpen) } + +func promptTrialInfo(inv *serpent.Invocation, fieldName string) (string, error) { + value, err := cliui.Prompt(inv, cliui.PromptOptions{ + Text: fmt.Sprintf("Please enter %s:", pretty.Sprint(cliui.DefaultStyles.Field, fieldName)), + Validate: func(s string) error { + if strings.TrimSpace(s) == "" { + return xerrors.Errorf("%s is required", fieldName) + } + return nil + }, + }) + if err != nil { + if errors.Is(err, cliui.Canceled) { + return "", nil + } + return "", err + } + return value, nil +} + +func promptDevelopers(inv *serpent.Invocation) (string, error) { + options := []string{"1-100", "101-500", "501-1000", "1001-2500", "2500+"} + selection, err := cliui.Select(inv, cliui.SelectOptions{ + Options: options, + HideSearch: false, + Message: "Select the number of developers:", + }) + if err != nil { + return "", xerrors.Errorf("select developers: %w", err) + } + return selection, nil +} + +func promptCountry(inv *serpent.Invocation) (string, error) { + countries := []string{ + "Afghanistan", "Åland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", + "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", + "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia, Plurinational State of", "Bonaire, Sint Eustatius and Saba", "Bosnia and Herzegovina", "Botswana", + "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", + "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", + "Congo", "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Côte d'Ivoire", "Croatia", "Cuba", "Curaçao", "Cyprus", "Czech Republic", + "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", + "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", + "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", + "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard Island and McDonald Islands", "Holy See (Vatican City State)", "Honduras", "Hong Kong", + "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Republic of", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", + "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", + "Kyrgyzstan", "Lao People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", + "Macao", "Macedonia, the Former Yugoslav Republic of", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", + "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of", "Monaco", "Mongolia", "Montenegro", "Montserrat", + "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "New Caledonia", "New Zealand", "Nicaragua", + "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Palestine, State of", + "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", + "Réunion", "Romania", "Russian Federation", "Rwanda", "Saint Barthélemy", "Saint Helena, Ascension and Tristan da Cunha", "Saint Kitts and Nevis", "Saint Lucia", "Saint Martin (French part)", "Saint Pierre and Miquelon", + "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", + "Sint Maarten (Dutch part)", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Sudan", "Spain", "Sri Lanka", + "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", + "Thailand", "Timor-Leste", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", + "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", + "Venezuela, Bolivarian Republic of", "Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.", "Wallis and Futuna", "Western Sahara", "Yemen", "Zambia", "Zimbabwe", + } + + selection, err := cliui.Select(inv, cliui.SelectOptions{ + Options: countries, + Message: "Select the country:", + HideSearch: false, + }) + if err != nil { + return "", xerrors.Errorf("select country: %w", err) + } + return selection, nil +} diff --git a/cli/login_test.go b/cli/login_test.go index 0428c332d02b0..92df197d76551 100644 --- a/cli/login_test.go +++ b/cli/login_test.go @@ -96,6 +96,58 @@ func TestLogin(t *testing.T) { "password", coderdtest.FirstUserParams.Password, "password", coderdtest.FirstUserParams.Password, // confirm "trial", "yes", + "firstName", coderdtest.TrialUserParams.FirstName, + "lastName", coderdtest.TrialUserParams.LastName, + "phoneNumber", coderdtest.TrialUserParams.PhoneNumber, + "jobTitle", coderdtest.TrialUserParams.JobTitle, + "companyName", coderdtest.TrialUserParams.CompanyName, + // `developers` and `country` `cliui.Select` automatically selects the first option during tests. + } + for i := 0; i < len(matches); i += 2 { + match := matches[i] + value := matches[i+1] + pty.ExpectMatch(match) + pty.WriteLine(value) + } + pty.ExpectMatch("Welcome to Coder") + <-doneChan + ctx := testutil.Context(t, testutil.WaitShort) + resp, err := client.LoginWithPassword(ctx, codersdk.LoginWithPasswordRequest{ + Email: coderdtest.FirstUserParams.Email, + Password: coderdtest.FirstUserParams.Password, + }) + require.NoError(t, err) + client.SetSessionToken(resp.SessionToken) + me, err := client.User(ctx, codersdk.Me) + require.NoError(t, err) + assert.Equal(t, coderdtest.FirstUserParams.Username, me.Username) + assert.Equal(t, coderdtest.FirstUserParams.Name, me.Name) + assert.Equal(t, coderdtest.FirstUserParams.Email, me.Email) + }) + + t.Run("InitialUserTTYWithNoTrial", func(t *testing.T) { + t.Parallel() + client := coderdtest.New(t, nil) + // The --force-tty flag is required on Windows, because the `isatty` library does not + // accurately detect Windows ptys when they are not attached to a process: + // https://github.com/mattn/go-isatty/issues/59 + doneChan := make(chan struct{}) + root, _ := clitest.New(t, "login", "--force-tty", client.URL.String()) + pty := ptytest.New(t).Attach(root) + go func() { + defer close(doneChan) + err := root.Run() + assert.NoError(t, err) + }() + + matches := []string{ + "first user?", "yes", + "username", coderdtest.FirstUserParams.Username, + "name", coderdtest.FirstUserParams.Name, + "email", coderdtest.FirstUserParams.Email, + "password", coderdtest.FirstUserParams.Password, + "password", coderdtest.FirstUserParams.Password, // confirm + "trial", "no", } for i := 0; i < len(matches); i += 2 { match := matches[i] @@ -142,6 +194,12 @@ func TestLogin(t *testing.T) { "password", coderdtest.FirstUserParams.Password, "password", coderdtest.FirstUserParams.Password, // confirm "trial", "yes", + "firstName", coderdtest.TrialUserParams.FirstName, + "lastName", coderdtest.TrialUserParams.LastName, + "phoneNumber", coderdtest.TrialUserParams.PhoneNumber, + "jobTitle", coderdtest.TrialUserParams.JobTitle, + "companyName", coderdtest.TrialUserParams.CompanyName, + // `developers` and `country` `cliui.Select` automatically selects the first option during tests. } for i := 0; i < len(matches); i += 2 { match := matches[i] @@ -185,6 +243,12 @@ func TestLogin(t *testing.T) { "password", coderdtest.FirstUserParams.Password, "password", coderdtest.FirstUserParams.Password, // confirm "trial", "yes", + "firstName", coderdtest.TrialUserParams.FirstName, + "lastName", coderdtest.TrialUserParams.LastName, + "phoneNumber", coderdtest.TrialUserParams.PhoneNumber, + "jobTitle", coderdtest.TrialUserParams.JobTitle, + "companyName", coderdtest.TrialUserParams.CompanyName, + // `developers` and `country` `cliui.Select` automatically selects the first option during tests. } for i := 0; i < len(matches); i += 2 { match := matches[i] @@ -217,6 +281,13 @@ func TestLogin(t *testing.T) { "--first-user-email", coderdtest.FirstUserParams.Email, "--first-user-password", coderdtest.FirstUserParams.Password, "--first-user-trial", + "--first-user-first-name", coderdtest.TrialUserParams.FirstName, + "--first-user-last-name", coderdtest.TrialUserParams.LastName, + "--first-user-phone-number", coderdtest.TrialUserParams.PhoneNumber, + "--first-user-job-title", coderdtest.TrialUserParams.JobTitle, + "--first-user-company-name", coderdtest.TrialUserParams.CompanyName, + "--first-user-country", coderdtest.TrialUserParams.Country, + "--first-user-developers", coderdtest.TrialUserParams.Developers, ) pty := ptytest.New(t).Attach(inv) w := clitest.StartWithWaiter(t, inv) @@ -245,6 +316,14 @@ func TestLogin(t *testing.T) { "--first-user-email", coderdtest.FirstUserParams.Email, "--first-user-password", coderdtest.FirstUserParams.Password, "--first-user-trial", + "--first-user-first-name", coderdtest.TrialUserParams.FirstName, + "--first-user-last-name", coderdtest.TrialUserParams.LastName, + "--first-user-phone-number", coderdtest.TrialUserParams.PhoneNumber, + "--first-user-job-title", coderdtest.TrialUserParams.JobTitle, + "--first-user-company-name", coderdtest.TrialUserParams.CompanyName, + "--first-user-country", coderdtest.TrialUserParams.Country, + "--first-user-developers", coderdtest.TrialUserParams.Developers, + // `developers` and `country` `cliui.Select` automatically selects the first option during tests. ) pty := ptytest.New(t).Attach(inv) w := clitest.StartWithWaiter(t, inv) @@ -299,12 +378,21 @@ func TestLogin(t *testing.T) { // Validate that we reprompt for matching passwords. pty.ExpectMatch("Passwords do not match") pty.ExpectMatch("Enter a " + pretty.Sprint(cliui.DefaultStyles.Field, "password")) - pty.WriteLine(coderdtest.FirstUserParams.Password) pty.ExpectMatch("Confirm") pty.WriteLine(coderdtest.FirstUserParams.Password) pty.ExpectMatch("trial") pty.WriteLine("yes") + pty.ExpectMatch("firstName") + pty.WriteLine(coderdtest.TrialUserParams.FirstName) + pty.ExpectMatch("lastName") + pty.WriteLine(coderdtest.TrialUserParams.LastName) + pty.ExpectMatch("phoneNumber") + pty.WriteLine(coderdtest.TrialUserParams.PhoneNumber) + pty.ExpectMatch("jobTitle") + pty.WriteLine(coderdtest.TrialUserParams.JobTitle) + pty.ExpectMatch("companyName") + pty.WriteLine(coderdtest.TrialUserParams.CompanyName) pty.ExpectMatch("Welcome to Coder") <-doneChan }) diff --git a/cli/testdata/coder_login_--help.golden b/cli/testdata/coder_login_--help.golden index e4109a494ed39..2ffb7522c2911 100644 --- a/cli/testdata/coder_login_--help.golden +++ b/cli/testdata/coder_login_--help.golden @@ -6,17 +6,38 @@ USAGE: Authenticate with Coder deployment OPTIONS: + --first-user-company-name string, $CODER_FIRST_USER_COMPANY_NAME + Specifies the company name of the user. + + --first-user-country string, $CODER_FIRST_USER_COUNTRY + Specifies the country of the user. + + --first-user-developers string, $CODER_FIRST_USER_DEVELOPERS + Specifies the number of developers. + --first-user-email string, $CODER_FIRST_USER_EMAIL Specifies an email address to use if creating the first user for the deployment. + --first-user-first-name string, $CODER_FIRST_USER_FIRST_NAME + Specifies the first name of the user. + --first-user-full-name string, $CODER_FIRST_USER_FULL_NAME Specifies a human-readable name for the first user of the deployment. + --first-user-job-title string, $CODER_FIRST_USER_JOB_TITLE + Specifies the job title of the user. + + --first-user-last-name string, $CODER_FIRST_USER_LAST_NAME + Specifies the last name of the user. + --first-user-password string, $CODER_FIRST_USER_PASSWORD Specifies a password to use if creating the first user for the deployment. + --first-user-phone-number string, $CODER_FIRST_USER_PHONE_NUMBER + Specifies the phone number of the user. + --first-user-trial bool, $CODER_FIRST_USER_TRIAL Specifies whether a trial license should be provisioned for the Coder deployment or not. diff --git a/coderd/coderdtest/coderdtest.go b/coderd/coderdtest/coderdtest.go index 05c31f35bd20a..5ed667aded5e8 100644 --- a/coderd/coderdtest/coderdtest.go +++ b/coderd/coderdtest/coderdtest.go @@ -651,6 +651,16 @@ var FirstUserParams = codersdk.CreateFirstUserRequest{ Name: "Test User", } +var TrialUserParams = codersdk.CreateFirstUserTrialInfo{ + FirstName: "John", + LastName: "Doe", + PhoneNumber: "9999999999", + JobTitle: "Engineer", + CompanyName: "Acme Inc", + Country: "United States", + Developers: "10-50", +} + // CreateFirstUser creates a user with preset credentials and authenticates // with the passed in codersdk client. func CreateFirstUser(t testing.TB, client *codersdk.Client) codersdk.CreateFirstUserResponse { diff --git a/docs/reference/cli/login.md b/docs/reference/cli/login.md index 9a27e4a6357c8..7ec3e201506cb 100644 --- a/docs/reference/cli/login.md +++ b/docs/reference/cli/login.md @@ -64,3 +64,66 @@ Specifies whether a trial license should be provisioned for the Coder deployment | Type | bool | By default, the CLI will generate a new session token when logging in. This flag will instead use the provided token as the session token. + +### --first-user-first-name + +| | | +| ----------- | ----------------------------------------- | +| Type | string | +| Environment | $CODER_FIRST_USER_FIRST_NAME | + +Specifies the first name of the user. + +### --first-user-last-name + +| | | +| ----------- | ---------------------------------------- | +| Type | string | +| Environment | $CODER_FIRST_USER_LAST_NAME | + +Specifies the last name of the user. + +### --first-user-phone-number + +| | | +| ----------- | ------------------------------------------- | +| Type | string | +| Environment | $CODER_FIRST_USER_PHONE_NUMBER | + +Specifies the phone number of the user. + +### --first-user-job-title + +| | | +| ----------- | ---------------------------------------- | +| Type | string | +| Environment | $CODER_FIRST_USER_JOB_TITLE | + +Specifies the job title of the user. + +### --first-user-company-name + +| | | +| ----------- | ------------------------------------------- | +| Type | string | +| Environment | $CODER_FIRST_USER_COMPANY_NAME | + +Specifies the company name of the user. + +### --first-user-country + +| | | +| ----------- | -------------------------------------- | +| Type | string | +| Environment | $CODER_FIRST_USER_COUNTRY | + +Specifies the country of the user. + +### --first-user-developers + +| | | +| ----------- | ----------------------------------------- | +| Type | string | +| Environment | $CODER_FIRST_USER_DEVELOPERS | + +Specifies the number of developers. From af7cf3b10ee5265e0c10fcc1c73f46eee7cbfed0 Mon Sep 17 00:00:00 2001 From: joobisb Date: Wed, 16 Oct 2024 10:41:08 +0530 Subject: [PATCH 2/5] remove trial params as env --- cli/login.go | 99 ++++++-------------------- cli/login_test.go | 37 ++++++---- cli/testdata/coder_login_--help.golden | 21 ------ docs/reference/cli/login.md | 63 ---------------- 4 files changed, 43 insertions(+), 177 deletions(-) diff --git a/cli/login.go b/cli/login.go index 3e08b052115c6..a4dcca7c66c52 100644 --- a/cli/login.go +++ b/cli/login.go @@ -149,14 +149,6 @@ func (r *RootCmd) login() *serpent.Command { password string trial bool useTokenForSession bool - - firstName string - lastName string - phoneNumber string - jobTitle string - companyName string - country string - developers string ) cmd := &serpent.Command{ Use: "login []", @@ -275,45 +267,46 @@ func (r *RootCmd) login() *serpent.Command { trial = v == "yes" || v == "y" } + var trialInfo codersdk.CreateFirstUserTrialInfo if trial { - if firstName == "" { - firstName, err = promptTrialInfo(inv, "firstName") + if trialInfo.FirstName == "" { + trialInfo.FirstName, err = promptTrialInfo(inv, "firstName") if err != nil { return err } } - if lastName == "" { - lastName, err = promptTrialInfo(inv, "lastName") + if trialInfo.LastName == "" { + trialInfo.LastName, err = promptTrialInfo(inv, "lastName") if err != nil { return err } } - if phoneNumber == "" { - phoneNumber, err = promptTrialInfo(inv, "phoneNumber") + if trialInfo.PhoneNumber == "" { + trialInfo.PhoneNumber, err = promptTrialInfo(inv, "phoneNumber") if err != nil { return err } } - if jobTitle == "" { - jobTitle, err = promptTrialInfo(inv, "jobTitle") + if trialInfo.JobTitle == "" { + trialInfo.JobTitle, err = promptTrialInfo(inv, "jobTitle") if err != nil { return err } } - if companyName == "" { - companyName, err = promptTrialInfo(inv, "companyName") + if trialInfo.CompanyName == "" { + trialInfo.CompanyName, err = promptTrialInfo(inv, "companyName") if err != nil { return err } } - if country == "" { - country, err = promptCountry(inv) + if trialInfo.Country == "" { + trialInfo.Country, err = promptCountry(inv) if err != nil { return err } } - if developers == "" { - developers, err = promptDevelopers(inv) + if trialInfo.Developers == "" { + trialInfo.Developers, err = promptDevelopers(inv) if err != nil { return err } @@ -321,20 +314,12 @@ func (r *RootCmd) login() *serpent.Command { } _, err = client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{ - Email: email, - Username: username, - Name: name, - Password: password, - Trial: trial, - TrialInfo: codersdk.CreateFirstUserTrialInfo{ - FirstName: firstName, - LastName: lastName, - PhoneNumber: phoneNumber, - JobTitle: jobTitle, - CompanyName: companyName, - Country: country, - Developers: developers, - }, + Email: email, + Username: username, + Name: name, + Password: password, + Trial: trial, + TrialInfo: trialInfo, }) if err != nil { return xerrors.Errorf("create initial user: %w", err) @@ -460,48 +445,6 @@ func (r *RootCmd) login() *serpent.Command { Description: "By default, the CLI will generate a new session token when logging in. This flag will instead use the provided token as the session token.", Value: serpent.BoolOf(&useTokenForSession), }, - { - Flag: "first-user-first-name", - Env: "CODER_FIRST_USER_FIRST_NAME", - Description: "Specifies the first name of the user.", - Value: serpent.StringOf(&firstName), - }, - { - Flag: "first-user-last-name", - Env: "CODER_FIRST_USER_LAST_NAME", - Description: "Specifies the last name of the user.", - Value: serpent.StringOf(&lastName), - }, - { - Flag: "first-user-phone-number", - Env: "CODER_FIRST_USER_PHONE_NUMBER", - Description: "Specifies the phone number of the user.", - Value: serpent.StringOf(&phoneNumber), - }, - { - Flag: "first-user-job-title", - Env: "CODER_FIRST_USER_JOB_TITLE", - Description: "Specifies the job title of the user.", - Value: serpent.StringOf(&jobTitle), - }, - { - Flag: "first-user-company-name", - Env: "CODER_FIRST_USER_COMPANY_NAME", - Description: "Specifies the company name of the user.", - Value: serpent.StringOf(&companyName), - }, - { - Flag: "first-user-country", - Env: "CODER_FIRST_USER_COUNTRY", - Description: "Specifies the country of the user.", - Value: serpent.StringOf(&country), - }, - { - Flag: "first-user-developers", - Env: "CODER_FIRST_USER_DEVELOPERS", - Description: "Specifies the number of developers.", - Value: serpent.StringOf(&developers), - }, } return cmd } diff --git a/cli/login_test.go b/cli/login_test.go index 92df197d76551..9a86e7caad351 100644 --- a/cli/login_test.go +++ b/cli/login_test.go @@ -281,16 +281,20 @@ func TestLogin(t *testing.T) { "--first-user-email", coderdtest.FirstUserParams.Email, "--first-user-password", coderdtest.FirstUserParams.Password, "--first-user-trial", - "--first-user-first-name", coderdtest.TrialUserParams.FirstName, - "--first-user-last-name", coderdtest.TrialUserParams.LastName, - "--first-user-phone-number", coderdtest.TrialUserParams.PhoneNumber, - "--first-user-job-title", coderdtest.TrialUserParams.JobTitle, - "--first-user-company-name", coderdtest.TrialUserParams.CompanyName, - "--first-user-country", coderdtest.TrialUserParams.Country, - "--first-user-developers", coderdtest.TrialUserParams.Developers, ) pty := ptytest.New(t).Attach(inv) w := clitest.StartWithWaiter(t, inv) + pty.ExpectMatch("firstName") + pty.WriteLine(coderdtest.TrialUserParams.FirstName) + pty.ExpectMatch("lastName") + pty.WriteLine(coderdtest.TrialUserParams.LastName) + pty.ExpectMatch("phoneNumber") + pty.WriteLine(coderdtest.TrialUserParams.PhoneNumber) + pty.ExpectMatch("jobTitle") + pty.WriteLine(coderdtest.TrialUserParams.JobTitle) + pty.ExpectMatch("companyName") + pty.WriteLine(coderdtest.TrialUserParams.CompanyName) + // `developers` and `country` `cliui.Select` automatically selects the first option during tests. pty.ExpectMatch("Welcome to Coder") w.RequireSuccess() ctx := testutil.Context(t, testutil.WaitShort) @@ -316,17 +320,20 @@ func TestLogin(t *testing.T) { "--first-user-email", coderdtest.FirstUserParams.Email, "--first-user-password", coderdtest.FirstUserParams.Password, "--first-user-trial", - "--first-user-first-name", coderdtest.TrialUserParams.FirstName, - "--first-user-last-name", coderdtest.TrialUserParams.LastName, - "--first-user-phone-number", coderdtest.TrialUserParams.PhoneNumber, - "--first-user-job-title", coderdtest.TrialUserParams.JobTitle, - "--first-user-company-name", coderdtest.TrialUserParams.CompanyName, - "--first-user-country", coderdtest.TrialUserParams.Country, - "--first-user-developers", coderdtest.TrialUserParams.Developers, - // `developers` and `country` `cliui.Select` automatically selects the first option during tests. ) pty := ptytest.New(t).Attach(inv) w := clitest.StartWithWaiter(t, inv) + pty.ExpectMatch("firstName") + pty.WriteLine(coderdtest.TrialUserParams.FirstName) + pty.ExpectMatch("lastName") + pty.WriteLine(coderdtest.TrialUserParams.LastName) + pty.ExpectMatch("phoneNumber") + pty.WriteLine(coderdtest.TrialUserParams.PhoneNumber) + pty.ExpectMatch("jobTitle") + pty.WriteLine(coderdtest.TrialUserParams.JobTitle) + pty.ExpectMatch("companyName") + pty.WriteLine(coderdtest.TrialUserParams.CompanyName) + // `developers` and `country` `cliui.Select` automatically selects the first option during tests. pty.ExpectMatch("Welcome to Coder") w.RequireSuccess() ctx := testutil.Context(t, testutil.WaitShort) diff --git a/cli/testdata/coder_login_--help.golden b/cli/testdata/coder_login_--help.golden index 2ffb7522c2911..e4109a494ed39 100644 --- a/cli/testdata/coder_login_--help.golden +++ b/cli/testdata/coder_login_--help.golden @@ -6,38 +6,17 @@ USAGE: Authenticate with Coder deployment OPTIONS: - --first-user-company-name string, $CODER_FIRST_USER_COMPANY_NAME - Specifies the company name of the user. - - --first-user-country string, $CODER_FIRST_USER_COUNTRY - Specifies the country of the user. - - --first-user-developers string, $CODER_FIRST_USER_DEVELOPERS - Specifies the number of developers. - --first-user-email string, $CODER_FIRST_USER_EMAIL Specifies an email address to use if creating the first user for the deployment. - --first-user-first-name string, $CODER_FIRST_USER_FIRST_NAME - Specifies the first name of the user. - --first-user-full-name string, $CODER_FIRST_USER_FULL_NAME Specifies a human-readable name for the first user of the deployment. - --first-user-job-title string, $CODER_FIRST_USER_JOB_TITLE - Specifies the job title of the user. - - --first-user-last-name string, $CODER_FIRST_USER_LAST_NAME - Specifies the last name of the user. - --first-user-password string, $CODER_FIRST_USER_PASSWORD Specifies a password to use if creating the first user for the deployment. - --first-user-phone-number string, $CODER_FIRST_USER_PHONE_NUMBER - Specifies the phone number of the user. - --first-user-trial bool, $CODER_FIRST_USER_TRIAL Specifies whether a trial license should be provisioned for the Coder deployment or not. diff --git a/docs/reference/cli/login.md b/docs/reference/cli/login.md index 7ec3e201506cb..9a27e4a6357c8 100644 --- a/docs/reference/cli/login.md +++ b/docs/reference/cli/login.md @@ -64,66 +64,3 @@ Specifies whether a trial license should be provisioned for the Coder deployment | Type | bool | By default, the CLI will generate a new session token when logging in. This flag will instead use the provided token as the session token. - -### --first-user-first-name - -| | | -| ----------- | ----------------------------------------- | -| Type | string | -| Environment | $CODER_FIRST_USER_FIRST_NAME | - -Specifies the first name of the user. - -### --first-user-last-name - -| | | -| ----------- | ---------------------------------------- | -| Type | string | -| Environment | $CODER_FIRST_USER_LAST_NAME | - -Specifies the last name of the user. - -### --first-user-phone-number - -| | | -| ----------- | ------------------------------------------- | -| Type | string | -| Environment | $CODER_FIRST_USER_PHONE_NUMBER | - -Specifies the phone number of the user. - -### --first-user-job-title - -| | | -| ----------- | ---------------------------------------- | -| Type | string | -| Environment | $CODER_FIRST_USER_JOB_TITLE | - -Specifies the job title of the user. - -### --first-user-company-name - -| | | -| ----------- | ------------------------------------------- | -| Type | string | -| Environment | $CODER_FIRST_USER_COMPANY_NAME | - -Specifies the company name of the user. - -### --first-user-country - -| | | -| ----------- | -------------------------------------- | -| Type | string | -| Environment | $CODER_FIRST_USER_COUNTRY | - -Specifies the country of the user. - -### --first-user-developers - -| | | -| ----------- | ----------------------------------------- | -| Type | string | -| Environment | $CODER_FIRST_USER_DEVELOPERS | - -Specifies the number of developers. From 2ed44c823f2a6636afe17bcd02cb1ffad57fe99e Mon Sep 17 00:00:00 2001 From: joobisb Date: Wed, 16 Oct 2024 13:48:34 +0530 Subject: [PATCH 3/5] set first-user-trial to false in deploy-pr workflow --- .github/workflows/pr-deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 1e7de50d2b21d..6b6cf1e18b2f3 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -410,7 +410,7 @@ jobs: --first-user-username coder \ --first-user-email pr${{ env.PR_NUMBER }}@coder.com \ --first-user-password $password \ - --first-user-trial \ + --first-user-trial=false \ --use-token-as-session \ https://${{ env.PR_HOSTNAME }} From 411d7d0f947d0b590dd0a2f6cc75372280685783 Mon Sep 17 00:00:00 2001 From: joobisb Date: Thu, 17 Oct 2024 14:24:57 +0530 Subject: [PATCH 4/5] fix typo --- cli/login.go | 2 +- site/src/pages/SetupPage/countries.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/login.go b/cli/login.go index a4dcca7c66c52..3bb4f0796e4a5 100644 --- a/cli/login.go +++ b/cli/login.go @@ -555,7 +555,7 @@ func promptCountry(inv *serpent.Invocation) (string, error) { "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Timor-Leste", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", - "Venezuela, Bolivarian Republic of", "Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.", "Wallis and Futuna", "Western Sahara", "Yemen", "Zambia", "Zimbabwe", + "Venezuela, Bolivarian Republic of", "Vietnam", "Virgin Islands, British", "Virgin Islands, U.S.", "Wallis and Futuna", "Western Sahara", "Yemen", "Zambia", "Zimbabwe", } selection, err := cliui.Select(inv, cliui.SelectOptions{ diff --git a/site/src/pages/SetupPage/countries.tsx b/site/src/pages/SetupPage/countries.tsx index 0fcebc25ac54d..9b13b6b6be0d9 100644 --- a/site/src/pages/SetupPage/countries.tsx +++ b/site/src/pages/SetupPage/countries.tsx @@ -964,7 +964,7 @@ export const countries = [ flag: "🇻🇪", }, { - name: "Viet Nam", + name: "Vietnam", flag: "🇻🇳", }, { From 10d718f7be73836ac08593d0f201379ab5665b08 Mon Sep 17 00:00:00 2001 From: joobisb Date: Thu, 17 Oct 2024 17:14:10 +0530 Subject: [PATCH 5/5] set first-user-trial to false in develop.sh --- scripts/develop.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/develop.sh b/scripts/develop.sh index bdaf81c7536e5..7dfad72d2e9f6 100755 --- a/scripts/develop.sh +++ b/scripts/develop.sh @@ -164,7 +164,7 @@ fatal() { if [ ! -f "${PROJECT_ROOT}/.coderv2/developsh-did-first-setup" ]; then # Try to create the initial admin user. - if "${CODER_DEV_SHIM}" login http://127.0.0.1:3000 --first-user-username=admin --first-user-email=admin@coder.com --first-user-password="${password}" --first-user-full-name="Admin User" --first-user-trial=true; then + if "${CODER_DEV_SHIM}" login http://127.0.0.1:3000 --first-user-username=admin --first-user-email=admin@coder.com --first-user-password="${password}" --first-user-full-name="Admin User" --first-user-trial=false; then # Only create this file if an admin user was successfully # created, otherwise we won't retry on a later attempt. touch "${PROJECT_ROOT}/.coderv2/developsh-did-first-setup"