Skip to content

Commit b00c268

Browse files
Set capabilities parameters
1 parent 64a3a31 commit b00c268

File tree

2 files changed

+60
-8
lines changed

2 files changed

+60
-8
lines changed

deps/rabbitmq_shovel/src/rabbit_shovel_parameters.erl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ amqp10_src_validation(_Def, User) ->
133133
{<<"src-uri">>, validate_uri_fun(User), mandatory},
134134
{<<"src-address">>, fun rabbit_parameter_validation:binary/2, mandatory},
135135
{<<"src-prefetch-count">>, fun rabbit_parameter_validation:number/2, optional},
136-
{<<"src-delete-after">>, fun validate_delete_after/2, optional}
136+
{<<"src-delete-after">>, fun validate_delete_after/2, optional},
137+
{<<"src-capabilities">>, fun validate_link_capabilities/2, optional}
137138
].
138139

139140
amqp091_src_validation(_Def, User) ->
@@ -168,7 +169,8 @@ amqp10_dest_validation(_Def, User) ->
168169
{<<"dest-application-properties">>, fun validate_amqp10_map/2, optional},
169170
{<<"dest-message-annotations">>, fun validate_amqp10_map/2, optional},
170171
% TODO: restrict to allowed fields
171-
{<<"dest-properties">>, fun validate_amqp10_map/2, optional}
172+
{<<"dest-properties">>, fun validate_amqp10_map/2, optional},
173+
{<<"dest-capabilities">>, fun validate_link_capabilities/2, optional}
172174
].
173175

174176
amqp091_dest_validation(_Def, User) ->
@@ -208,6 +210,17 @@ validate_uri(Name, Term, User) ->
208210
E -> E
209211
end.
210212

213+
validate_link_capabilities(Capabilities, Term) ->
214+
case rabbit_parameter_validation:list(Capabilities, Term) of
215+
ok -> case [V || C <- Capabilities,
216+
V <- [rabbit_parameter_validation:binary(C, Term)],
217+
element(1, V) =:= error] of
218+
[] -> ok;
219+
[E | _] -> E
220+
end;
221+
E -> E
222+
end.
223+
211224
validate_params_user(#amqp_params_direct{}, none) ->
212225
ok;
213226
validate_params_user(#amqp_params_direct{virtual_host = VHost},

deps/rabbitmq_shovel/test/parameters_SUITE.erl

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ groups() ->
3434
parse_amqp10,
3535
parse_amqp10_minimal,
3636
validate_amqp10,
37-
validate_amqp10_with_a_map
37+
validate_amqp10_with_a_map,
38+
validate_amqp10_with_wrong_capabilities_type
3839
]}
3940
].
4041

@@ -230,6 +231,7 @@ parse_amqp10(_Config) ->
230231
{<<"src-address">>, <<"a-src-queue">>},
231232
{<<"src-delete-after">>, <<"never">>},
232233
{<<"src-prefetch-count">>, 30},
234+
{<<"src-capabilities">>, []},
233235

234236
{<<"dest-protocol">>, <<"amqp10">>},
235237
{<<"dest-uri">>, <<"amqp://remotehost:5672">>},
@@ -240,7 +242,8 @@ parse_amqp10(_Config) ->
240242
<<"app-prop-value">>}]},
241243
{<<"dest-message-annotations">>, [{<<"some-message-ann">>,
242244
<<"message-ann-value">>}]},
243-
{<<"dest-properties">>, [{<<"user_id">>, <<"some-user">>}]}
245+
{<<"dest-properties">>, [{<<"user_id">>, <<"some-user">>}]},
246+
{<<"dest-capabilities">>, [<<"one">>, <<"two">>]}
244247
],
245248
ObfuscatedParams = rabbit_shovel_parameters:obfuscate_uris_in_definition(Params),
246249
?assertMatch(
@@ -250,7 +253,8 @@ parse_amqp10(_Config) ->
250253
uris := ["amqp://localhost:5672"],
251254
delete_after := never,
252255
prefetch_count := 30,
253-
source_address := <<"a-src-queue">>
256+
source_address := <<"a-src-queue">>,
257+
receiver_capabilities := []
254258
},
255259
dest := #{module := rabbit_amqp10_shovel,
256260
uris := ["amqp://remotehost:5672"],
@@ -261,7 +265,8 @@ parse_amqp10(_Config) ->
261265
<<"app-prop-value">>},
262266
properties := #{user_id := <<"some-user">>},
263267
add_timestamp_header := true,
264-
add_forward_headers := true
268+
add_forward_headers := true,
269+
sender_capabilities := [<<"one">>, <<"two">>]
265270
}
266271
}},
267272
rabbit_shovel_parameters:parse({"vhost", "my_shovel"}, "my-cluster",
@@ -327,6 +332,34 @@ validate_amqp10(_Config) ->
327332
[] = validate_ok(Res),
328333
ok.
329334

335+
validate_amqp10_with_wrong_capabilities_type(_Config) ->
336+
Params =
337+
#{
338+
<<"ack-mode">> => <<"on-publish">>,
339+
<<"reconnect-delay">> => 1001,
340+
341+
<<"src-protocol">> => <<"amqp10">>,
342+
<<"src-uri">> => <<"amqp://localhost:5672">>,
343+
<<"src-address">> => <<"a-src-queue">>,
344+
<<"src-delete-after">> => <<"never">>,
345+
<<"src-prefetch-count">> => 30,
346+
<<"src-capabilities">> => <<"one">>,
347+
348+
<<"dest-protocol">> => <<"amqp10">>,
349+
<<"dest-uri">> => <<"amqp://remotehost:5672">>,
350+
<<"dest-address">> => <<"a-dest-queue">>,
351+
<<"dest-add-forward-headers">> => true,
352+
<<"dest-add-timestamp-header">> => true,
353+
<<"dest-application-properties">> => [{<<"some-app-prop">>,
354+
<<"app-prop-value">>}],
355+
<<"dest-message-annotations">> => [{<<"some-message-ann">>, <<"message-ann-value">>}],
356+
<<"dest-properties">> => #{<<"user_id">> => <<"some-user">>}
357+
},
358+
Res = rabbit_shovel_parameters:validate("my-vhost", <<"shovel">>,
359+
"my-shovel", Params, none),
360+
{error, _, [<<"src-capabilities">>, <<"one">>]} = find_first_error(Res).
361+
362+
330363
validate_amqp10_with_a_map(_Config) ->
331364
Params =
332365
#{
@@ -352,8 +385,7 @@ validate_amqp10_with_a_map(_Config) ->
352385

353386
Res = rabbit_shovel_parameters:validate("my-vhost", <<"shovel">>,
354387
"my-shovel", Params, none),
355-
[] = validate_ok(Res),
356-
ok.
388+
validate_ok(Res).
357389

358390
validate_ok([ok | T]) ->
359391
validate_ok(T);
@@ -362,3 +394,10 @@ validate_ok([[_|_] = L | T]) ->
362394
validate_ok([]) -> [];
363395
validate_ok(X) ->
364396
exit({not_ok, X}).
397+
find_first_error([]) ->
398+
undefined;
399+
find_first_error([V | T]) ->
400+
case V of
401+
{error, _, _} = E -> E;
402+
_ -> find_first_error(T)
403+
end.

0 commit comments

Comments
 (0)