digitalocean / nginxconfig.io

⚙️ NGINX config generator on steroids 💉
https://do.co/nginxconfig
MIT License
27.76k stars 2.05k forks source link

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

Open mhkarimi1383 opened 2 years ago

mhkarimi1383 commented 2 years ago

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

MattIPv4 commented 2 years ago

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

MarryJane89 commented 2 years ago

Me too

MrJmpl3 commented 2 years ago

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

But I don't sure about some things

MattIPv4 commented 2 years ago

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.

mhkarimi1383 commented 2 years ago

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

MattIPv4 commented 2 years ago

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
Siddharth9890 commented 1 year ago

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

MattIPv4 commented 1 year ago

Go for it 👍