docs(bridge_v2): add specs for CRUD functions
This commit is contained in:
parent
425d0db310
commit
729e7df0d5
|
@ -107,6 +107,20 @@
|
||||||
bridge_v1_start/2
|
bridge_v1_start/2
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
%%====================================================================
|
||||||
|
%% Types
|
||||||
|
%%====================================================================
|
||||||
|
|
||||||
|
-type bridge_v2_info() :: #{
|
||||||
|
type := binary(),
|
||||||
|
name := binary(),
|
||||||
|
raw_config := map(),
|
||||||
|
resource_data := map(),
|
||||||
|
status := emqx_resource:resource_status(),
|
||||||
|
%% Explanation of the status if the status is not connected
|
||||||
|
error := term()
|
||||||
|
}.
|
||||||
|
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
%% Loading and unloading config when EMQX starts and stops
|
%% Loading and unloading config when EMQX starts and stops
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
|
@ -157,6 +171,7 @@ unload_bridges() ->
|
||||||
%% CRUD API
|
%% CRUD API
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
|
|
||||||
|
-spec lookup(binary() | atom(), binary() | atom()) -> {ok, bridge_v2_info()} | {error, not_found}.
|
||||||
lookup(Type, Name) ->
|
lookup(Type, Name) ->
|
||||||
case emqx:get_raw_config([?ROOT_KEY, Type, Name], not_found) of
|
case emqx:get_raw_config([?ROOT_KEY, Type, Name], not_found) of
|
||||||
not_found ->
|
not_found ->
|
||||||
|
@ -191,8 +206,8 @@ lookup(Type, Name) ->
|
||||||
{disconnected, <<"Pending installation">>}
|
{disconnected, <<"Pending installation">>}
|
||||||
end,
|
end,
|
||||||
{ok, #{
|
{ok, #{
|
||||||
type => Type,
|
type => bin(Type),
|
||||||
name => Name,
|
name => bin(Name),
|
||||||
raw_config => RawConf,
|
raw_config => RawConf,
|
||||||
resource_data => InstanceData,
|
resource_data => InstanceData,
|
||||||
status => DisplayBridgeV2Status,
|
status => DisplayBridgeV2Status,
|
||||||
|
@ -200,9 +215,12 @@ lookup(Type, Name) ->
|
||||||
}}
|
}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec list() -> [bridge_v2_info() | {error, term()}].
|
||||||
list() ->
|
list() ->
|
||||||
list_with_lookup_fun(fun lookup/2).
|
list_with_lookup_fun(fun lookup/2).
|
||||||
|
|
||||||
|
-spec create(atom() | binary(), binary(), map()) ->
|
||||||
|
{ok, emqx_config:update_result()} | {error, any()}.
|
||||||
create(BridgeType, BridgeName, RawConf) ->
|
create(BridgeType, BridgeName, RawConf) ->
|
||||||
?SLOG(debug, #{
|
?SLOG(debug, #{
|
||||||
brige_action => create,
|
brige_action => create,
|
||||||
|
@ -217,9 +235,10 @@ create(BridgeType, BridgeName, RawConf) ->
|
||||||
#{override_to => cluster}
|
#{override_to => cluster}
|
||||||
).
|
).
|
||||||
|
|
||||||
%% NOTE: This function can cause broken references but it is only called from
|
%% NOTE: This function can cause broken references from rules but it is only
|
||||||
%% test cases.
|
%% called directly from test cases.
|
||||||
-spec remove(atom() | binary(), binary()) -> ok | {error, any()}.
|
|
||||||
|
-spec remove(atom() | binary(), atom() | binary()) -> ok | {error, any()}.
|
||||||
remove(BridgeType, BridgeName) ->
|
remove(BridgeType, BridgeName) ->
|
||||||
?SLOG(debug, #{
|
?SLOG(debug, #{
|
||||||
brige_action => remove,
|
brige_action => remove,
|
||||||
|
@ -237,6 +256,7 @@ remove(BridgeType, BridgeName) ->
|
||||||
{error, Reason} -> {error, Reason}
|
{error, Reason} -> {error, Reason}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec check_deps_and_remove(atom() | binary(), atom() | binary(), boolean()) -> ok | {error, any()}.
|
||||||
check_deps_and_remove(BridgeType, BridgeName, AlsoDeleteActions) ->
|
check_deps_and_remove(BridgeType, BridgeName, AlsoDeleteActions) ->
|
||||||
AlsoDelete =
|
AlsoDelete =
|
||||||
case AlsoDeleteActions of
|
case AlsoDeleteActions of
|
||||||
|
|
Loading…
Reference in New Issue