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

Create a <File> component #26

Closed
fmvilas opened this issue Nov 24, 2020 · 8 comments
Closed

Create a <File> component #26

fmvilas opened this issue Nov 24, 2020 · 8 comments
Assignees

Comments

@fmvilas
Copy link
Member

fmvilas commented Nov 24, 2020

The template author should be able to use a component representing the current file being rendered. We can call this component <File>. It should take —at least— the following props:

  • name: It represents the name of the file in the output.
  • permissions: It represents the permissions of the file in the output.

Hints

  • Consider using a standard way of defining file permissions, like the Unix one. Make sure it's applicable to all the major operating systems.
  • Consider starting the docs, tests, and code of this component before any other tasks are finished, to increase work parallelization.
@jonaslagoni jonaslagoni self-assigned this Nov 24, 2020
@jonaslagoni
Copy link
Member

Some questions regarding the props:

  • how does the name prop expect to work together with the file name template $$schema$$ from the generator?
  • Also if no name is provided I would assume the actual file name of the template is what is being used as name for the rendered file?
  • Are the permissions prop really relevant? What's the use-case for actually stating them from a templater's POV?

@fmvilas
Copy link
Member Author

fmvilas commented Nov 25, 2020

how does the name prop expect to work together with the file name template $$schema$$ from the generator?

I'd expect the prop name to replace the $$schema$$ functionality.

Also if no name is provided I would assume the actual file name of the template is what is being used as name for the rendered file?

Yes. Defaults to current behavior where it might get the name from the file or from the $$schema$$ syntax.

Are the permissions prop really relevant? What's the use-case for actually stating them from a templater's POV?

Some files need to be executable (scripts, for instance). Skip this part for now if you feel it's gonna take a lot of time.

@jonaslagoni
Copy link
Member

Are the permissions prop really relevant? What's the use-case for actually stating them from a templater's POV?

Some files need to be executable (scripts, for instance). Skip this part for now if you feel it's gonna take a lot of time.

Its not that, I feel this is a security risk, I see what you mean, however if script files are generated I expect myself as a user to have to give the file access to run. A malicious template owner might add a script file hidden somewhere, which are executing once the user tries to use the "normal" library. The user would have no idea that is it happening since we already gave the file execution permissions.

I know that at the moment hooks can easily be used to implement the same functionality, but I can imagine that would change as well in some way 🤷 In my mind these form for code generators are super awesome but also the perfect opportunity for malicious actors to inject anything into a persons computer.

But I can also see the usefulness in having this prop.

@fmvilas
Copy link
Member Author

fmvilas commented Nov 25, 2020

It's already a problem without hooks too. For instance, right now (without React) if the template file is executable, it will be copied as executable too if it's marked as nonRenderableFile (see this).

It's a valid concern but it's also true it has nothing to do with the task at hand so I'd not worry about it now. Feel free to create an issue on the Generator to raise your concern.

@jonaslagoni
Copy link
Member

It's already a problem without hooks too. For instance, right now (without React) if the template file is executable, it will be copied as executable too if it's marked as nonRenderableFile (see this).

This is not true, the files are never copied with execution permissions even if they did since you install the template (before generating the files) all files are given -rw-rw--r-- and once generated they receive -rw-r--r--. This is regardless of whether nonRenderableFile are sat or not. So even if the user manually changes the templates file permissions before generating the files it it still does not preserve the permissions 🙂

@jonaslagoni
Copy link
Member

Down to the actual permission configuration would one rather define it as 0o777 or "777"?

0o is to describe the number as octal.

@fmvilas
Copy link
Member Author

fmvilas commented Nov 27, 2020

This is not true, the files are never copied with execution permissions

Seems to be an OS issue? nodejs/node#26936. It's respecting permissions for me on Mac OS X.

Down to the actual permission configuration would one rather define it as 0o777 or "777"?

What about an JS object like:

{
  executable: true,
  user: {
    read: true,
    write: true,
  },
  group: {
    read: true,
    write: true,
  }
}

And depending on the OS it will convert it down to the corresponding code.

@magicmatatjahu
Copy link
Member

Done by asyncapi/generator-react-sdk@c884869 commit

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

No branches or pull requests

3 participants