Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit c6e76a1

Browse files
Merge pull request #164 from secrethub/feature/signup-org-init
Ask to create an organization on signup
2 parents 7001463 + 55a8940 commit c6e76a1

1 file changed

Lines changed: 45 additions & 4 deletions

File tree

internals/secrethub/signup.go

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ type SignUpCommand struct {
2323
username string
2424
fullName string
2525
email string
26+
org string
27+
orgDescription string
2628
force bool
2729
io ui.IO
2830
newClient newClientFunc
@@ -43,9 +45,11 @@ func NewSignUpCommand(io ui.IO, newClient newClientFunc, credentialStore Credent
4345
// Register registers the command, arguments and flags on the provided Registerer.
4446
func (cmd *SignUpCommand) Register(r command.Registerer) {
4547
clause := r.Command("signup", "Create a free personal developer account.")
46-
clause.Flag("username", "The username you would like to use on SecretHub. If not set, you will be asked for it.").StringVar(&cmd.username)
47-
clause.Flag("full-name", "If not set, you will be asked to provide your full name.").StringVar(&cmd.fullName)
48-
clause.Flag("email", "If not set, you will be asked to provide your email address.").StringVar(&cmd.email)
48+
clause.Flag("username", "The username you would like to use on SecretHub.").StringVar(&cmd.username)
49+
clause.Flag("full-name", "Your full name.").StringVar(&cmd.fullName)
50+
clause.Flag("email", "Your (work) email address we will use for all correspondence.").StringVar(&cmd.email)
51+
clause.Flag("org", "The name of your organization.").StringVar(&cmd.org)
52+
clause.Flag("org-description", "A description (max 144 chars) for your organization so others will recognize it.").StringVar(&cmd.orgDescription)
4953
registerForceFlag(clause).BoolVar(&cmd.force)
5054

5155
command.BindAction(clause, cmd.Run)
@@ -103,11 +107,12 @@ func (cmd *SignUpCommand) Run() error {
103107
}
104108
}
105109
if cmd.email == "" {
106-
cmd.email, err = ui.AskAndValidate(cmd.io, "Your email address: ", 2, api.ValidateEmail)
110+
cmd.email, err = ui.AskAndValidate(cmd.io, "Your (work) email address: ", 2, api.ValidateEmail)
107111
if err != nil {
108112
return err
109113
}
110114
}
115+
fmt.Fprintln(cmd.io.Stdout())
111116
}
112117
}
113118

@@ -181,7 +186,43 @@ func (cmd *SignUpCommand) Run() error {
181186
}
182187

183188
cmd.progressPrinter.Stop()
189+
fmt.Fprint(cmd.io.Stdout(), "Created your account.\n\n")
184190

191+
createWorkspace := cmd.org != ""
192+
if !createWorkspace {
193+
createWorkspace, err = ui.AskYesNo(cmd.io, "Do you want to create a shared workspace for your team?", ui.DefaultYes)
194+
if err != nil {
195+
return err
196+
}
197+
fmt.Fprintln(cmd.io.Stdout())
198+
if !createWorkspace {
199+
fmt.Fprint(cmd.io.Stdout(), "You can create a shared workspace later using `secrethub org init`.\n\n")
200+
}
201+
}
202+
if createWorkspace {
203+
if cmd.org == "" {
204+
cmd.org, err = ui.AskAndValidate(cmd.io, "Workspace name (e.g. your company name): ", 2, api.ValidateOrgName)
205+
if err != nil {
206+
return err
207+
}
208+
}
209+
if cmd.orgDescription == "" {
210+
cmd.orgDescription, err = ui.AskAndValidate(cmd.io, "A description (max 144 chars) for your team workspace so others will recognize it:\n", 2, api.ValidateOrgDescription)
211+
if err != nil {
212+
return err
213+
}
214+
}
215+
216+
_, err := client.Orgs().Create(cmd.org, cmd.orgDescription)
217+
if err == api.ErrOrgAlreadyExists {
218+
fmt.Fprintf(cmd.io.Stdout(), "The workspace %s already exists. If it is your organization, ask a colleague to invite you to the workspace. You can also create a new one using `secrethub org init`.\n", cmd.org)
219+
} else if err != nil {
220+
return err
221+
} else {
222+
fmt.Fprintln(cmd.io.Stdout(), "\nCreated your shared workspace.")
223+
}
224+
}
185225
fmt.Fprintf(cmd.io.Stdout(), "Setup complete. To read your first secret, run:\n\n secrethub read %s\n\n", secretPath)
226+
186227
return nil
187228
}

0 commit comments

Comments
 (0)