feat: Add the option to generate a trial license during setup (#5110)

This allows users to generate a 30 day free license during setup to
test out Enterprise features.
This commit is contained in:
Kyle Carberry
2022-11-16 17:09:49 -06:00
committed by GitHub
parent b6703b11c6
commit fb9ca7b830
29 changed files with 332 additions and 79 deletions
+17 -4
View File
@@ -38,10 +38,13 @@ func init() {
}
func login() *cobra.Command {
const firstUserTrialEnv = "CODER_FIRST_USER_TRIAL"
var (
email string
username string
password string
trial bool
)
cmd := &cobra.Command{
Use: "login <url>",
@@ -162,11 +165,20 @@ func login() *cobra.Command {
}
}
if !cmd.Flags().Changed("first-user-trial") && os.Getenv(firstUserTrialEnv) == "" {
v, _ := cliui.Prompt(cmd, cliui.PromptOptions{
Text: "Start a 30-day trial of Enterprise?",
IsConfirm: true,
Default: "yes",
})
trial = v == "yes" || v == "y"
}
_, err = client.CreateFirstUser(cmd.Context(), codersdk.CreateFirstUserRequest{
Email: email,
Username: username,
OrganizationName: username,
Password: password,
Email: email,
Username: username,
Password: password,
Trial: trial,
})
if err != nil {
return xerrors.Errorf("create initial user: %w", err)
@@ -251,6 +263,7 @@ func login() *cobra.Command {
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.")
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.")
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.")
cliflag.BoolVarP(cmd.Flags(), &trial, "first-user-trial", "", firstUserTrialEnv, false, "Specifies whether a trial license should be provisioned for the Coder deployment or not.")
return cmd
}
+4 -1
View File
@@ -56,6 +56,7 @@ func TestLogin(t *testing.T) {
"email", "user@coder.com",
"password", "password",
"password", "password", // Confirm.
"trial", "yes",
}
for i := 0; i < len(matches); i += 2 {
match := matches[i]
@@ -74,7 +75,7 @@ func TestLogin(t *testing.T) {
// 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", client.URL.String(), "--first-user-username", "testuser", "--first-user-email", "user@coder.com", "--first-user-password", "password")
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")
pty := ptytest.New(t)
root.SetIn(pty.Input())
root.SetOut(pty.Output())
@@ -127,6 +128,8 @@ func TestLogin(t *testing.T) {
pty.WriteLine("pass")
pty.ExpectMatch("Confirm")
pty.WriteLine("pass")
pty.ExpectMatch("trial")
pty.WriteLine("yes")
pty.ExpectMatch("Welcome to Coder")
<-doneChan
})
+3 -4
View File
@@ -60,10 +60,9 @@ func TestResetPassword(t *testing.T) {
client := codersdk.New(accessURL)
_, err = client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{
Email: email,
Username: username,
Password: oldPassword,
OrganizationName: "example",
Email: email,
Username: username,
Password: oldPassword,
})
require.NoError(t, err)
+3 -4
View File
@@ -71,10 +71,9 @@ func TestServer(t *testing.T) {
client := codersdk.New(accessURL)
_, err = client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{
Email: "some@one.com",
Username: "example",
Password: "password",
OrganizationName: "example",
Email: "some@one.com",
Username: "example",
Password: "password",
})
require.NoError(t, err)
cancelFunc()