-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Two suggestions, but they sort of conflict with one another, so it might be better to have two different keys/hooks (only one should be configured):
- Allow
mfa():before_env_set: {MySecretManager, :resolve_secrets, []}which would be called asapply(mod, fun, [pair | args]). - Allow a
/2function, which is not used byMap.new/2directly, but is used withEnum.reduce/3. I'd love to specify this withmfa()as well, but there's some oddities involved that would need to be resolved.
Both of these are centred around the same issue, using an Elixir implementation of telia-oss/aws-env.
Using an MFA (entry 1), one could write a function that would parse values with sm:// or ssm:// or whatever and make an ExAws call to resolve the value. This would be inefficient, as ssm://foo/bar/baz showing up more than once would (of necessity) retrieve the same value. This could be mitigated with the process dictionary, but one would have no way of clearing that.
A different approach might be to do something like:
before_env_set: [collect: {MySecretManager, :collect, [%{}]}]
# elsewhere
defmodule MySecretManager do
def collect(env, cache) do
{vars, _cache} = Enum.reduce(env, {%{}, cache}, &resolve/2)
vars
end
defp resolve({key, "sm://" <> lookup}, {acc, %{lookup => value} = cache}) do
{Map.put(acc, key, value), cache}
end
defp resolve({key, "sm://" <> lookup}, {acc, cache})
value = resolve_sm(lookup)
{Map.put(acc, key, value), Map.put(cache, lookup, value)}
end
defp resolve({key, value}, {acc, cache}), do: {Map.put(acc, key, value), cache}I'm sure there's a better way to write this, but having an efficient way of resolving this without performing duplicate lookups would be very good. (There's more to what we have than what I've shown, but it's not really that different.)