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

Commit b24de2d

Browse files
Merge pull request #368 from secrethub/feature/drop-signup
Drop signup command in favor of web-signup
2 parents 6fbe236 + e88a3e6 commit b24de2d

4 files changed

Lines changed: 95 additions & 286 deletions

File tree

internals/secrethub/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func (app *App) registerCommands() {
176176

177177
// Commands
178178
NewInitCommand(app.io, app.clientFactory.NewUnauthenticatedClient, app.clientFactory.NewClientWithCredentials, app.credentialStore).Register(app.cli)
179-
NewSignUpCommand(app.io, app.clientFactory.NewUnauthenticatedClient, app.credentialStore).Register(app.cli)
179+
NewSignUpCommand(app.io).Register(app.cli)
180180
NewWriteCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
181181
NewReadCommand(app.io, app.clientFactory.NewClient).Register(app.cli)
182182
NewGenerateSecretCommand(app.io, app.clientFactory.NewClient).Register(app.cli)

internals/secrethub/init.go

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ import (
99
"github.com/secrethub/secrethub-cli/internals/cli/progress"
1010
"github.com/secrethub/secrethub-cli/internals/cli/ui"
1111
"github.com/secrethub/secrethub-cli/internals/secrethub/command"
12+
"github.com/secrethub/secrethub-go/internals/api"
1213
"github.com/secrethub/secrethub-go/internals/errio"
1314
"github.com/secrethub/secrethub-go/pkg/secrethub"
15+
"github.com/secrethub/secrethub-go/pkg/secrethub/configdir"
1416
"github.com/secrethub/secrethub-go/pkg/secrethub/credentials"
17+
"github.com/secrethub/secrethub-go/pkg/secretpath"
1518
)
1619

20+
const signupMessage = "Go to https://signup.secrethub.io/ and follow the steps to create an account and get it set up on this machine."
21+
1722
// InitCommand configures the user's SecretHub account for use on this machine.
1823
type InitCommand struct {
1924
backupCode string
@@ -50,8 +55,7 @@ func (cmd *InitCommand) Register(r command.Registerer) {
5055
type InitMode int
5156

5257
const (
53-
InitModeSignup InitMode = iota + 1
54-
InitModeBackupCode
58+
InitModeBackupCode InitMode = iota + 1
5559
InitModeSetupCode
5660
)
5761

@@ -105,23 +109,14 @@ func (cmd *InitCommand) Run() error {
105109

106110
switch option {
107111
case 0:
108-
fmt.Fprintln(cmd.io.Output(), "Go to https://signup.secrethub.io/ and follow the steps to create an account and get it set up on this machine.")
112+
fmt.Fprintln(cmd.io.Output(), signupMessage)
109113
return nil
110114
case 1:
111115
mode = InitModeBackupCode
112116
}
113117
}
114118

115119
switch mode {
116-
case InitModeSignup:
117-
signupCommand := SignUpCommand{
118-
io: cmd.io,
119-
newClient: cmd.newUnauthenticatedClient,
120-
credentialStore: cmd.credentialStore,
121-
progressPrinter: cmd.progressPrinter,
122-
force: cmd.force,
123-
}
124-
return signupCommand.Run()
125120
case InitModeSetupCode:
126121
setupCode := cmd.setupCode
127122

@@ -287,3 +282,86 @@ func promptForDeviceName(io ui.IO) (string, error) {
287282
}
288283
return deviceName, nil
289284
}
285+
286+
// createStartRepo creates a start repository and writes a fist secret to it, so that
287+
// the user can start by reading their first secret. It returns the secret's path.
288+
// This is intended to smoothen onboarding.
289+
func createStartRepo(client secrethub.ClientInterface, username string, fullName string) (string, error) {
290+
repoPath := secretpath.Join(username, "start")
291+
_, err := client.Repos().Create(secretpath.Join(repoPath))
292+
if err != nil {
293+
return "", err
294+
}
295+
296+
secretPath := secretpath.Join(repoPath, "hello")
297+
message := fmt.Sprintf("Welcome %s! This is your first secret. To write a new version of this secret, run:\n\n secrethub write %s", fullName, secretPath)
298+
299+
_, err = client.Secrets().Write(secretPath, []byte(message))
300+
if err != nil {
301+
return "", err
302+
}
303+
return secretPath, nil
304+
}
305+
306+
// createWorkspace creates a new org with the given name and description.
307+
func createWorkspace(client secrethub.ClientInterface, io ui.IO, org string, orgDescription string, progressPrinter progress.Printer) error {
308+
if org == "" {
309+
createWorkspace, err := ui.AskYesNo(io, "Do you want to create a shared workspace for your team?", ui.DefaultYes)
310+
if err != nil {
311+
return err
312+
}
313+
fmt.Fprintln(io.Output())
314+
if !createWorkspace {
315+
fmt.Fprint(io.Output(), "You can create a shared workspace later using `secrethub org init`.\n\n")
316+
return nil
317+
}
318+
}
319+
320+
var err error
321+
if org == "" {
322+
org, err = ui.AskAndValidate(io, "Workspace name (e.g. your company name): ", 2, api.ValidateOrgName)
323+
if err != nil {
324+
return err
325+
}
326+
}
327+
if orgDescription == "" {
328+
orgDescription, err = ui.AskAndValidate(io, "A description (max 144 chars) for your team workspace so others will recognize it:\n", 2, api.ValidateOrgDescription)
329+
if err != nil {
330+
return err
331+
}
332+
}
333+
334+
fmt.Fprint(io.Output(), "Creating your shared workspace...")
335+
progressPrinter.Start()
336+
337+
_, err = client.Orgs().Create(org, orgDescription)
338+
progressPrinter.Stop()
339+
if err == api.ErrOrgAlreadyExists {
340+
fmt.Fprintf(io.Output(), "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", org)
341+
} else if err != nil {
342+
return err
343+
} else {
344+
fmt.Fprint(io.Output(), "Created your shared workspace.\n\n")
345+
}
346+
return nil
347+
}
348+
349+
// writeCredential writes the given credential to the configuration directory.
350+
func writeNewCredential(credential *credentials.KeyCreator, passphrase string, credentialFile *configdir.CredentialFile) error {
351+
exportKey := credential.Key
352+
if passphrase != "" {
353+
exportKey = exportKey.Passphrase(credentials.FromString(passphrase))
354+
}
355+
356+
encodedCredential, err := credential.Export()
357+
if err != nil {
358+
return err
359+
}
360+
361+
return credentialFile.Write(encodedCredential)
362+
}
363+
364+
// askCredentialPassphrase prompts the user for a passphrase to protect the local credential.
365+
func askCredentialPassphrase(io ui.IO) (string, error) {
366+
return ui.AskPassphrase(io, "Please enter a passphrase to protect your local credential (leave empty for no passphrase): ", "Enter the same passphrase again: ", 3)
367+
}

0 commit comments

Comments
 (0)