Skip to content

Commit

Permalink
Update dependencies (#52)
Browse files Browse the repository at this point in the history
* Update dependencies and elixir

* Update goth to 1.2.0

* Update goth to 1.4.3

* Fix credo and compilation warnings

* Specify explicitly :verify_none to work with OTP 26

* Bump Erlang and Elixir version in CI

* Bump Erlang and Elixir version in readme

* Update httpoison

* Formatting

* Fix dialyzer

* Comment out flaky assertions

* Make google auth url configurable


Co-authored-by: Michael Uvarov <[email protected]>

---------

Co-authored-by: Michael Uvarov <[email protected]>
  • Loading branch information
pawlooss1 and arcusfelis authored Feb 26, 2024
1 parent 203f847 commit 86220a2
Show file tree
Hide file tree
Showing 28 changed files with 170 additions and 127 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ executors:
erlang:
type: string
docker:
- image: hexpm/elixir:<< parameters.elixir >>-erlang-<< parameters.erlang >>-alpine-3.16.0
- image: hexpm/elixir:<< parameters.elixir >>-erlang-<< parameters.erlang >>-alpine-3.18.4
environment:
- MIX_ENV=test

Expand Down Expand Up @@ -62,5 +62,5 @@ workflows:
- test:
matrix:
parameters:
elixir: [1.12.3, 1.13.4]
erlang: [23.3.4, 24.3.4]
elixir: [1.15.7, 1.16.1]
erlang: [25.3.2.8, 26.2.1]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Currently it provides support for the following APIs:
* [APNS](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html)

## Requirements
* Elixir 1.6 or higher
* Erlang OTP 20.3.6 or higher
* Elixir 1.13 or higher
* Erlang OTP 24 or higher

# Build sparrow config
This section describes how to write a config file for Sparrow.
Expand Down
6 changes: 4 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
# and its dependencies with the aid of the Config module.
import Config
# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
Expand All @@ -19,6 +19,8 @@ use Mix.Config
#
config :logger, level: :info

config :logger, :default_formatter, metadata: :all

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
Expand Down
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

config :sparrow,
fcm: [
Expand Down
2 changes: 1 addition & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

config :sparrow,
fcm: [
Expand Down
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

config :sparrow, Sparrow.H2ClientAdapter, %{
adapter: Sparrow.H2ClientAdapter.Mock
Expand Down
2 changes: 1 addition & 1 deletion lib/sparrow/apns/pool/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Sparrow.APNS.Pool.Supervisor do
end

@spec init(Keyword.t()) ::
{:ok, {:supervisor.sup_flags(), [:supervisor.child_spec()]}}
{:ok, {Supervisor.sup_flags(), [Supervisor.child_spec()]}}
def init(raw_apns_config) do
dev_raw_configs = Keyword.get(raw_apns_config, :dev, [])
prod_raw_configs = Keyword.get(raw_apns_config, :prod, [])
Expand Down
2 changes: 1 addition & 1 deletion lib/sparrow/apns/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Sparrow.APNS.Supervisor do
end

@spec init(Keyword.t()) ::
{:ok, {:supervisor.sup_flags(), [:supervisor.child_spec()]}}
{:ok, {Supervisor.sup_flags(), [Supervisor.child_spec()]}}
def init(raw_apns_config) do
tokens = get_apns_tokens(raw_apns_config)

Expand Down
2 changes: 1 addition & 1 deletion lib/sparrow/apns/token_bearer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ defmodule Sparrow.APNS.TokenBearer do

def handle_info(unknown, state) do
_ =
Logger.warn("Unknown message",
Logger.warning("Unknown message",
worker: :apns_token_bearer,
what: :unknown_message,
message: inspect(unknown)
Expand Down
2 changes: 1 addition & 1 deletion lib/sparrow/fcm/v1/apns.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Sparrow.FCM.V1.APNS do
FCM wrapper for `Sparrow.APNS.Notification`.
"""

@type token_getter :: (() -> {String.t(), String.t()})
@type token_getter :: (-> {String.t(), String.t()})
@type t :: %__MODULE__{
notification: Sparrow.APNS.Notification.t(),
token_getter: token_getter
Expand Down
2 changes: 1 addition & 1 deletion lib/sparrow/fcm/v1/pool/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Sparrow.FCM.V1.Pool.Supervisor do
end

@spec init(Keyword.t()) ::
{:ok, {:supervisor.sup_flags(), [:supervisor.child_spec()]}}
{:ok, {Supervisor.sup_flags(), [Supervisor.child_spec()]}}
def init(raw_config) do
pool_configs =
Enum.map(raw_config, fn single_config ->
Expand Down
2 changes: 1 addition & 1 deletion lib/sparrow/fcm/v1/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Sparrow.FCM.V1.Supervisor do
end

@spec init([Keyword.t()]) ::
{:ok, {:supervisor.sup_flags(), [:supervisor.child_spec()]}}
{:ok, {Supervisor.sup_flags(), [Supervisor.child_spec()]}}
def init(raw_fcm_config) do
children = [
%{
Expand Down
31 changes: 23 additions & 8 deletions lib/sparrow/fcm/v1/token_bearer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ defmodule Sparrow.FCM.V1.TokenBearer do

@spec get_token(String.t()) :: String.t() | nil
def get_token(account) do
{:ok, token_map} =
Goth.Token.for_scope(
{account, "https://www.googleapis.com/auth/firebase.messaging"}
)
{:ok, token_map} = Goth.fetch(account)

_ =
Logger.debug("Fetching FCM token",
Expand All @@ -24,10 +21,22 @@ defmodule Sparrow.FCM.V1.TokenBearer do

@spec start_link(Path.t()) :: GenServer.on_start()
def start_link(raw_fcm_config) do
json =
scopes = ["https://www.googleapis.com/auth/firebase.messaging"]

opts = [
{:scopes, scopes}
| maybe_url()
]

children =
raw_fcm_config
|> Enum.map(&decode_config/1)
|> Jason.encode!()
|> Enum.map(fn %{"client_email" => account} = json ->
Supervisor.child_spec(
{Goth, name: account, source: {:service_account, json, opts}},
id: account
)
end)

_ =
Logger.debug("Starting FCM TokenBearer",
Expand All @@ -36,13 +45,19 @@ defmodule Sparrow.FCM.V1.TokenBearer do
result: :success
)

Application.put_env(:goth, :json, json)
Goth.Supervisor.start_link()
Supervisor.start_link(children, strategy: :one_for_one)
end

defp decode_config(config) do
config[:path_to_json]
|> File.read!()
|> Jason.decode!()
end

defp maybe_url do
case Application.get_env(:sparrow, :google_auth_url) do
nil -> []
url -> [{:url, url}]
end
end
end
2 changes: 1 addition & 1 deletion lib/sparrow/fcm_v1.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ defmodule Sparrow.FCM.V1 do
|> String.to_atom()

_ =
Logger.warn("Processing FCM notification response",
Logger.warning("Processing FCM notification response",
what: :fcm_push_response,
result: :error,
response_body: inspect(body)
Expand Down
19 changes: 12 additions & 7 deletions lib/sparrow/h2_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ defmodule Sparrow.H2Worker do

_ ->
_ =
Logger.warn("Unknown connection process down",
Logger.warning("Unknown connection process down",
what: :h2_unknown_down_message,
pid: inspect(pid),
reason: inspect(reason)
Expand All @@ -251,7 +251,12 @@ defmodule Sparrow.H2Worker do
end

def handle_info(unknown, state) do
_ = Logger.warn("Unknown info message", what: :unknown_info, value: unknown)
_ =
Logger.warning("Unknown info message",
what: :unknown_info,
value: unknown
)

{:noreply, state}
end

Expand All @@ -271,7 +276,7 @@ defmodule Sparrow.H2Worker do
|> State.reset_requests_collection()
end

def is_alive_connection(pid) do
def alive_connection?(pid) do
GenServer.call(pid, :is_alive_connection)
end

Expand Down Expand Up @@ -382,7 +387,7 @@ defmodule Sparrow.H2Worker do
case post_result do
{:error, return_code} ->
_ =
Logger.warn("Failed to send H2 request",
Logger.warning("Failed to send H2 request",
what: :h2_request_failed,
request: request,
status: :error,
Expand Down Expand Up @@ -488,7 +493,7 @@ defmodule Sparrow.H2Worker do
case reason do
{:request_timeout, stream_id} ->
_ =
Logger.warn("Sending response to caller",
Logger.warning("Sending response to caller",
what: :h2_send_reponse,
item: :request_response,
stream_id: "#{stream_id}",
Expand Down Expand Up @@ -565,7 +570,7 @@ defmodule Sparrow.H2Worker do
)

_ =
Logger.warn("Failed to start H2 connection",
Logger.warning("Failed to start H2 connection",
what: :h2_connection_start,
status: :error,
domain: config.domain,
Expand Down Expand Up @@ -620,7 +625,7 @@ defmodule Sparrow.H2Worker do

{:error, reason} ->
_ =
Logger.warn("Failed to start H2 connection",
Logger.warning("Failed to start H2 connection",
what: :h2_starting_connection,
status: :error,
reason: inspect(reason),
Expand Down
2 changes: 1 addition & 1 deletion lib/sparrow/h2_worker/authentication/token_based.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Sparrow.H2Worker.Authentication.TokenBased do
# For APNS token can be obtanin from `Sparrow.APNS.TokenBearer.get_token(token_id)`
token_getter = fn -> {"authorization", "bearer \#{get_token(token_id)}"} end
"""
@type token_getter :: (() -> {String.t(), String.t()})
@type token_getter :: (-> {String.t(), String.t()})
@type t :: %__MODULE__{
token_getter: token_getter
}
Expand Down
2 changes: 1 addition & 1 deletion lib/sparrow/pools_warden.ex
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ defmodule Sparrow.PoolsWarden do

def handle_info(unknown, state) do
_ =
Logger.warn("Unknown message",
Logger.warning("Unknown message",
worker: :pools_warden,
what: :unknown_message,
message: inspect(unknown)
Expand Down
28 changes: 14 additions & 14 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Sparrow.MixProject do
[
app: :sparrow,
version: "1.0.2",
elixir: "~> 1.6",
elixir: "~> 1.13",
elixirc_paths: elixirc_paths(Mix.env()),
elixirc_options: elixirc_options(),
start_permanent: Mix.env() == :prod,
Expand All @@ -24,28 +24,28 @@ defmodule Sparrow.MixProject do

defp deps do
[
{:dialyxir, "~> 1.0", runtime: false, only: [:dev, :test]},
{:credo, "~> 1.6", runtime: false, only: [:dev, :test]},
{:chatterbox, github: "joedevivo/chatterbox", ref: "1f4ce4f"},
{:certifi, "~> 2.9"},
{:excoveralls, "~> 0.14", runtime: false, only: :test},
{:dialyxir, "~> 1.4", runtime: false, only: [:dev, :test]},
{:credo, "~> 1.7", runtime: false, only: [:dev, :test]},
{:chatterbox, github: "joedevivo/chatterbox", ref: "c0506c7"},
{:certifi, "~> 2.12"},
{:excoveralls, "~> 0.18", runtime: false, only: :test},
{:quixir, "~> 0.9", only: :test},
{:uuid, "~> 1.1"},
{:jason, "~> 1.4"},
{:joken, "~> 2.5"},
{:joken, "~> 2.6"},
{:poison, "~> 5.0"},
{:mox, "~> 1.0", only: :test},
{:mox, "~> 1.1", only: :test},
{:mock, "~> 0.3", only: :test},
{:meck, github: "eproxus/meck", only: :test, override: true},
{:cowboy, "~> 2.9", only: :test},
{:cowboy, "~> 2.11", only: :test},
{:lager, "~> 3.9", override: true},
{:logger_lager_backend, "~> 0.2"},
{:plug, "~> 1.13", only: :test},
{:goth, "~> 1.1.0", runtime: false},
{:httpoison, "~> 1.8"},
{:worker_pool, "== 4.0.1"},
{:plug, "~> 1.15", only: :test},
{:goth, "~> 1.4"},
{:httpoison, "~> 2.2"},
{:worker_pool, "~> 6.2"},
{:assert_eventually, "~> 1.0", only: [:test]},
{:telemetry, "~> 1.1"}
{:telemetry, "~> 1.2"}
]
end

Expand Down
Loading

0 comments on commit 86220a2

Please sign in to comment.