Skip to content

Conversation

@piotr-andruszkiewicz-wttech
Copy link
Contributor

@piotr-andruszkiewicz-wttech piotr-andruszkiewicz-wttech commented May 26, 2025

$ ./bin/aem auth user --help
User management

Usage:
  aem auth user [command]

Aliases:
  user, usr

Available Commands:
  key         Private keys management
  keystore    Keystore management
  password    Password management

Flags:
  -h, --help   help for user

$ ./bin/aem auth user key --help
Private keys management

Usage:
  aem auth user key [command]

Aliases:
  key, keys

Available Commands:
  add         Add user's private key to their keystore
  delete      Delete user's private key from their keystore

Flags:
  -h, --help   help for key
  
$ ./bin/aem auth user key add --help
Add user's private key to their keystore

Usage:
  aem auth user key add [flags]

Aliases:
  add, create, new

Flags:
  -h, --help                       help for add
      --id string                  user id
      --key-alias string           key alias
      --key-password string        key password
      --keystore-file string       path to keystore file
      --keystore-password string   keystore password
      --new-alias string           new key alias (optional)
      --scope string               user scope

$ ./bin/aem auth user key rm --help
Delete user's private key from their keystore

Usage:
  aem auth user key delete [flags]

Aliases:
  delete, remove, rm

Flags:
  -h, --help               help for delete
      --id string          user id
      --key-alias string   key alias
      --scope string       user scope

$ ./bin/aem auth user key add --scope we-retail --id DSCP-athB1NYLBXvdTuN -A  --key-alias test-alias --keystore-file ~/Downloads/test.keystore --keystore-password abcd
INFO[2025-05-27 11:21:34] User key added             

$ ./bin/aem auth user key add --scope we-retail --id DSCP-athB1NYLBXvdTuN -A  --key-alias test-alias --keystore-file ~/Downloads/test.keystore --keystore-password abcd
INFO[2025-05-27 11:21:36] User key already exists    

$ ./bin/aem auth user key rm --scope we-retail --id DSCP-athB1NYLBXvdTuN -A --key-alias test-alias
INFO[2025-05-27 11:21:46] User key deleted           

$ ./bin/aem auth user key rm --scope we-retail --id DSCP-athB1NYLBXvdTuN -A --key-alias test-alias
INFO[2025-05-27 11:21:47] User key does not exist    

cmd/aem/user.go Outdated
func (c *CLI) KeystoreKeyAdd() *cobra.Command {
cmd := &cobra.Command{
Use: "add",
Short: "Create user Keystore key",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"masło maślane" a bit :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not mix upper case with lowercase; make it looking elegant / consistent

cmd/aem/user.go Outdated
return
}

changed, err := instance.Auth().UserManager().DeleteKeystoreKey(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commands are scoped so keystore keys should be also scoped

UserManager().Keystore().DeleteKey() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

return UsersPath + "/" + scope + "/" + id
}

func readKeyStore(filename string, password []byte) (*jks.KeyStore, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we reading this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because what we get from AEM when something is wrong with the keystore is a 500 response with HTML document. I wanted to check the keystore locally so we get more info rather than parsing the response.

}

if status == nil || !status.Created {
return false, fmt.Errorf("%s > cannot add keystore key: keystore does not exist", um.instance.IDColor())
Copy link
Contributor

@krystian-panek-vmltech krystian-panek-vmltech May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot add keystore key as keystore does not exist ? ( i mean merge msg)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

"keyStore": keystoreFilePath,
}

keystorePath := assembleUserPath(scope, id) + ".ks.html"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

composeUserPath

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stubborn 😉

cmd/aem/user.go Outdated
cmd := &cobra.Command{
Use: "status",
Short: "Get status of keystore",
Short: "Get status of a user's keystore",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just user keystore ? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

cmd/aem/user.go Outdated
func (c *CLI) userKeyAdd() *cobra.Command {
cmd := &cobra.Command{
Use: "add",
Short: "Add user's private key to their keystore",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just user private key

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keystore/{keystore_status => status}.go

}

func (km *KeystoreManager) Status(scope, id string) (*keystore.Status, error) {
userKeystorePath := composeUserPath(scope, id) + ".ks.json"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are appending ".ks.json" here and on line 52 as well ; extract same func or sth

@piotr-andruszkiewicz-wttech piotr-andruszkiewicz-wttech merged commit 9fc43a1 into main May 27, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants