textbasedrequests / treqs

📃 text-based requests 🦖
MIT License
1 stars 1 forks source link

Dynamic parameters #3

Open FrankKair opened 2 years ago

FrankKair commented 2 years ago

When testing APIs with authentication, you often have a .env file with secrets, i.e.:

API_PASSWORD=SOME_PWD_HERE

It would be good for treqs to be able to access these values in runtime, instead of adding them to the TOML files (thus exposing company secrets):

url = "blabla"
method = "blabla"

password = "$API_PASSWORD"

In runtime, treqs could check:

Once treqs finds a .env file that contains API_PASSWORD, it can substitute the $API_PASSWORD value with SOME_PWD_HERE. Such action/function could either be part of Checker or a new module (example below):

module Treqs
  def call(filepath)
    filepath
      .then { |fpath|  Parser.call(fpath) }
      .then { |hash|   Checker.call(hash) }
+     .then { |hash|   Secrets.inject(hash) }
      .then { |hash|   Config.new(hash) }
      .then { |config| Requestor.call(config) }
  end

  module_function :call
end
FrankKair commented 2 years ago

More generally all the $VAR values can be seen as dynamic parameters. Take the following example:

url = "https://example.com"
method = "GET"

[params]
custom = "$ARG1"

When calling treqs, this is what it would look like:

$ treqs example.toml ARG1=hello

Which means that besides checking $ENV and .env files, we could also accept key-value pairs as arguments to the CLI.