chore: fix dialyzer warnings about info generator functions.

It seems that it's now smart enough to detect that schema options with default values cannot ever return `:error`.
This commit is contained in:
James Harton 2024-05-14 14:48:50 +12:00
parent 331261f05e
commit 69dc1f1dbc
Signed by: james
GPG key ID: 90E82DAA13F624F4
2 changed files with 29 additions and 39 deletions

View file

@ -8,7 +8,7 @@ defmodule AshAuthentication.Jwt.Config do
"""
alias Ash.Resource
alias AshAuthentication.{Info, Jwt, TokenResource}
alias AshAuthentication.{Info, TokenResource}
alias Joken.{Config, Signer}
@doc """
@ -118,12 +118,9 @@ defmodule AshAuthentication.Jwt.Config do
@spec token_signer(Resource.t(), keyword) :: Signer.t()
def token_signer(resource, opts \\ []) do
algorithm =
with :error <- Keyword.fetch(opts, :signing_algorithm),
:error <- Info.authentication_tokens_signing_algorithm(resource) do
Jwt.default_algorithm()
else
{:ok, algorithm} -> algorithm
end
Keyword.get_lazy(opts, :signing_algorithm, fn ->
Info.authentication_tokens_signing_algorithm!(resource)
end)
signing_secret =
with :error <- Keyword.fetch(opts, :signing_secret),
@ -156,11 +153,8 @@ defmodule AshAuthentication.Jwt.Config do
defp token_lifetime(resource) do
resource
|> Info.authentication_tokens_token_lifetime()
|> case do
{:ok, lifetime} -> lifetime_to_seconds(lifetime)
:error -> Jwt.default_lifetime_hrs() * 60 * 60
end
|> Info.authentication_tokens_token_lifetime!()
|> lifetime_to_seconds()
end
defp lifetime_to_seconds({seconds, :seconds}), do: seconds

View file

@ -31,36 +31,32 @@ defmodule AshAuthentication.TokenResource.Actions do
"""
@spec expunge_expired(Resource.t(), keyword) :: :ok | {:error, any}
def expunge_expired(resource, opts \\ []) do
case Info.token_expunge_expired_action_name(resource) do
{:ok, expunge_expired_action_name} ->
resource
|> DataLayer.transaction(
fn -> expunge_inside_transaction(resource, expunge_expired_action_name, opts) end,
nil,
%{
type: :bulk_destroy,
metadata: %{
metadata: %{
resource: resource,
action: expunge_expired_action_name
}
}
expunge_expired_action_name = Info.token_expunge_expired_action_name!(resource)
resource
|> DataLayer.transaction(
fn -> expunge_inside_transaction(resource, expunge_expired_action_name, opts) end,
nil,
%{
type: :bulk_destroy,
metadata: %{
metadata: %{
resource: resource,
action: expunge_expired_action_name
}
)
|> case do
{:ok, {:ok, notifications}} ->
Notifier.notify(notifications)
:ok
}
}
)
|> case do
{:ok, {:ok, notifications}} ->
Notifier.notify(notifications)
:ok
{:ok, {:error, reason}} ->
{:error, reason}
{:ok, {:error, reason}} ->
{:error, reason}
{:error, reason} ->
{:error, reason}
end
:error ->
{:error, "No configured expunge_expired_action_name"}
{:error, reason} ->
{:error, reason}
end
end