revelrylabs / prodops_ex

The Elixir SDK for ProdOps
MIT License
0 stars 0 forks source link

Configuration improvements #35

Closed estreeper closed 4 months ago

estreeper commented 4 months ago

Links to #24

This modifies the project configuration, and introduces the NimbleOptions library to validate options and set default values. The practical benefits of this are that you no longer need to specify certain options if you place them somewhere in application configuration instead:

Before:

ProdopsEx.Artifact.create_artifact(%{prompt_template_id: 123, artifact_slug: "code_gen", project_id: 456, inputs: [%{name: "testinput", value: "something"}]}, %ProdopsEx.Config{bearer_token: "BEARER_TOKEN"})

After:

ProdopsEx.Artifact.create_artifact(%{prompt_template_id: 123, artifact_slug: "code_gen", project_id: 456, inputs: [%{name: "testinput", value: "something"}]})

When developing on this, values can be places in lib/prodops/config.secret.exs, and should look like:

import Config

config :prodops_ex,
  bearer_token: "YOUR TOKEN HERE"

This gets rid of the %Config{} struct, but we provide validations at runtime using NimbleOptions.validate. The one thing to remember is that the final argument of each function should be a keyword list, and configuration should be passed in to Config.resolve_config/1, which gets configuration from, in order of precedence: passed-in config, application config, default config (defined in the definition in lib/prodops/config.ex).

We can likely do something similar with the params that functions get so that we can do things like set a default project_id, but that's not included here.

estreeper commented 4 months ago

Thanks @jacksonoberkirch, good call, I added a config.example-secret.exs and just the stub of a CONTRIBUTING.md file with instructions on copying that over.