refactor(connector aggregator): move shared schemas to app

This commit is contained in:
Thales Macedo Garitezi 2024-05-10 15:24:00 -03:00
parent b232784df2
commit 729441d1ce
2 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,89 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2024 EMQ Technologies Co., Ltd. All Rights Reserved.
%%--------------------------------------------------------------------
-module(emqx_connector_aggregator_schema).
-behaviour(hocon_schema).
-include_lib("typerefl/include/types.hrl").
-include_lib("hocon/include/hoconsc.hrl").
%% API
-export([
container/0
]).
%% `hocon_schema' API
-export([
namespace/0,
roots/0,
fields/1,
desc/1
]).
%%------------------------------------------------------------------------------
%% Type declarations
%%------------------------------------------------------------------------------
%%------------------------------------------------------------------------------
%% API
%%------------------------------------------------------------------------------
container() ->
{container,
hoconsc:mk(
%% TODO: Support selectors once there are more than one container.
hoconsc:union(fun
(all_union_members) -> [ref(container_csv)];
({value, _Value}) -> [ref(container_csv)]
end),
#{
required => true,
default => #{<<"type">> => <<"csv">>},
desc => ?DESC("container")
}
)}.
%%------------------------------------------------------------------------------
%% `hocon_schema' API
%%------------------------------------------------------------------------------
namespace() -> "connector_aggregator".
roots() -> [].
fields(container_csv) ->
[
{type,
mk(
csv,
#{
required => true,
desc => ?DESC("container_csv")
}
)},
{column_order,
mk(
hoconsc:array(string()),
#{
required => false,
default => [],
desc => ?DESC("container_csv_column_order")
}
)}
].
desc(Name) when
Name == container_csv
->
?DESC(Name);
desc(_Name) ->
undefined.
%%------------------------------------------------------------------------------
%% Internal fns
%%------------------------------------------------------------------------------
mk(Type, Meta) -> hoconsc:mk(Type, Meta).
ref(Name) -> hoconsc:ref(?MODULE, Name).

View File

@ -0,0 +1,19 @@
emqx_connector_aggregator_schema {
container.label:
"""Container for aggregated events"""
container.desc:
"""Settings governing the file format of an upload containing aggregated events."""
container_csv.label:
"""CSV container"""
container_csv.desc:
"""Records (events) will be aggregated and uploaded as a CSV file."""
container_csv_column_order.label:
"""CSV column order"""
container_csv_column_order.desc:
"""Event fields that will be ordered first as columns in the resulting CSV file.<br/>
Regardless of this setting, resulting CSV will contain all the fields of aggregated events, but all the columns not explicitly mentioned here will be ordered after the ones listed here in the lexicographical order."""
}