Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass verify: verify_none ssl setting explicitly to httpc calls to get rid of warnings when HTTPS and OTP 25 are used #97

Merged
merged 8 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Used by "mix format"
[
line_length: 120,
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
18 changes: 11 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
timeout-minutes: 30
name: Internal Typespecs
env:
OTP: "22.3"
ELIXIR: "1.9"
OTP: "23.3"
ELIXIR: "1.11"
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
Expand Down Expand Up @@ -50,8 +50,8 @@ jobs:
runs-on: ubuntu-20.04
name: Code Style
env:
OTP: "22.3"
ELIXIR: "1.9"
OTP: "23.3"
ELIXIR: "1.11"
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
Expand Down Expand Up @@ -107,8 +107,8 @@ jobs:
timeout-minutes: 30
name: External Typespecs
env:
OTP: "22.3"
ELIXIR: "1.9"
OTP: "23.3"
ELIXIR: "1.11"
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
Expand Down Expand Up @@ -157,8 +157,12 @@ jobs:
elixir: "1.8"
- otp: "22.3"
elixir: "1.9"
- otp: "23.1"
- otp: "23.3"
elixir: "1.11"
- otp: "24.3"
elixir: "1.12"
- otp: "25.0"
elixir: "1.14"
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
Expand Down
6 changes: 2 additions & 4 deletions lib/avrora/codec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ defmodule Avrora.Codec do
...> schema.full_name
"io.confluent.Payment"
"""
@callback extract_schema(payload :: binary()) ::
{:ok, result :: Avrora.Schema.t()} | {:error, reason :: term()}
@callback extract_schema(payload :: binary()) :: {:ok, result :: Avrora.Schema.t()} | {:error, reason :: term()}

@doc """
Decode a binary Avro message into the Elixir data.
Expand All @@ -46,8 +45,7 @@ defmodule Avrora.Codec do
{:ok, %{"id" => "00000000-0000-0000-0000-000000000000", "amount" => 15.99}}

"""
@callback decode(payloadd :: binary()) ::
{:ok, result :: map() | list(map())} | {:error, reason :: term()}
@callback decode(payloadd :: binary()) :: {:ok, result :: map() | list(map())} | {:error, reason :: term()}

@doc """
Decode a binary Avro message into the Elixir data with given schema.
Expand Down
8 changes: 2 additions & 6 deletions lib/avrora/codec/schema_registry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,14 @@ defmodule Avrora.Codec.SchemaRegistry do
case payload do
<<@magic_bytes, <<id::size(32)>>, body::binary>> ->
unless is_nil(schema.id) do
Logger.warn(
"message already contains embeded schema id, given schema id will be ignored"
)
Logger.warn("message already contains embeded schema id, given schema id will be ignored")
end

schema = %Schema{schema | id: id}

with {:ok, schema} <- resolve(schema) do
if id != schema.id do
Logger.warn(
"message embeded schema id is different from the resolved and used schema id"
)
Logger.warn("message embeded schema id is different from the resolved and used schema id")
end

Codec.Plain.decode(body, schema: schema)
Expand Down
12 changes: 3 additions & 9 deletions lib/avrora/encoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ defmodule Avrora.Encoder do
def decode(payload, schema_name: schema_name) when is_binary(payload) do
with {:ok, schema_name} <- Name.parse(schema_name) do
unless is_nil(schema_name.version) do
Logger.warn(
"decoding with schema version is not supported, `#{schema_name.name}` used instead"
)
Logger.warn("decoding with schema version is not supported, `#{schema_name.name}` used instead")
end

schema = %Schema{full_name: schema_name.name}
Expand Down Expand Up @@ -100,9 +98,7 @@ defmodule Avrora.Encoder do
def decode_plain(payload, schema_name: schema_name) when is_binary(payload) do
with {:ok, schema_name} <- Name.parse(schema_name) do
unless is_nil(schema_name.version) do
Logger.warn(
"decoding with schema version is not supported, `#{schema_name.name}` used instead"
)
Logger.warn("decoding with schema version is not supported, `#{schema_name.name}` used instead")
end

Codec.Plain.decode(payload, schema: %Schema{full_name: schema_name.name})
Expand Down Expand Up @@ -144,9 +140,7 @@ defmodule Avrora.Encoder do
end

unless is_nil(schema_name.version) do
Logger.warn(
"encoding with schema version is not supported yet, `#{schema_name.name}` used instead"
)
Logger.warn("encoding with schema version is not supported yet, `#{schema_name.name}` used instead")
end

schema = %Schema{full_name: schema_name.name}
Expand Down
6 changes: 4 additions & 2 deletions lib/avrora/http_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Avrora.HTTPClient do
@spec get(String.t(), keyword(String.t())) :: {:ok, map()} | {:error, term()}
def get(url, options \\ []) do
with {:ok, headers} <- extract_headers(options),
{:ok, {{_, status, _}, _, body}} <- :httpc.request(:get, {'#{url}', headers}, [], []) do
{:ok, {{_, status, _}, _, body}} <- :httpc.request(:get, {'#{url}', headers}, [ssl: ssl_options()], []) do
handle(status, body)
end
end
Expand All @@ -22,7 +22,7 @@ defmodule Avrora.HTTPClient do
{:ok, content_type} <- Keyword.fetch(options, :content_type),
{:ok, headers} <- extract_headers(options),
{:ok, {{_, status, _}, _, body}} <-
:httpc.request(:post, {'#{url}', headers, [content_type], body}, [], []) do
:httpc.request(:post, {'#{url}', headers, [content_type], body}, [ssl: ssl_options()], []) do
handle(status, body)
end
end
Expand All @@ -42,4 +42,6 @@ defmodule Avrora.HTTPClient do
{:error, _} -> {:error, {status, body}}
end
end

defp ssl_options, do: [verify: :verify_none]
end
6 changes: 2 additions & 4 deletions lib/avrora/resolver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ defmodule Avrora.Resolver do
...> schema.full_name
"io.confluent.Payment"
"""
@spec resolve_any(nonempty_list(integer() | String.t())) ::
{:ok, Avrora.Schema.t()} | {:error, term()}
@spec resolve_any(nonempty_list(integer() | String.t())) :: {:ok, Avrora.Schema.t()} | {:error, term()}
def resolve_any(ids) do
ids = List.wrap(ids)
total = Enum.count(ids)
Expand Down Expand Up @@ -100,8 +99,7 @@ defmodule Avrora.Resolver do
defp resolve_with_registry(schema_name) do
if Config.self().registry_schemas_autoreg() && is_nil(schema_name.version) do
with {:ok, schema} <- file_storage().get(schema_name.origin),
{:error, :unconfigured_registry_url} <-
registry_storage().put(schema_name.name, schema.json),
{:error, :unconfigured_registry_url} <- registry_storage().put(schema_name.name, schema.json),
do: {:reclaim, schema}
else
with {:error, :unconfigured_registry_url} <- registry_storage().get(schema_name.origin),
Expand Down
6 changes: 2 additions & 4 deletions lib/avrora/storage.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ defmodule Avrora.Storage do
@typedoc "Schema indentifier."
@type schema_id :: String.t() | integer()

@callback get(key :: schema_id) ::
{:ok, result :: nil | Avrora.Schema.t()} | {:error, reason :: term()}
@callback get(key :: schema_id) :: {:ok, result :: nil | Avrora.Schema.t()} | {:error, reason :: term()}

@callback put(key :: schema_id, value :: Avrora.Schema.t()) ::
{:ok, result :: Avrora.Schema.t()} | {:error, reason :: term()}
Expand All @@ -22,8 +21,7 @@ defmodule Avrora.Storage do
@typedoc "Naive timestamp with second precision."
@type timestamp :: timeout()

@callback delete(key :: Storage.schema_id()) ::
{:ok, result :: boolean()} | {:error, reason :: term()}
@callback delete(key :: Storage.schema_id()) :: {:ok, result :: boolean()} | {:error, reason :: term()}

@callback expire(key :: Storage.schema_id(), ttl :: timeout()) ::
{:ok, timestamp :: timestamp()} | {:error, reason :: term()}
Expand Down
4 changes: 1 addition & 3 deletions lib/avrora/storage/file.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ defmodule Avrora.Storage.File do
with {:ok, schema_name} <- Name.parse(name),
filepath <- name_to_filepath(schema_name.name) do
unless is_nil(schema_name.version) do
Logger.warn(
"reading schema file with version is not allowed, `#{schema_name.name}` used instead"
)
Logger.warn("reading schema file with version is not allowed, `#{schema_name.name}` used instead")
end

Logger.debug("reading schema `#{schema_name.name}` from the file #{filepath}")
Expand Down
3 changes: 1 addition & 2 deletions lib/avrora/storage/memory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ defmodule Avrora.Storage.Memory do
def put(key, value), do: put(__MODULE__, key, value)

@doc false
@spec put(pid() | atom(), Storage.schema_id(), Schema.t()) ::
{:ok, Avrora.Schema.t()} | {:error, term()}
@spec put(pid() | atom(), Storage.schema_id(), Schema.t()) :: {:ok, Avrora.Schema.t()} | {:error, term()}
def put(pid, key, value), do: {GenServer.cast(pid, {:put, key, value}), value}

@doc """
Expand Down
4 changes: 1 addition & 3 deletions lib/avrora/storage/registry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ defmodule Avrora.Storage.Registry do
{:ok, id} <- Map.fetch(response, "id"),
{:ok, schema} <- SchemaEncoder.from_json(value) do
unless is_nil(schema_name.version) do
Logger.warn(
"storing schema with version is not allowed, `#{schema_name.name}` used instead"
)
Logger.warn("storing schema with version is not allowed, `#{schema_name.name}` used instead")
end

Logger.debug("new schema `#{schema_name.name}` stored with global id `#{id}`")
Expand Down
6 changes: 2 additions & 4 deletions lib/avrora/utils/registrar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ defmodule Avrora.Utils.Registrar do
...> schema.full_name
"io.confluent.Payment"
"""
@spec register_schema_by_name(String.t(), as: String.t(), force: boolean) ::
{:ok, Schema.t()} | {:error, term()}
@spec register_schema_by_name(String.t(), as: String.t(), force: boolean) :: {:ok, Schema.t()} | {:error, term()}
def register_schema_by_name(name, opts \\ []) do
if Keyword.get(opts, :force, false) do
with {:ok, schema} <- file_storage().get(name), do: register_schema(schema, opts)
Expand Down Expand Up @@ -77,8 +76,7 @@ defmodule Avrora.Utils.Registrar do
...> schema.full_name
"io.confluent.Payment"
"""
@spec register_schema(Schema.t(), as: String.t(), force: boolean) ::
{:ok, Schema.t()} | {:error, term()}
@spec register_schema(Schema.t(), as: String.t(), force: boolean) :: {:ok, Schema.t()} | {:error, term()}
def register_schema(schema, opts \\ []) do
full_name =
if is_nil(schema.version),
Expand Down
Loading