Skip to content

Conversation

@echonesis
Copy link
Contributor

@echonesis echonesis commented Dec 27, 2025

What changes were proposed in this pull request?

Enhanced the ozone sh bucket|key|volume getacl command to support a --json flag.
The command now outputs JSON format by default (consistent with other Ozone CLI commands).
Users can use --json=false to get a comma-separated string format compatible with setacl/addacl commands.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-5306

How was this patch tested?

GitHub Actions CI: https://github.com/echonesis/ozone/actions/runs/20594091686
Local Test:

> docker compose exec om ozone sh bucket getacl s3v/bucket1
[ {
  "type" : "USER",
  "name" : "testuser",
  "aclScope" : "ACCESS",
  "aclSet" : [ "ALL" ],
  "aclList" : [ "ALL" ]
}, {
  "type" : "GROUP",
  "name" : "testuser",
  "aclScope" : "ACCESS",
  "aclSet" : [ "READ", "LIST" ],
  "aclList" : [ "READ", "LIST" ]
} ]

> docker compose exec om ozone sh bucket getacl --json s3v/bucket1
[ {
  "type" : "USER",
  "name" : "testuser",
  "aclScope" : "ACCESS",
  "aclList" : [ "ALL" ],
  "aclSet" : [ "ALL" ]
}, {
  "type" : "GROUP",
  "name" : "testuser",
  "aclScope" : "ACCESS",
  "aclList" : [ "READ", "LIST" ],
  "aclSet" : [ "READ", "LIST" ]
} ]

> docker compose exec om ozone sh bucket getacl --json=false s3v/bucket1
user:testuser:a,group:testuser:rl

@adoroszlai adoroszlai changed the title HDDS-5306. Ozone Shell getacl capable of printing ACL string the way it is fed to setacl HDDS-5306. Add ozone sh * getacl option to match setacl input format Dec 27, 2025
*/
public abstract class GetAclHandler extends AclHandler {

@Option(names = {"--string", "-o"},
Copy link
Contributor

@ChenSammi ChenSammi Dec 29, 2025

Choose a reason for hiding this comment

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

Thanks @echonesis for working on this task.

I would suggest add an following Option instead of this one,

  @CommandLine.Option(names = {"--json"},
      description = "Format output as JSON",
      defaultValue = "true")
  private boolean json;

The rest looks good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review!
I've been considering the --json approach with the following concerns:

  1. Clearer user intent: The --string flag explicitly opts into the string format, while --json with defaultValue="true" creates confusion (why have a flag for the default behavior?).
  2. Backward compatibility: The current implementation maintains the existing default JSON output without any flags, which is less disruptive to existing users.
  3. Future extensibility: If we need additional formats (e.g., --xml or --yaml), having explicit format flags is cleaner than having --json=false alongside other format flags.

What do you think? I'm open to your perspective on this!

Copy link
Contributor

@ChenSammi ChenSammi Dec 30, 2025

Choose a reason for hiding this comment

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

It's very good to thought that there are possible other formats to support in future. But the current Ozone CLI state is either json or plain output without structured format, so --json is used in many CLIs. To have a consistent CLI option format, --json is preferred. There is possibility to support xml or yaml in future, but we don't see such requirements so far. If it becomes true, then a lot of existing CLIs need to improved in batches.

why have a flag for the default behavior?

If there is --json in the command line, then it's true, otherwise it's false. So default "true" might not be feasible, "false" is more appropriate.

"--string", "-o"

"--string" is kind of vague, user cannot get the clear idea about what this option means without looking into description, and "-o" usually means "--output-file". A self explained option name is more preferred.

Copy link
Contributor

@ChenSammi ChenSammi Dec 30, 2025

Choose a reason for hiding this comment

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

I guess(didn't test it) defaultValue = "true" will cause problem, there could be no way to get a false state, could you test it if defaultValue = "true" works? The reason why defaultValue = "true" is recommended at first place is to keep the backward compatibility, but if it's not feasible, I think defaultValue = "false" is acceptable, though it will change the current output behavior, but just format, not content.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the Option settings, and it works for backward compatibility.

  • default: JSON
  • with --json: JSON
  • with --json=false: String

We could use the syntax:

@Option(names = {"--json"},
    description = "Format output as JSON",
    defaultValue = "true",
    fallbackValue = "true")
private boolean json;

@echonesis echonesis requested a review from ChenSammi December 29, 2025 08:01
public abstract class GetAclHandler extends AclHandler {

@Option(names = {"--json"},
description = "Format output as JSON",
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add more explanation in description.

Format output as JSON. Default is true. Use --json=false to turn off output JSON format.

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.

2 participants