Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/harbor/root/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ import (

func PasswordCommand() *cobra.Command {
var opts change.PasswordChangeView
var isAdmin bool

cmd := &cobra.Command{
Use: "password",
Short: "Change your password",
Args: cobra.MinimumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
change.ChangePasswordView(&opts)
change.ChangePasswordView(&opts, isAdmin)

err := UpdatePassword(&opts)
if err != nil {
Expand All @@ -41,6 +42,8 @@ func PasswordCommand() *cobra.Command {
},
}

cmd.Flags().BoolVar(&isAdmin, "admin", false, "Admin password change")

return cmd
}

Expand Down
3 changes: 2 additions & 1 deletion doc/cli-docs/harbor-password.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ harbor password [flags]
### Options

```sh
-h, --help help for password
--admin Admin password change
-h, --help help for password
```

### Options inherited from parent commands
Expand Down
4 changes: 4 additions & 0 deletions doc/man-docs/man1/harbor-password.1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Change your password


.SH OPTIONS
\fB--admin\fP[=false]
Admin password change

.PP
\fB-h\fP, \fB--help\fP[=false]
help for password

Expand Down
4 changes: 2 additions & 2 deletions pkg/views/password/change/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type PasswordChangeView struct {
ConfirmPassword string
}

func ChangePasswordView(view *PasswordChangeView) {
func ChangePasswordView(view *PasswordChangeView, isAdmin bool) {
theme := huh.ThemeCharm()

err := huh.NewForm(
Expand All @@ -38,7 +38,7 @@ func ChangePasswordView(view *PasswordChangeView) {
EchoMode(huh.EchoModePassword).
Value(&view.OldPassword).
Validate(func(str string) error {
if strings.TrimSpace(str) == "" {
if !isAdmin && strings.TrimSpace(str) == "" {
return errors.New("old password cannot be empty")
}
return nil
Expand Down
Loading