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 a flag to have zed exit with code 1 on check failure #246

Merged
merged 1 commit into from
Jun 28, 2023
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
15 changes: 14 additions & 1 deletion internal/commands/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io"
"os"
"strings"

"github.com/authzed/authzed-go/pkg/requestmeta"
Expand Down Expand Up @@ -73,6 +74,7 @@ func RegisterPermissionCmd(rootCmd *cobra.Command) *cobra.Command {
_ = checkCmd.Flags().MarkHidden("revision")
checkCmd.Flags().Bool("explain", false, "requests debug information from SpiceDB and prints out a trace of the requests")
checkCmd.Flags().Bool("schema", false, "requests debug information from SpiceDB and prints out the schema used")
checkCmd.Flags().Bool("error-on-no-permission", false, "if true, zed will return exit code 1 if subject does not have unconditional permission")
Copy link
Member

Choose a reason for hiding this comment

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

bike shedding but maybe --exit-1-without-membership? I don't really like either

Can we find prior art for a flag like this in other software?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did a cursory search but couldn't find anything before I came up with this name randomly. I'm fine with whatever

checkCmd.Flags().String("caveat-context", "", "the caveat context to send along with the check, in JSON form")
registerConsistencyFlags(checkCmd.Flags())

Expand Down Expand Up @@ -232,7 +234,18 @@ func checkCmdFunc(cmd *cobra.Command, args []string) error {
return fmt.Errorf("unknown permission response: %v", resp.Permissionship)
}

return displayDebugInformationIfRequested(cmd, trailerMD, false)
err = displayDebugInformationIfRequested(cmd, trailerMD, false)
if err != nil {
return err
}

if cobrautil.MustGetBool(cmd, "error-on-no-permission") {
if resp.Permissionship != v1.CheckPermissionResponse_PERMISSIONSHIP_HAS_PERMISSION {
os.Exit(1)
}
}

return nil
}

func expandCmdFunc(cmd *cobra.Command, args []string) error {
Expand Down