Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ACL JSON list output option #102

Merged
merged 1 commit into from
Jan 10, 2024
Merged
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
14 changes: 14 additions & 0 deletions client/getacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var cmdGetACL = &Command{
Long: `
Acl get the ACL for a key.

-json: Returns the ACL as a JSON formatted list of access rules, useful for generating files to be used with knox access -acl.

This doesn't require any access to the key and allows, e.g., to see who has admin access to ask for grants.

For more about knox, see https://github.com/pinterest/knox.
Expand All @@ -23,6 +25,8 @@ See also: knox keys, knox get
`,
}

var getACLJSON = cmdGetACL.Flag.Bool("json", false, "")

func runGetACL(cmd *Command, args []string) *ErrorStatus {
if len(args) != 1 {
return &ErrorStatus{fmt.Errorf("acl takes only one argument. See 'knox help acl'"), false}
Expand All @@ -34,6 +38,16 @@ func runGetACL(cmd *Command, args []string) *ErrorStatus {
return &ErrorStatus{fmt.Errorf("Error getting key ACL: %s", err.Error()), true}
}

if *getACLJSON {
aclEnc, err := json.Marshal(acl)
if err != nil {
// malformated ACL considered as knox server side error
return &ErrorStatus{fmt.Errorf("Could not marshal ACL: %v", acl), true}
}
fmt.Println(string(aclEnc))
return nil
}

for _, a := range *acl {
aEnc, err := json.Marshal(a)
if err != nil {
Expand Down
Loading