Merge pull request #13456 from thalesmg/20240711-r57-minor-schema-registry-api-nit
fix(schema registry): handle large names during lookup
This commit is contained in:
commit
5be654e31e
|
@ -44,6 +44,12 @@
|
||||||
get_serde/1
|
get_serde/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
%%-------------------------------------------------------------------------------------------------
|
||||||
|
%% Type definitions
|
||||||
|
%%-------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-define(BAD_SCHEMA_NAME, <<"bad_schema_name">>).
|
||||||
|
|
||||||
-type schema() :: #{
|
-type schema() :: #{
|
||||||
type := serde_type(),
|
type := serde_type(),
|
||||||
source := binary(),
|
source := binary(),
|
||||||
|
@ -87,6 +93,8 @@ get_schema(SchemaName) ->
|
||||||
Config ->
|
Config ->
|
||||||
{ok, Config}
|
{ok, Config}
|
||||||
catch
|
catch
|
||||||
|
throw:#{reason := ?BAD_SCHEMA_NAME} ->
|
||||||
|
{error, not_found};
|
||||||
throw:not_found ->
|
throw:not_found ->
|
||||||
{error, not_found}
|
{error, not_found}
|
||||||
end.
|
end.
|
||||||
|
@ -343,16 +351,20 @@ to_bin(A) when is_atom(A) -> atom_to_binary(A);
|
||||||
to_bin(B) when is_binary(B) -> B.
|
to_bin(B) when is_binary(B) -> B.
|
||||||
|
|
||||||
schema_name_bin_to_atom(Bin) when size(Bin) > 255 ->
|
schema_name_bin_to_atom(Bin) when size(Bin) > 255 ->
|
||||||
throw(
|
Msg = iolist_to_binary(
|
||||||
iolist_to_binary(
|
|
||||||
io_lib:format(
|
io_lib:format(
|
||||||
"Name is is too long."
|
"Name is is too long."
|
||||||
" Please provide a shorter name (<= 255 bytes)."
|
" Please provide a shorter name (<= 255 bytes)."
|
||||||
" The name that is too long: \"~s\"",
|
" The name that is too long: \"~s\"",
|
||||||
[Bin]
|
[Bin]
|
||||||
)
|
)
|
||||||
)
|
),
|
||||||
);
|
Reason = #{
|
||||||
|
kind => validation_error,
|
||||||
|
reason => ?BAD_SCHEMA_NAME,
|
||||||
|
hint => Msg
|
||||||
|
},
|
||||||
|
throw(Reason);
|
||||||
schema_name_bin_to_atom(Bin) ->
|
schema_name_bin_to_atom(Bin) ->
|
||||||
try
|
try
|
||||||
binary_to_existing_atom(Bin, utf8)
|
binary_to_existing_atom(Bin, utf8)
|
||||||
|
|
|
@ -347,7 +347,8 @@ t_crud(Config) ->
|
||||||
|
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
%% Tests that we can't create names that are too long and get a decent error message.
|
%% Tests that we can't create or lookup names that are too long and get a decent error
|
||||||
|
%% message.
|
||||||
t_name_too_long(Config) ->
|
t_name_too_long(Config) ->
|
||||||
SerdeType = ?config(serde_type, Config),
|
SerdeType = ?config(serde_type, Config),
|
||||||
SourceBin = ?config(schema_source, Config),
|
SourceBin = ?config(schema_source, Config),
|
||||||
|
@ -368,4 +369,11 @@ t_name_too_long(Config) ->
|
||||||
}},
|
}},
|
||||||
request({post, Params})
|
request({post, Params})
|
||||||
),
|
),
|
||||||
|
?assertMatch(
|
||||||
|
{ok, 404, #{
|
||||||
|
<<"code">> := <<"NOT_FOUND">>,
|
||||||
|
<<"message">> := <<"Schema not found">>
|
||||||
|
}},
|
||||||
|
request({get, SchemaName})
|
||||||
|
),
|
||||||
ok.
|
ok.
|
||||||
|
|
Loading…
Reference in New Issue