Skip to content

Commit

Permalink
define args as empty list per default
Browse files Browse the repository at this point in the history
  • Loading branch information
mruoss committed Mar 19, 2023
1 parent af16a67 commit 2f0525e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- ### Added | Changed | Deprecated | Removed | Fixed | Security -->

### Fixed

- `K8s.Conn.Auth.Exec` - Define default value for `:args` - [#240](https://github.com/coryodaniel/k8s/pull/240)

### Added

- `K8s.Conn.Auth.Azure` - Azure auth provider added by @hanspagh - [#162](https://github.com/coryodaniel/k8s/issues/162), [#225](https://github.com/coryodaniel/k8s/issues/225)
Expand Down
14 changes: 6 additions & 8 deletions lib/k8s/conn/auth/exec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ defmodule K8s.Conn.Auth.Exec do
alias __MODULE__
alias K8s.Conn.Error

defstruct [:command, :env, :args]
defstruct [:command, :env, args: []]

@type t :: %__MODULE__{
command: String.t(),
Expand All @@ -46,23 +46,21 @@ defmodule K8s.Conn.Auth.Exec do
@spec create(map() | any, String.t() | any) :: {:ok, t} | {:error, Error.t()} | :skip
def create(%{"exec" => %{"command" => command} = config}, _) do
# Optional:
args = Map.get(config, "args", [])
env = Map.get(config, "env", [])
args = config["args"] |> List.wrap()
env = config["env"] |> List.wrap() |> format_env()

{:ok,
%__MODULE__{
command: command,
env: format_env(env),
env: env,
args: args
}}
end

def create(_, _), do: :skip

@spec format_env(nil | map) :: {binary, any}
defp format_env(nil), do: %{}
defp format_env(env) when is_list(env), do: Enum.into(env, %{}, &format_env/1)
defp format_env(%{"name" => key, "value" => value}), do: {key, value}
@spec format_env(list()) :: map()
defp format_env(env), do: Map.new(env, &{&1["name"], &1["value"]})

defimpl K8s.Conn.RequestOptions, for: K8s.Conn.Auth.Exec do
@doc "Generates HTTP Authorization options for auth-provider authentication"
Expand Down

0 comments on commit 2f0525e

Please sign in to comment.