Packages
avrora
0.14.0
0.30.2
0.30.1
0.30.0
0.29.2
0.29.1
0.29.0
0.28.0
0.27.0
0.26.0
0.25.0
0.24.2
0.24.1
0.24.0
0.23.0
0.22.0
0.21.1
0.21.0
0.20.0
0.19.0
0.18.1
0.18.0
0.17.0
0.16.0
0.15.0
0.14.1
0.14.0
0.13.0
0.12.0
0.11.0
0.10.0
0.9.1
0.9.0
0.8.1
0.8.0
0.7.1
0.7.0
0.6.0
0.5.1
0.5.0
0.4.0
0.3.1
0.3.0
0.2.2
0.2.1
0.2.0
0.1.1-beta
0.1.0-beta
An Elixir library for working with Avro messages conveniently. It supports local schema files and Confluent® schema registry.
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/avrora.reg.schema.ex
defmodule Mix.Tasks.Avrora.Reg.Schema do
use Mix.Task
@moduledoc """
Register either one schema or all schemas in the `Avrora.Config.schemas_path`
directory.
mix avrora.reg.schema [--all] [--name NAME]
The search of the schemas will be performed under path configured in `schemas_path`
configuration option. One of either option must be given.
## Options
* `--name` - the full name of the schema to register (exclusive with `--all`)
* `--all` - register all found schemas
The `--name` option expects that given schema name will comply to
`Avrora.Storage.File` module rules.
For example, if the schema name is `io.confluent.Payment` it should be stored
as `<schemas path>/io/confluent/Payment.avsc`
## Usage
mix avrora.reg.schema --name io.confluent.Payment
mix avrora.reg.schema --all
"""
alias Avrora.Config
alias Avrora.Schema.Name
@shortdoc "Register schema(s) in the Confluent Schema Registry"
@impl Mix.Task
def run(argv) do
{:ok, _} = Application.ensure_all_started(:avrora)
{:ok, _} = Avrora.start_link()
case argv do
["--all"] ->
[schemas_path(), "**", "*.avsc"]
|> Path.join()
|> Path.wildcard()
|> Enum.each(fn file_path ->
file_path
|> Path.relative_to(schemas_path())
|> Path.rootname()
|> String.replace("/", ".")
|> register()
end)
["--name", name] ->
name |> String.trim() |> register()
_ ->
message = """
don't know how to handle `#{Enum.join(argv, " ")}'
please use #{IO.ANSI.yellow()}mix help avrora.reg.schema#{IO.ANSI.reset()} for help
"""
Mix.shell().error(message)
exit({:shutdown, 1})
end
end
defp register(name) do
with {:ok, schema_name} <- Name.parse(name),
{:ok, schema} <- file_storage().get(name) do
Mix.shell().info("schema `#{schema_name.name}` will be registered")
registry_storage().put(schema_name.name, schema.json)
else
{:error, error} ->
Mix.shell().error("schema `#{name}' will be skipped due to an error `#{error}'")
end
end
defp schemas_path, do: Config.self().schemas_path()
defp file_storage, do: Config.self().file_storage()
defp registry_storage, do: Config.self().registry_storage()
end