Skip to content

ENT-13089: Added validation of module names#247

Merged
olehermanse merged 3 commits into
cfengine:masterfrom
jakub-nt:ENT-13089
Jul 4, 2025
Merged

ENT-13089: Added validation of module names#247
olehermanse merged 3 commits into
cfengine:masterfrom
jakub-nt:ENT-13089

Conversation

@jakub-nt

@jakub-nt jakub-nt commented Jul 4, 2025

Copy link
Copy Markdown
Contributor

No description provided.

jakub-nt added 3 commits July 4, 2025 15:01
Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
@jakub-nt jakub-nt requested a review from olehermanse July 4, 2025 13:28

@olehermanse olehermanse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice. Only small comments, feel free to fix in a follow-up PR.

Comment thread JSON.md
For the `build` array, it must be inside each module object (with `name` as the key).
Local modules (files and folders in same directory as `cfbs.json`), must start with `./`, and end with `/` if it's a directory.
Module names should not be longer than 64 characters.
Module names (not including adfixes `./`, `/`, `.cf`, `.json` for local modules) should only contain lowercase ASCII alphanumeric characters possibly separated by dashes, and should start with a letter.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Module names (not including adfixes `./`, `/`, `.cf`, `.json` for local modules) should only contain lowercase ASCII alphanumeric characters possibly separated by dashes, and should start with a letter.
Module names (not including affixes `./`, `/`, `.cf`, `.json` for local modules) should only contain lowercase ASCII alphanumeric characters possibly separated by dashes, and should start with a letter.

Comment thread cfbs/utils.py
Comment thread cfbs/utils.py
Comment thread cfbs/validate.py
Comment on lines +189 to +190
if not name.startswith("./"):
raise CFBSValidationError(name, "Local module names should begin with `./`")

@olehermanse olehermanse Jul 4, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is ensured by is_module_local(), so should be an assert / programmer error if that's not the case:

Suggested change
if not name.startswith("./"):
raise CFBSValidationError(name, "Local module names should begin with `./`")
assert name.startswith("./"), "is_module_local() should ensure this module starts with ./"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, but I thought this is safer since the implementation could change in the future.

Comment thread cfbs/validate.py
@olehermanse olehermanse merged commit 61b4338 into cfengine:master Jul 4, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants