Skip to content

Commit 8e97375

Browse files
author
Piotr Andruszkiewicz
committed
Refactor user password management: update command descriptions and streamline path generation
1 parent 0684047 commit 8e97375

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

cmd/aem/user.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ func (c *CLI) KeystoreCreate() *cobra.Command {
105105
cmd.Flags().String("id", "", "user id")
106106
_ = cmd.MarkFlagRequired("id")
107107
cmd.Flags().String("scope", "", "user scope")
108-
_ = cmd.MarkFlagRequired("scope")
109108
cmd.Flags().String("keystore-password", "", "keystore password")
110109
_ = cmd.MarkFlagRequired("keystore-password")
111110
return cmd
@@ -114,7 +113,7 @@ func (c *CLI) KeystoreCreate() *cobra.Command {
114113
func (c *CLI) UserPasswordSet() *cobra.Command {
115114
cmd := &cobra.Command{
116115
Use: "set",
117-
Short: "Set user password",
116+
Short: "Set user password. Password is read from input.",
118117
Aliases: []string{"update", "change"},
119118
Run: func(cmd *cobra.Command, args []string) {
120119
instances, err := c.aem.InstanceManager().One()
@@ -132,7 +131,7 @@ func (c *CLI) UserPasswordSet() *cobra.Command {
132131
return
133132
}
134133

135-
changed, err := instances.Auth().UserManager().PasswordSet(scope, id, password)
134+
changed, err := instances.Auth().UserManager().SetPassword(scope, id, password)
136135
if err != nil {
137136
c.Error(err)
138137
return
@@ -149,7 +148,6 @@ func (c *CLI) UserPasswordSet() *cobra.Command {
149148
cmd.Flags().String("id", "", "user id")
150149
_ = cmd.MarkFlagRequired("id")
151150
cmd.Flags().String("scope", "", "user scope")
152-
_ = cmd.MarkFlagRequired("scope")
153151

154152
return cmd
155153
}

pkg/user_manager.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const (
2020
)
2121

2222
func (um *UserManager) KeystoreStatus(scope, id string) (*keystore.Status, error) {
23-
userKeystorePath := UsersPath + "/" + scope + "/" + id + ".ks.json"
23+
userKeystorePath := generateUserPath(scope, id) + ".ks.json"
2424

2525
response, err := um.instance.http.Request().Get(userKeystorePath)
2626

@@ -48,7 +48,7 @@ func (um *UserManager) KeystoreCreate(scope, id, keystorePassword string) (bool,
4848
return false, statusError
4949
}
5050

51-
if statusResponse.Created == true {
51+
if statusResponse.Created {
5252
return false, nil
5353
}
5454

@@ -58,7 +58,7 @@ func (um *UserManager) KeystoreCreate(scope, id, keystorePassword string) (bool,
5858
":operation": "createStore",
5959
}
6060

61-
userKeystoreCreatePath := UsersPath + "/" + scope + "/" + id + ".ks.html"
61+
userKeystoreCreatePath := generateUserPath(scope, id) + ".ks.html"
6262
postResponse, postError := um.instance.http.Request().SetQueryParams(pathParams).Post(userKeystoreCreatePath)
6363

6464
if postError != nil {
@@ -73,7 +73,7 @@ func (um *UserManager) KeystoreCreate(scope, id, keystorePassword string) (bool,
7373
}
7474

7575
func (um *UserManager) ReadState(scope string, id string) (*user.Status, error) {
76-
userPath := UsersPath + "/" + scope + "/" + id
76+
userPath := generateUserPath(scope, id)
7777

7878
response, err := um.instance.http.Request().Get(userPath + ".json")
7979

@@ -93,14 +93,14 @@ func (um *UserManager) ReadState(scope string, id string) (*user.Status, error)
9393
return result, nil
9494
}
9595

96-
func (um *UserManager) PasswordSet(scope string, id string, password string) (bool, error) {
96+
func (um *UserManager) SetPassword(scope string, id string, password string) (bool, error) {
9797
userStatus, err := um.ReadState(scope, id)
9898

9999
if err != nil {
100100
return false, err
101101
}
102102

103-
userPath := UsersPath + "/" + scope + "/" + id
103+
userPath := generateUserPath(scope, id)
104104

105105
passwordCheckResponse, err := um.instance.http.Request().
106106
SetBasicAuth(userStatus.AuthorizableID, password).
@@ -128,3 +128,10 @@ func (um *UserManager) PasswordSet(scope string, id string, password string) (bo
128128

129129
return true, nil
130130
}
131+
132+
func generateUserPath(scope string, id string) string {
133+
if scope == "" {
134+
return UsersPath + "/" + id
135+
}
136+
return UsersPath + "/" + scope + "/" + id
137+
}

0 commit comments

Comments
 (0)