Skip to content

Commit ce5c461

Browse files
Add version endpoint
And reload page if version has changed
1 parent 3687f2e commit ce5c461

File tree

4 files changed

+47
-15
lines changed

4 files changed

+47
-15
lines changed

deps/rabbitmq_management/priv/www/js/main.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function getAccessToken() {
9191
function start_app_login () {
9292
app = new Sammy.Application(function () {
9393
this.get('/', function () {})
94-
this.get('#/', function () {})
94+
this.get('#/', function () {})
9595
if (!oauth.enabled || !oauth.oauth_disable_basic_auth) {
9696
this.put('#/login', function() {
9797
set_basic_auth(this.params['username'], this.params['password'])
@@ -115,6 +115,7 @@ function start_app_login () {
115115

116116

117117
function check_login () {
118+
check_etag()
118119
user = JSON.parse(sync_get('/whoami'));
119120
if (user == false || user.error) {
120121
clear_auth();
@@ -1863,10 +1864,11 @@ function get_chart_range_type(arg) {
18631864
return 'basic';
18641865
}
18651866

1866-
function check_etag(etag) {
1867-
lastEtag = get_pref('etag')
1868-
if (!lastEtag || lastEtag != etag) {
1869-
store_pref('etag', etag)
1867+
function check_etag() {
1868+
let curVersion = sync_get('/version')
1869+
let storedVersion = get_pref('version')
1870+
if (!storedVersion || storedVersion != curVersion) {
1871+
store_pref('version', curVersion)
18701872
location.reload()
18711873
}
18721874
}

deps/rabbitmq_management/src/rabbit_mgmt_dispatcher.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,5 +208,6 @@ dispatcher() ->
208208
{"/auth/attempts/:node/source", rabbit_mgmt_wm_auth_attempts, [by_source]},
209209
{"/login", rabbit_mgmt_wm_login, []},
210210
{"/config/effective", rabbit_mgmt_wm_environment, []},
211-
{"/auth/hash_password/:password", rabbit_mgmt_wm_hash_password, []}
211+
{"/auth/hash_password/:password", rabbit_mgmt_wm_hash_password, []},
212+
{"/version", rabbit_mgmt_wm_version, []}
212213
].

deps/rabbitmq_management/src/rabbit_mgmt_oauth_bootstrap.erl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,12 @@ bootstrap_oauth(Req0, State) ->
1919
AuthSettings = rabbit_mgmt_wm_auth:authSettings(),
2020
Dependencies = oauth_dependencies(),
2121
JSContent = import_dependencies(Dependencies) ++
22-
check_etag() ++
2322
set_oauth_settings(AuthSettings) ++
2423
set_token_auth(AuthSettings, Req0) ++
2524
export_dependencies(Dependencies),
2625
{ok, cowboy_req:reply(200, #{<<"content-type">> => <<"text/javascript; charset=utf-8">>},
2726
JSContent, Req0), State}.
2827

29-
check_etag() ->
30-
ETag = case {rabbit:product_name(), rabbit:product_version()} of
31-
{undefined, _} -> rabbit:base_product_version();
32-
{_, undefined} -> rabbit:base_product_version();
33-
{_,_} -> rabbit:product_name() ++ " " ++ rabbit:product_version()
34-
end,
35-
["check_etag('" ++ ETag ++ "');"].
36-
3728
set_oauth_settings(AuthSettings) ->
3829
JsonAuthSettings = rabbit_json:encode(rabbit_mgmt_format:format_nulls(AuthSettings)),
3930
["set_oauth_settings(", JsonAuthSettings, ");"].
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
%% This Source Code Form is subject to the terms of the Mozilla Public
2+
%% License, v. 2.0. If a copy of the MPL was not distributed with this
3+
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
%%
5+
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
6+
%%
7+
8+
-module(rabbit_mgmt_wm_version).
9+
10+
-export([init/2]).
11+
-export([to_json/2, content_types_provided/2]).
12+
-export([variances/2]).
13+
14+
-include_lib("rabbit_common/include/rabbit.hrl").
15+
-include_lib("rabbitmq_management_agent/include/rabbit_mgmt_records.hrl").
16+
17+
%%--------------------------------------------------------------------
18+
19+
init(Req, _State) ->
20+
{cowboy_rest, rabbit_mgmt_headers:set_no_cache_headers(
21+
rabbit_mgmt_headers:set_common_permission_headers(Req, ?MODULE), ?MODULE),
22+
#context{}}.
23+
24+
variances(Req, Context) ->
25+
{[<<"accept-encoding">>, <<"origin">>], Req, Context}.
26+
27+
content_types_provided(ReqData, Context) ->
28+
{rabbit_mgmt_util:responder_map(to_json), ReqData, Context}.
29+
30+
to_json(ReqData, Context) ->
31+
Version = case rabbit:product_version() of
32+
undefined -> rabbit:base_product_version();
33+
V -> V
34+
end,
35+
rabbit_mgmt_util:reply(list_to_binary(Version), ReqData, Context).
36+
37+
%%--------------------------------------------------------------------
38+

0 commit comments

Comments
 (0)