Skip to content

Commit 762891d

Browse files
Add proxy settings to the schema
1 parent 534e4f1 commit 762891d

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

deps/rabbitmq_auth_backend_oauth2/priv/schema/rabbitmq_auth_backend_oauth2.schema

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,21 @@
220220
rabbit_oauth2_schema:translate_oauth_providers(Conf)
221221
end}.
222222

223+
{mapping,
224+
"auth_oauth2.proxy",
225+
"rabbitmq_auth_backend_oauth2.key_config.proxy",
226+
[{datatype, string}]}.
227+
228+
{mapping,
229+
"auth_oauth2.proxy_username",
230+
"rabbitmq_auth_backend_oauth2.key_config.proxy_username",
231+
[{datatype, string}]}.
232+
233+
{mapping,
234+
"auth_oauth2.proxy_password",
235+
"rabbitmq_auth_backend_oauth2.key_config.proxy_password",
236+
[{datatype, string}]}.
237+
223238
{mapping,
224239
"auth_oauth2.https.peer_verification",
225240
"rabbitmq_auth_backend_oauth2.key_config.peer_verification",
@@ -322,6 +337,21 @@
322337
"rabbitmq_auth_backend_oauth2.oauth_providers",
323338
[{datatype, integer}]}.
324339

340+
{mapping,
341+
"auth_oauth2.oauth_providers.$name.proxy",
342+
"rabbitmq_auth_backend_oauth2.oauth_providers",
343+
[{datatype, string}]}.
344+
345+
{mapping,
346+
"auth_oauth2.oauth_providers.$name.proxy_username",
347+
"rabbitmq_auth_backend_oauth2.oauth_providers",
348+
[{datatype, string}]}.
349+
350+
{mapping,
351+
"auth_oauth2.oauth_providers.$name.proxy_password",
352+
"rabbitmq_auth_backend_oauth2.oauth_providers",
353+
[{datatype, string}]}.
354+
325355
{mapping,
326356
"auth_oauth2.oauth_providers.$name.https.hostname_verification",
327357
"rabbitmq_auth_backend_oauth2.oauth_providers",

deps/rabbitmq_auth_backend_oauth2/src/rabbit_oauth2_provider.erl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,38 @@ get_algorithms(OAuthProviderId) ->
173173
V -> proplists:get_value(algorithms, V, undefined)
174174
end.
175175

176+
-spec get_proxy(oauth_provider_id()) -> list() | undefined.
177+
get_proxy(root) ->
178+
proplists:get_value(proxy, get_env(key_config, []), undefined);
179+
get_proxy(OAuthProviderId) ->
180+
OAuthProviders = get_env(oauth_providers, #{}),
181+
case maps:get(OAuthProviderId, OAuthProviders, undefined) of
182+
undefined -> undefined;
183+
V -> proplists:get_value(proxy, V, undefined)
184+
end.
185+
186+
-spec get_proxy_auth(oauth_provider_id()) -> {list(),list()} | undefined.
187+
get_proxy_auth(root) ->
188+
get_proxy_auth(
189+
proplists:get_value(proxy_username, get_env(key_config, []), undefined),
190+
proplists:get_value(proxy_password, get_env(key_config, []), undefined)
191+
);
192+
get_proxy_auth(OAuthProviderId) ->
193+
OAuthProviders = get_env(oauth_providers, #{}),
194+
case maps:get(OAuthProviderId, OAuthProviders, undefined) of
195+
undefined -> undefined;
196+
V -> get_proxy_auth(
197+
proplists:get_value(proxy_username, V, undefined),
198+
proplists:get_value(proxy_password, V, undefined)
199+
)
200+
end.
201+
get_proxy_auth(Username, Password) ->
202+
case {Username, Password} of
203+
{undefined, _} -> undefined;
204+
{_, undefined} -> undefined;
205+
{_,_} = Auth -> Auth
206+
end.
207+
176208
get_env(Par) ->
177209
application:get_env(rabbitmq_auth_backend_oauth2, Par, undefined).
178210
get_env(Par, Def) ->

deps/rabbitmq_auth_backend_oauth2/src/rabbit_oauth2_schema.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ mapOauthProviderProperty({Key, Value}) ->
261261
cuttlefish:invalid(io_lib:format(
262262
"Invalid attribute (~p) value: should be a map of Key,Value pairs",
263263
[Key]));
264+
proxy -> validator_uri(Key, Value);
265+
proxy_username -> binary_to_list(Value);
266+
proxy_password -> binary_to_list(Value);
264267
_ -> Value
265268
end}.
266269

deps/rabbitmq_auth_backend_oauth2/test/config_schema_SUITE_data/rabbitmq_auth_backend_oauth2.snippets

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,5 +316,31 @@
316316
}
317317
]}
318318
], []
319+
},
320+
{proxy,
321+
"auth_oauth2.proxy = http://localproxy:8080
322+
auth_oauth2.proxy_username = proxyuser
323+
auth_oauth2.proxy_password = proxypwd
324+
auth_oauth2.oauth_providers.keycloak.proxy = http://localproxy2:8080
325+
auth_oauth2.oauth_providers.keycloak.proxy_username = proxyuser2
326+
auth_oauth2.oauth_providers.keycloak.proxy_password = proxypwd2",
327+
[
328+
{rabbitmq_auth_backend_oauth2, [
329+
{key_config, [
330+
{proxy_password, "proxypwd"},
331+
{proxy_username, "proxyuser"},
332+
{proxy, "http://localproxy:8080"}
333+
]},
334+
{oauth_providers,
335+
#{
336+
<<"keycloak">> => [
337+
{proxy_password, "proxypwd2"},
338+
{proxy_username, "proxyuser2"},
339+
{proxy, "http://localproxy2:8080"}
340+
]
341+
}
342+
}
343+
]}
344+
], []
319345
}
320346
].

0 commit comments

Comments
 (0)