markdown-link-check icon indicating copy to clipboard operation
markdown-link-check copied to clipboard

Allow JS for config

Open bnb opened this issue 5 years ago • 12 comments

It would be ideal for the use case of CI with secrets if JS could be used for the config, assuming it returns an Object that is in the shape of the config options.

bnb avatar Aug 17 '20 23:08 bnb

Could you tell me more about your use case? MLC is already available as a JS function that you can call from any JS script and why not in your CI using Node.js. The configuration for MLC can then be passed as a JS object to the function (the options param). Is that enough or is that that you also need all the options to be configurable through this option object?

NicolasMassart avatar Sep 25 '20 15:09 NicolasMassart

@NicolasMassart specifically, I want to use the CLI --config flag and be able to pass a .js file that returns an Object that would be the same as the JSON Object that it currently looks at. This would allow me to programmatically set variables that are specific to my CI environment rather than having to write the config file in CI.

bnb avatar Sep 25 '20 17:09 bnb

Why not generate this JSON from your JS script in your CI job then use the generated JSON with the --config option?

NicolasMassart avatar Sep 26 '20 09:09 NicolasMassart

I could but having to generate the file, write it to the filesystem, make sure that it'll also exist locally when not running in CI / write it in that case, and actually testing/debugging it in CI is a lot more work for users than just writing a JS file that returns an object.

bnb avatar Sep 28 '20 16:09 bnb

The issue I see is that STDIN is already used for MD input and then can't be used for a JSON config stream input. Can you describe what you would like the command line to look like please?

NicolasMassart avatar Sep 29 '20 10:09 NicolasMassart

NOTE: It seems STDIN is not used for MD direct input as described in #67 but only to input list of files or files links using STDIN. But the issue remains the same here, STDIN is already used.

NicolasMassart avatar Oct 02 '20 09:10 NicolasMassart

A common pattern to solve this is to use ENV variables. What would you htink about giving the option to set the config as a JSON string in an env variable? This would solve your CI issue doesn't it?

NicolasMassart avatar Nov 09 '20 09:11 NicolasMassart

Theoretically yes, environment variables for every single setting would solve this problem.

bnb avatar Nov 09 '20 20:11 bnb

Going to be totally upfront: I don't understand the stdin issues enough to meaningfully be able to provide input on them.

bnb avatar Nov 09 '20 20:11 bnb

Going to be totally upfront: I don't understand the stdin issues enough to meaningfully be able to provide input on them.

Me neither, I have to dig in this a bit.

NicolasMassart avatar Nov 12 '20 14:11 NicolasMassart

Hi @ll,

there is one potential security issue where it could make sense to have a more dynamic configuration and this is when someone has to put credentials in the config stored in a repo. But instead of injecting the entire config as env variable, why don't you just implement a special replacement command for env vars like {{env.<env_var_name>}}. E.g:

{
  ...
  "httpHeaders": [
    {
      "urls": ["https://example.com"],
      "headers": {
        "Authorization": "Bearer {{env.EXAMPLE_COM_TOKEN}}",
        "Foo": "Bar"
      }
    }
  ],
  ...
}

I think this is super easy to implement, easy to understand and would give us enough flexibility.

Best, Chris

volkc avatar Dec 18 '20 06:12 volkc

For what it's worth, that was the exact use case I had.

bnb avatar Jan 22 '21 18:01 bnb