Skip to content

Commit

Permalink
Add password reset features (#346)
Browse files Browse the repository at this point in the history
* Add `--reset-password` flag to `add user` command

* Add `reset-password` command

* Add docs for password resets

* Update artifacts from running `make docs`
  • Loading branch information
rocketeerbkw authored May 1, 2024
1 parent 6662fa5 commit bddff17
Show file tree
Hide file tree
Showing 14 changed files with 207 additions and 122 deletions.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ Use "{{.CommandPath}} [command] --help" for more information about a command.{{e
rootCmd.AddCommand(whoamiCmd)
rootCmd.AddCommand(uploadCmd)
rootCmd.AddCommand(rawCmd)
rootCmd.AddCommand(resetPasswordCmd)
}

// version/build information command
Expand Down
1 change: 1 addition & 0 deletions cmd/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var lagoonSSHKey string
var userFirstName string
var userLastName string
var userEmail string
var resetPassword bool
var pubKeyFile string
var sshKeyName string

Expand Down
30 changes: 27 additions & 3 deletions cmd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ var addUserCmd = &cobra.Command{
Aliases: []string{"u"},
Short: "Add a user to lagoon",
Run: func(cmd *cobra.Command, args []string) {
userFlags := parseUser(*cmd.Flags())
if userFlags.Email == "" {
user := parseUser(*cmd.Flags())
if user.Email == "" {
fmt.Println("Missing arguments: Email address is not defined")
cmd.Help()
os.Exit(1)
}
var customReqResult []byte
var err error
customReqResult, err = uClient.AddUser(userFlags)
customReqResult, err = uClient.AddUser(user, resetPassword)
handleError(err)
returnResultData := map[string]interface{}{}
err = json.Unmarshal([]byte(customReqResult), &returnResultData)
Expand Down Expand Up @@ -496,6 +496,28 @@ var RemoveUserFromOrganization = &cobra.Command{
},
}

var resetPasswordCmd = &cobra.Command{
Use: "reset-password",
Aliases: []string{"reset-pass", "rp"},
Short: "Send a password reset email",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
validateToken(lagoonCLIConfig.Current) // get a new token if the current one is invalid
},
Run: func(cmd *cobra.Command, args []string) {
if userEmail == "" {
fmt.Println("Missing arguments: Email address is not defined")
cmd.Help()
os.Exit(1)
}

if yesNo(fmt.Sprintf("You are attempting to send a password reset email to '%s', are you sure?", userEmail)) {
result, err := uClient.ResetPassword(userEmail)
handleError(err)
fmt.Println(string(result))
}
},
}

var (
currentUserEmail string
pubKeyValue string
Expand All @@ -505,6 +527,7 @@ func init() {
addUserCmd.Flags().StringVarP(&userFirstName, "firstName", "F", "", "First name of the user")
addUserCmd.Flags().StringVarP(&userLastName, "lastName", "L", "", "Last name of the user")
addUserCmd.Flags().StringVarP(&userEmail, "email", "E", "", "Email address of the user")
addUserCmd.Flags().BoolVarP(&resetPassword, "reset-password", "", false, "Send a password reset email")
addUserSSHKeyCmd.Flags().StringVarP(&userEmail, "email", "E", "", "Email address of the user")
addUserSSHKeyCmd.Flags().StringVarP(&sshKeyName, "keyname", "N", "", "Name of the SSH key (optional, if not provided will try use what is in the pubkey file)")
addUserSSHKeyCmd.Flags().StringVarP(&pubKeyFile, "pubkey", "K", "", "Specify path to the public key to add")
Expand All @@ -523,4 +546,5 @@ func init() {
RemoveUserFromOrganization.Flags().StringP("name", "O", "", "Name of the organization")
RemoveUserFromOrganization.Flags().StringP("email", "E", "", "Email address of the user")
RemoveUserFromOrganization.Flags().Bool("owner", false, "Set the user as an owner of the organization")
resetPasswordCmd.Flags().StringVarP(&userEmail, "email", "E", "", "Email address of the user")
}
1 change: 1 addition & 0 deletions docs/commands/lagoon.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ lagoon [flags]
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications
* [lagoon login](lagoon_login.md) - Log into a Lagoon instance
* [lagoon raw](lagoon_raw.md) - Run a custom query or mutation
* [lagoon reset-password](lagoon_reset-password.md) - Send a password reset email
* [lagoon retrieve](lagoon_retrieve.md) - Trigger a retrieval operation on backups
* [lagoon run](lagoon_run.md) - Run a task against an environment
* [lagoon ssh](lagoon_ssh.md) - Display the SSH command to access a specific environment in a project
Expand Down
1 change: 1 addition & 0 deletions docs/commands/lagoon_add_user.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ lagoon add user [flags]
-F, --firstName string First name of the user
-h, --help help for user
-L, --lastName string Last name of the user
--reset-password Send a password reset email
```

### Options inherited from parent commands
Expand Down
10 changes: 5 additions & 5 deletions docs/commands/lagoon_deploy_branch.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ lagoon deploy branch [flags]
### Options

```
-b, --branch string Branch name to deploy
-r, --branchRef string Branch ref to deploy
--buildvar strings Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2])
-h, --help help for branch
--returnData Returns the build name instead of success text
-b, --branch string Branch name to deploy
-r, --branchRef string Branch ref to deploy
--buildvar stringArray Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2])
-h, --help help for branch
--returnData Returns the build name instead of success text
```

### Options inherited from parent commands
Expand Down
6 changes: 3 additions & 3 deletions docs/commands/lagoon_deploy_latest.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ lagoon deploy latest [flags]
### Options

```
--buildvar strings Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2])
-h, --help help for latest
--returnData Returns the build name instead of success text
--buildvar stringArray Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2])
-h, --help help for latest
--returnData Returns the build name instead of success text
```

### Options inherited from parent commands
Expand Down
10 changes: 5 additions & 5 deletions docs/commands/lagoon_deploy_promote.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ lagoon deploy promote [flags]
### Options

```
--buildvar strings Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2])
-d, --destination string Destination environment name to create
-h, --help help for promote
--returnData Returns the build name instead of success text
-s, --source string Source environment name to use as the base to deploy from
--buildvar stringArray Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2])
-d, --destination string Destination environment name to create
-h, --help help for promote
--returnData Returns the build name instead of success text
-s, --source string Source environment name to use as the base to deploy from
```

### Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/lagoon_deploy_pullrequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ lagoon deploy pullrequest [flags]
```
-N, --baseBranchName string Pullrequest base branch name
-R, --baseBranchRef string Pullrequest base branch reference hash
--buildvar strings Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2])
--buildvar stringArray Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2])
-H, --headBranchName string Pullrequest head branch name
-M, --headBranchRef string Pullrequest head branch reference hash
-h, --help help for pullrequest
Expand Down
36 changes: 36 additions & 0 deletions docs/commands/lagoon_reset-password.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## lagoon reset-password

Send a password reset email

```
lagoon reset-password [flags]
```

### Options

```
-E, --email string Email address of the user
-h, --help help for reset-password
```

### Options inherited from parent commands

```
--config-file string Path to the config file to use (must be *.yml or *.yaml)
--debug Enable debugging output (if supported)
-e, --environment string Specify an environment to use
--force Force yes on prompts (if supported)
-l, --lagoon string The Lagoon instance to interact with
--no-header No header on table (if supported)
--output-csv Output as CSV (if supported)
--output-json Output as JSON (if supported)
--pretty Make JSON pretty (if supported)
-p, --project string Specify a project to use
--skip-update-check Skip checking for updates
-i, --ssh-key string Specify path to a specific SSH key to use for lagoon authentication
```

### SEE ALSO

* [lagoon](lagoon.md) - Command line integration for Lagoon

Loading

0 comments on commit bddff17

Please sign in to comment.