-
Notifications
You must be signed in to change notification settings - Fork 9
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
Naming convention for "internal" variables and rules #5
Comments
For variables declared inside of rules, there's no reason I can think of to use x := 5
my_rule {
x := 10
print(x) # prints 10
} However, one place where I think this question is highly relevant, and one I know have come up in the past, is whether there should be a way to mark top level variables and rules as "private". This could either be done by naming convention, like you suggest: allow {
_my_helper_rule
}
_my_helper_rule {
# some logic here
} While this would provide a hint to the reader, there's currently nothing to "enforce" this, unless one wants to be creative with e.g. an authz policy that denies requests to any path with a package system.authz
default allow := {"allowed": true}
allow := {"allowed": false, "reason": "access to documents prefixed with '_' not allowed"} {
startswith(input.path[count(input.path) -1], "_")
}
allow := {"allowed": false, "reason": "access to 'data' not allowed"} {
input.path == ["v1", "data"]
} Although you could easily retrieve these by querying for a parent document, so you'd need to expand on the above for a real use case, whether a good idea or not. For the future, we could either consider a keyword to mark rules as private/internal, or extend the metadata annotations to include an attribute that would do this, e.g. # METADATA
# description: helper rule that helps
# visibility: private
my_helper_rule {
# some logic here
} This could be done today already using custom annotations, but if we wanted the server to enforce this, we'd need to work on making that happen. I think this approach is probably the one I'd prefer. |
Also, move the section on future keywords into an "Older Advice" category. Fixes #5 Signed-off-by: Anders Eknert <anders@styra.com>
) Also, move the section on future keywords into an "Older Advice" category. Fixes #5 Signed-off-by: Anders Eknert <anders@styra.com>
I would like to have a dedicated section/paragraph/etc explicitly defining naming convention for "internal" variable names inside functions/rules. i.e. should they be prefixed with _ as I saw in some guides.
e.g. - should we use
_t
ort
for those variablesThe text was updated successfully, but these errors were encountered: