MCPcopy
hub / github.com/kopia/kopia / runServerUserAddSet

Method runServerUserAddSet

cli/command_user_add_set.go:56–109  ·  view source on GitHub ↗
(ctx context.Context, rep repo.RepositoryWriter)

Source from the content-addressed store, hash-verified

54}
55
56func (c *commandServerUserAddSet) runServerUserAddSet(ctx context.Context, rep repo.RepositoryWriter) error {
57 username := c.userSetName
58
59 up, err := c.getExistingOrNewUserProfile(ctx, rep, username)
60 if err != nil {
61 return err
62 }
63
64 changed := false
65
66 if p := c.userSetPassword; p != "" {
67 changed = true
68
69 if err := up.SetPassword(p); err != nil {
70 return errors.Wrap(err, "error setting password")
71 }
72 }
73
74 if ph := c.userSetPasswordHash; ph != "" {
75 if err := up.SetPasswordHash(ph); err != nil {
76 return errors.Wrap(err, "error setting password hash")
77 }
78
79 changed = true
80 }
81
82 if up.PasswordHash == nil || c.userAskPassword {
83 pwd, err := askConfirmPass(c.out.stdout(), "Enter new password for user "+username+": ")
84 if err != nil {
85 return err
86 }
87
88 changed = true
89
90 if err := up.SetPassword(pwd); err != nil {
91 return errors.Wrap(err, "error setting password")
92 }
93 }
94
95 if !changed && !c.isNew {
96 return errors.New("no change")
97 }
98
99 if err := user.SetUserProfile(ctx, rep, up); err != nil {
100 return errors.Wrap(err, "error setting user profile")
101 }
102
103 log(ctx).Infof(`
104Updated user credentials will take effect in 5-10 minutes or when the server is restarted.
105To refresh credentials in a running server use 'kopia server refresh' command.
106`)
107
108 return nil
109}
110
111var errPasswordsDoNotMatch = errors.New("passwords do not match")
112

Callers

nothing calls this directly

Calls 6

SetUserProfileFunction · 0.92
askConfirmPassFunction · 0.85
SetPasswordMethod · 0.80
SetPasswordHashMethod · 0.80
stdoutMethod · 0.65

Tested by

no test coverage detected