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 methods to validate types, relations, ids and tuples #226

Open
rhamzeh opened this issue Apr 4, 2024 · 0 comments
Open

add methods to validate types, relations, ids and tuples #226

rhamzeh opened this issue Apr 4, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@rhamzeh
Copy link
Member

rhamzeh commented Apr 4, 2024

Let's plan on moving this logic to language and have test cases for them, we can then implement this in several languages consistently

Originally posted by @rhamzeh in openfga/vscode-ext#215 (review)

Current set of regexes used:

Protos:

API:
https://github.com/openfga/openfga/blob/main/pkg/tuple/tuple.go#L35-L38

	userIDRegex   = regexp.MustCompile(`^[^:#\s]+$`)
	objectRegex   = regexp.MustCompile(`^[^:#\s]+:[^#:\s]+$`)
	userSetRegex  = regexp.MustCompile(`^[^:#\s]+:[^#\s]+#[^:#\s]+$`)
	relationRegex = regexp.MustCompile(`^[^:#@\s]+$`)

Validation has to pass both sets of regexes above in order to be valid according to the API.


On the VS Code/Playground side we use a different set of less permissive regexes:
https://github.com/openfga/vscode-ext/blob/07e65ccd3a0d533bcbbb2b4495899d73d2656e3b/server/src/openfga-yaml-schema.ts#L126-L154

We have yet more regexes in language:

// eslint-disable-next-line no-useless-escape
const defaultTypeRule = "^[^:#@\\s]{1,254}$";
// eslint-disable-next-line no-useless-escape
const defaultRelationRule = "^[^:#@\\s]{1,50}$";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants