Skip to content

Commit

Permalink
Use derived state use_ca_cert in SUMA GenServer (#2396)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-suse authored Mar 8, 2024
1 parent b6cef38 commit 7fd8e31
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
7 changes: 5 additions & 2 deletions lib/trento/infrastructure/software_updates/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@ defmodule Trento.Infrastructure.SoftwareUpdates.Suma.State do
:username,
:password,
:ca_cert,
:auth
:auth,
use_ca_cert: false
]

@type t :: %{
url: String.t() | nil,
username: String.t() | nil,
password: String.t() | nil,
ca_cert: String.t() | nil,
use_ca_cert: boolean(),
auth: String.t() | nil
}

defimpl Inspect, for: State do
def inspect(%State{url: url, username: username}, opts) do
def inspect(%State{url: url, username: username, use_ca_cert: use_ca_cert}, opts) do
Inspect.Map.inspect(
%{
url: url,
username: username,
use_ca_cert: use_ca_cert,
password: "<REDACTED>",
auth: "<REDACTED>",
ca_cert: "<REDACTED>"
Expand Down
11 changes: 6 additions & 5 deletions lib/trento/infrastructure/software_updates/suma.ex
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ defmodule Trento.Infrastructure.SoftwareUpdates.Suma do
defp do_handle({:get_system_id, fully_qualified_domain_name}, %State{
url: url,
auth: auth_cookie,
ca_cert: ca_cert
use_ca_cert: use_ca_cert
}),
do: SumaApi.get_system_id(url, auth_cookie, fully_qualified_domain_name, ca_cert != nil)
do: SumaApi.get_system_id(url, auth_cookie, fully_qualified_domain_name, use_ca_cert)

defp do_handle({:get_relevant_patches, system_id}, %State{
url: url,
auth: auth_cookie,
ca_cert: ca_cert
use_ca_cert: use_ca_cert
}),
do: SumaApi.get_relevant_patches(url, auth_cookie, system_id, ca_cert != nil)
do: SumaApi.get_relevant_patches(url, auth_cookie, system_id, use_ca_cert)

defp process_identifier(server_name), do: {:global, identification_tuple(server_name)}

Expand All @@ -124,7 +124,8 @@ defmodule Trento.Infrastructure.SoftwareUpdates.Suma do
username: username,
password: password,
ca_cert: ca_cert,
auth: auth_cookie
auth: auth_cookie,
use_ca_cert: ca_cert != nil
}}
end
end
Expand Down
6 changes: 6 additions & 0 deletions test/trento/infrastructure/software_updates/suma_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ defmodule Trento.Infrastructure.SoftwareUpdates.SumaTest do
username: nil,
password: nil,
ca_cert: nil,
use_ca_cert: false,
auth: nil
}

Expand Down Expand Up @@ -92,6 +93,7 @@ defmodule Trento.Infrastructure.SoftwareUpdates.SumaTest do
username: username,
password: "<REDACTED>",
ca_cert: "<REDACTED>",
use_ca_cert: true,
auth: "<REDACTED>"
}

Expand Down Expand Up @@ -126,6 +128,7 @@ defmodule Trento.Infrastructure.SoftwareUpdates.SumaTest do
username: username,
password: password,
ca_cert: ca_cert,
use_ca_cert: true,
auth: auth_cookie
}

Expand Down Expand Up @@ -153,6 +156,7 @@ defmodule Trento.Infrastructure.SoftwareUpdates.SumaTest do
username: nil,
password: nil,
ca_cert: nil,
use_ca_cert: false,
auth: nil
}

Expand Down Expand Up @@ -210,6 +214,7 @@ defmodule Trento.Infrastructure.SoftwareUpdates.SumaTest do
username: username,
password: password,
ca_cert: ca_cert,
use_ca_cert: true,
auth: "pxt-session-cookie=4321"
}

Expand All @@ -232,6 +237,7 @@ defmodule Trento.Infrastructure.SoftwareUpdates.SumaTest do
username: nil,
password: nil,
ca_cert: nil,
use_ca_cert: false,
auth: nil
}

Expand Down

0 comments on commit 7fd8e31

Please sign in to comment.