-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule Logflare.Auth.Cache do | ||
@moduledoc """ | ||
Cache for Authorization context. The keys for this cache expire in the defined | ||
Cachex `expiration`. | ||
""" | ||
|
||
require Cachex.Spec | ||
|
||
alias Logflare.Auth | ||
|
||
def child_spec(_) do | ||
stats = Application.get_env(:logflare, :cache_stats, false) | ||
|
||
%{ | ||
id: __MODULE__, | ||
start: | ||
{Cachex, :start_link, | ||
[__MODULE__, [stats: stats, expiration: Cachex.Spec.expiration(default: 30_000)]]} | ||
} | ||
end | ||
|
||
@spec verify_access_token(OauthAccessToken.t() | String.t(), String.t() | [String.t()]) :: | ||
{:ok, User.t()} | {:error, term()} | ||
def verify_access_token(access_token_or_api_key, scopes), | ||
do: apply_repo_fun(__ENV__.function, [access_token_or_api_key, scopes]) | ||
|
||
defp apply_repo_fun(arg1, arg2) do | ||
Logflare.ContextCache.apply_fun(Auth, arg1, arg2) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters