fix(authz api): fix schema error
This commit is contained in:
parent
3df21a9e14
commit
c4e0eff772
|
@ -22,8 +22,7 @@
|
||||||
-include_lib("emqx/include/logger.hrl").
|
-include_lib("emqx/include/logger.hrl").
|
||||||
-include_lib("stdlib/include/ms_transform.hrl").
|
-include_lib("stdlib/include/ms_transform.hrl").
|
||||||
|
|
||||||
-define(EXAMPLE_USERNAME, #{type => username,
|
-define(EXAMPLE_USERNAME, #{username => user1,
|
||||||
key => user1,
|
|
||||||
rules => [ #{topic => <<"test/toopic/1">>,
|
rules => [ #{topic => <<"test/toopic/1">>,
|
||||||
permission => <<"allow">>,
|
permission => <<"allow">>,
|
||||||
action => <<"publish">>
|
action => <<"publish">>
|
||||||
|
@ -38,8 +37,7 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}).
|
}).
|
||||||
-define(EXAMPLE_CLIENTID, #{type => clientid,
|
-define(EXAMPLE_CLIENTID, #{clientid => client1,
|
||||||
key => client1,
|
|
||||||
rules => [ #{topic => <<"test/toopic/1">>,
|
rules => [ #{topic => <<"test/toopic/1">>,
|
||||||
permission => <<"allow">>,
|
permission => <<"allow">>,
|
||||||
action => <<"publish">>
|
action => <<"publish">>
|
||||||
|
@ -54,8 +52,7 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}).
|
}).
|
||||||
-define(EXAMPLE_ALL , #{type => all,
|
-define(EXAMPLE_ALL , #{rules => [ #{topic => <<"test/toopic/1">>,
|
||||||
rules => [ #{topic => <<"test/toopic/1">>,
|
|
||||||
permission => <<"allow">>,
|
permission => <<"allow">>,
|
||||||
action => <<"publish">>
|
action => <<"publish">>
|
||||||
}
|
}
|
||||||
|
@ -106,37 +103,39 @@ definitions() ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Record = #{
|
Username = #{
|
||||||
oneOf => [ #{type => object,
|
type => object,
|
||||||
required => [username, rules],
|
required => [username, rules],
|
||||||
properties => #{
|
properties => #{
|
||||||
username => #{
|
username => #{
|
||||||
type => string,
|
type => string,
|
||||||
example => <<"username">>
|
example => <<"username">>
|
||||||
},
|
},
|
||||||
rules => minirest:ref(<<"rules">>)
|
rules => minirest:ref(<<"rules">>)
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
, #{type => object,
|
Clientid = #{
|
||||||
required => [clientid, rules],
|
type => object,
|
||||||
properties => #{
|
required => [clientid, rules],
|
||||||
username => #{
|
properties => #{
|
||||||
type => string,
|
clientid => #{
|
||||||
example => <<"clientid">>
|
type => string,
|
||||||
},
|
example => <<"clientid">>
|
||||||
rules => minirest:ref(<<"rules">>)
|
},
|
||||||
}
|
rules => minirest:ref(<<"rules">>)
|
||||||
}
|
}
|
||||||
, #{type => object,
|
},
|
||||||
required => [rules],
|
ALL = #{
|
||||||
properties => #{
|
type => object,
|
||||||
rules => minirest:ref(<<"rules">>)
|
required => [rules],
|
||||||
}
|
properties => #{
|
||||||
}
|
rules => minirest:ref(<<"rules">>)
|
||||||
]
|
}
|
||||||
},
|
},
|
||||||
[ #{<<"rules">> => Rules}
|
[ #{<<"rules">> => Rules}
|
||||||
, #{<<"record">> => Record}
|
, #{<<"username">> => Username}
|
||||||
|
, #{<<"clientid">> => Clientid}
|
||||||
|
, #{<<"all">> => ALL}
|
||||||
].
|
].
|
||||||
|
|
||||||
purge_api() ->
|
purge_api() ->
|
||||||
|
@ -187,7 +186,12 @@ records_api() ->
|
||||||
'application/json' => #{
|
'application/json' => #{
|
||||||
schema => #{
|
schema => #{
|
||||||
type => array,
|
type => array,
|
||||||
items => minirest:ref(<<"record">>)
|
items => #{
|
||||||
|
oneOf => [ minirest:ref(<<"username">>)
|
||||||
|
, minirest:ref(<<"clientid">>)
|
||||||
|
, minirest:ref(<<"all">>)
|
||||||
|
]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
examples => #{
|
examples => #{
|
||||||
username => #{
|
username => #{
|
||||||
|
@ -226,7 +230,11 @@ records_api() ->
|
||||||
'application/json' => #{
|
'application/json' => #{
|
||||||
schema => #{
|
schema => #{
|
||||||
type => array,
|
type => array,
|
||||||
items => minirest:ref(<<"record">>)
|
items => #{
|
||||||
|
oneOf => [ minirest:ref(<<"username">>)
|
||||||
|
, minirest:ref(<<"clientid">>)
|
||||||
|
]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
examples => #{
|
examples => #{
|
||||||
username => #{
|
username => #{
|
||||||
|
@ -262,8 +270,24 @@ records_api() ->
|
||||||
requestBody => #{
|
requestBody => #{
|
||||||
content => #{
|
content => #{
|
||||||
'application/json' => #{
|
'application/json' => #{
|
||||||
schema => minirest:ref(<<"record">>),
|
schema => #{
|
||||||
|
type => array,
|
||||||
|
items => #{
|
||||||
|
oneOf => [ minirest:ref(<<"username">>)
|
||||||
|
, minirest:ref(<<"clientid">>)
|
||||||
|
, minirest:ref(<<"all">>)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
examples => #{
|
examples => #{
|
||||||
|
username => #{
|
||||||
|
summary => <<"Username">>,
|
||||||
|
value => jsx:encode(?EXAMPLE_USERNAME)
|
||||||
|
},
|
||||||
|
clientid => #{
|
||||||
|
summary => <<"Clientid">>,
|
||||||
|
value => jsx:encode(?EXAMPLE_CLIENTID)
|
||||||
|
},
|
||||||
all => #{
|
all => #{
|
||||||
summary => <<"All">>,
|
summary => <<"All">>,
|
||||||
value => jsx:encode(?EXAMPLE_ALL)
|
value => jsx:encode(?EXAMPLE_ALL)
|
||||||
|
@ -308,7 +332,11 @@ record_api() ->
|
||||||
description => <<"OK">>,
|
description => <<"OK">>,
|
||||||
content => #{
|
content => #{
|
||||||
'application/json' => #{
|
'application/json' => #{
|
||||||
schema => minirest:ref(<<"record">>),
|
schema => #{
|
||||||
|
oneOf => [ minirest:ref(<<"username">>)
|
||||||
|
, minirest:ref(<<"clientid">>)
|
||||||
|
]
|
||||||
|
},
|
||||||
examples => #{
|
examples => #{
|
||||||
username => #{
|
username => #{
|
||||||
summary => <<"Username">>,
|
summary => <<"Username">>,
|
||||||
|
@ -317,10 +345,6 @@ record_api() ->
|
||||||
clientid => #{
|
clientid => #{
|
||||||
summary => <<"Clientid">>,
|
summary => <<"Clientid">>,
|
||||||
value => jsx:encode(?EXAMPLE_CLIENTID)
|
value => jsx:encode(?EXAMPLE_CLIENTID)
|
||||||
},
|
|
||||||
all => #{
|
|
||||||
summary => <<"All">>,
|
|
||||||
value => jsx:encode(?EXAMPLE_ALL)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -353,7 +377,11 @@ record_api() ->
|
||||||
requestBody => #{
|
requestBody => #{
|
||||||
content => #{
|
content => #{
|
||||||
'application/json' => #{
|
'application/json' => #{
|
||||||
schema => minirest:ref(<<"record">>),
|
schema => #{
|
||||||
|
oneOf => [ minirest:ref(<<"username">>)
|
||||||
|
, minirest:ref(<<"clientid">>)
|
||||||
|
]
|
||||||
|
},
|
||||||
examples => #{
|
examples => #{
|
||||||
username => #{
|
username => #{
|
||||||
summary => <<"Username">>,
|
summary => <<"Username">>,
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
definitions() ->
|
definitions() ->
|
||||||
Sources = #{
|
Sources = #{
|
||||||
oneOf => [ minirest:ref(<<"http">>)
|
oneOf => [ minirest:ref(<<"http">>)
|
||||||
|
, minirest:ref(<<"built-in-database">>)
|
||||||
, minirest:ref(<<"mongo_single">>)
|
, minirest:ref(<<"mongo_single">>)
|
||||||
, minirest:ref(<<"mongo_rs">>)
|
, minirest:ref(<<"mongo_rs">>)
|
||||||
, minirest:ref(<<"mongo_sharded">>)
|
, minirest:ref(<<"mongo_sharded">>)
|
||||||
|
@ -446,6 +447,21 @@ definitions() ->
|
||||||
ssl => minirest:ref(<<"ssl">>)
|
ssl => minirest:ref(<<"ssl">>)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Mnesia = #{
|
||||||
|
type => object,
|
||||||
|
required => [type, enable],
|
||||||
|
properties => #{
|
||||||
|
type => #{
|
||||||
|
type => string,
|
||||||
|
enum => [<<"redis">>],
|
||||||
|
example => <<"redis">>
|
||||||
|
},
|
||||||
|
enable => #{
|
||||||
|
type => boolean,
|
||||||
|
example => true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
File = #{
|
File = #{
|
||||||
type => object,
|
type => object,
|
||||||
required => [type, enable, rules],
|
required => [type, enable, rules],
|
||||||
|
@ -475,6 +491,7 @@ definitions() ->
|
||||||
[ #{<<"sources">> => Sources}
|
[ #{<<"sources">> => Sources}
|
||||||
, #{<<"ssl">> => SSL}
|
, #{<<"ssl">> => SSL}
|
||||||
, #{<<"http">> => HTTP}
|
, #{<<"http">> => HTTP}
|
||||||
|
, #{<<"built-in-database">> => Mnesia}
|
||||||
, #{<<"mongo_single">> => MongoSingle}
|
, #{<<"mongo_single">> => MongoSingle}
|
||||||
, #{<<"mongo_rs">> => MongoRs}
|
, #{<<"mongo_rs">> => MongoRs}
|
||||||
, #{<<"mongo_sharded">> => MongoSharded}
|
, #{<<"mongo_sharded">> => MongoSharded}
|
||||||
|
|
|
@ -405,7 +405,7 @@ get_raw_sources() ->
|
||||||
RawSources = emqx:get_raw_config([authorization, sources]),
|
RawSources = emqx:get_raw_config([authorization, sources]),
|
||||||
Schema = #{roots => emqx_authz_schema:fields("authorization"), fields => #{}},
|
Schema = #{roots => emqx_authz_schema:fields("authorization"), fields => #{}},
|
||||||
Conf = #{<<"sources">> => RawSources},
|
Conf = #{<<"sources">> => RawSources},
|
||||||
#{sources := Sources} = hocon_schema:check_plain(Schema, Conf, #{atom_key => true, no_conversion => true}),
|
#{sources := Sources} = hocon_schema:check_plain(Schema, Conf, #{atom_key => true, only_fill_defaults => true}),
|
||||||
Sources.
|
Sources.
|
||||||
|
|
||||||
get_raw_source(Type) ->
|
get_raw_source(Type) ->
|
||||||
|
|
Loading…
Reference in New Issue