nginxconfig.io icon indicating copy to clipboard operation
nginxconfig.io copied to clipboard

Add a Node.js CLI that interfaces with the generators directly

Open mhkarimi1383 opened this issue 3 years ago • 8 comments

Feature request

Just a simple API giving parameters and return the confirmation

Feature description

For automation reasons I need such API for that reason

How the feature is useful

Using Automation tools like Ansible or making a simple cli

mhkarimi1383 avatar May 12 '22 18:05 mhkarimi1383

I think an API itself would be out-of-scope for this project, as it's a client-side tool built for the browser.

That being said, we do have the config generators themselves exposed in such a way that it'd likely be pretty simple for someone to add a CLI interface to the project that just reads in a large config JSON file (similar to the JSON data stored in the URL when using the in-browser version) and running it through the generators: https://github.com/digitalocean/nginxconfig.io/tree/master/src/nginxconfig/generators

MattIPv4 avatar May 13 '22 12:05 MattIPv4

Me too

MarryJane89 avatar Jun 10 '22 19:06 MarryJane89

@MattIPv4 Maybe a CLI can be work as a NPM package.

  • Install NPM package in global (example: nginxconfig-io)
  • Write a JSON with the config
  • Execute 'nginxconfig-io [Path of the JSON config]'

But I don't sure about some things

  • Where storage the files? In nginx folder Or using another param or the path where execute the CLI?
  • How the files can be generate? In nginx config or bundle in tar file
  • The ifs in the generator using computed value, how can simulate that in Node CLI?

MrJmpl3 avatar Oct 04 '22 14:10 MrJmpl3

Where storage the files?

As in, within the repo? src/nginxconfig/cli feels like the logical location. Assuming the correct bin entry is added to the package.json, it doesn't actually matter where the entrypoint script is.

How the files can be generate?

I would probably expect the CLI to take a directory argument, and the CLI then writes the files directly to there. I like the idea of adding an optional --tar flag though that outputs the single tar file instead.

The ifs in the generator using computed value, how can simulate that in Node CLI?

Some logic will need to be written that takes the provided JSON data and gives each property a new sub-object with the value as the computed property. OR, the opposite could be done where the generators are updated to remove the computed property, and the data from the Vue client is transformed to remove that property before being passed to the generators.

MattIPv4 avatar Oct 04 '22 18:10 MattIPv4

Where storage the files?

As in, within the repo? src/nginxconfig/cli feels like the logical location. Assuming the correct bin entry is added to the package.json, it doesn't actually matter where the entrypoint script is.

How the files can be generate?

I would probably expect the CLI to take a directory argument, and the CLI then writes the files directly to there. I like the idea of adding an optional --tar flag though that outputs the single tar file instead.

The ifs in the generator using computed value, how can simulate that in Node CLI?

Some logic will need to be written that takes the provided JSON data and gives each property a new sub-object with the value as the computed property. OR, the opposite could be done where the generators are updated to remove the computed property, and the data from the Vue client is transformed to remove that property before being passed to the generators.

I would love to have it as a parameter since I want to use it within my automation scripts or my ansible plays Also would be nice to get all of the parameters as a yaml or json file or using environment variables

mhkarimi1383 avatar Oct 04 '22 18:10 mhkarimi1383

Yah, I'd expect this to take a JSON file as the config input (representing what you normally be in the UI):

nginxconfig --config whatever.json --out /etc/nginx

MattIPv4 avatar Oct 04 '22 19:10 MattIPv4

hey @MattIPv4 i would like to work on this is this issue still open to work?

Siddharth9890 avatar Oct 05 '23 07:10 Siddharth9890

Go for it 👍

MattIPv4 avatar Oct 05 '23 13:10 MattIPv4