Skip to content

fsnode: add JSON/YAML support for File/Directory - #1500

Closed
mvo5 wants to merge 2 commits into
osbuild:mainfrom
mvo5:custom-unmarshalers-2-alternative2
Closed

mvo5 wants to merge 2 commits into
osbuild:mainfrom
mvo5:custom-unmarshalers-2-alternative2

Conversation

@mvo5

@mvo5 mvo5 commented May 6, 2025

Copy link
Copy Markdown
Contributor

Another alternative version of #1479 - I think I like this one best so far


When we move ImageConfig into YAML we will need support for
fsnode.File as it is used as part of the ImageConfig.

This commit adds support for JSON/YAML unmarshaling.


fsnode: use path/filepath instead of path

When validating paths in the fsnode module, use the filepath
module instead of the (more generic) path.

When validating paths in the fsnode module, use the `filepath`
module instead of the (more generic) `path`.
@mvo5
mvo5 requested review from achilleas-k and lzap May 6, 2025 18:05
@mvo5
mvo5 requested a review from a team as a code owner May 6, 2025 18:05
@mvo5
mvo5 requested review from schuellerf and supakeen May 6, 2025 18:05
const usernameRegex = `^[A-Za-z0-9_.][A-Za-z0-9_.-]{0,31}$`
const groupnameRegex = `^[A-Za-z0-9_][A-Za-z0-9_-]{0,31}$`

type baseFsNodeJSON struct {

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.

We could also call this baseFsNodeData might be a bit clearer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This was exactly my idea when I read your concern about exposing fields.

Lesson learned, for the new blueprint I want to avoid getters/setters, so I think the new blueprint struct must be immutable. There might be some unmarshal hooks, but once everything is loaded up no changes should be allowed, no getters or anything. I really hope we can achieve this, then all fields can be exported. Well except unions which are not exported and one has to use AsXXX "getter" but that is the only way how to use it.

@mvo5
mvo5 force-pushed the custom-unmarshalers-2-alternative2 branch from a7e9214 to 35661ad Compare May 6, 2025 18:15
When we move `ImageConfig` into YAML we will need support for
`fsnode.{Dir,File}` as it is used as part of the ImageConfig.

This commit adds support for JSON/YAML unmarshaling.

@lzap lzap left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is miles cleaner than the reflection magic you were proposing initially.

@mvo5

mvo5 commented May 9, 2025

Copy link
Copy Markdown
Contributor Author

Closing in favor of #1508

@mvo5 mvo5 closed this May 9, 2025
auto-merge was automatically disabled May 9, 2025 09:31

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants