Skip to content

Commit 1882fad

Browse files
MB-47613 [BP] Add buckets names and UUID to pools/default
backport of: http://review.couchbase.org/c/ns_server/+/156065 Change-Id: I3dfab227c1f054d3aad301a4a27b6800892a40e0 Reviewed-on: http://review.couchbase.org/c/ns_server/+/159447 Well-Formed: Restriction Checker Reviewed-by: Artem Stemkovski <[email protected]> Tested-by: Build Bot <[email protected]> Tested-by: <[email protected]>
1 parent cca34c6 commit 1882fad

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

src/menelaus_auth.erl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020

2121
-include("ns_common.hrl").
2222
-include("rbac.hrl").
23+
-include("cut.hrl").
2324

2425
-export([has_permission/2,
2526
is_internal/1,
27+
filter_accessible_buckets/3,
2628
get_accessible_buckets/2,
2729
extract_auth/1,
2830
extract_identity_from_cert/1,
@@ -46,6 +48,11 @@
4648

4749
%% External API
4850

51+
filter_accessible_buckets(Fun, Buckets, Req) ->
52+
Identity = get_identity(Req),
53+
Roles = menelaus_roles:get_compiled_roles(Identity),
54+
lists:filter(?cut(menelaus_roles:is_allowed(Fun(_), Roles)), Buckets).
55+
4956
-spec get_accessible_buckets(fun ((bucket_name()) -> rbac_permission()), mochiweb_request()) ->
5057
[bucket_name()].
5158
get_accessible_buckets(Fun, Req) ->

src/menelaus_web_pools.erl

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,29 @@ handle_pool_info(Id, Req) ->
102102
PassedETag = proplists:get_value("etag", Query),
103103
case WaitChangeS of
104104
undefined ->
105-
reply_json(Req, build_pool_info(Id, Req, normal, unstable,
106-
LocalAddr, undefined));
105+
reply_json(Req, pool_info(Id, Req, normal, unstable,
106+
LocalAddr, undefined));
107107
_ ->
108108
WaitChange = list_to_integer(WaitChangeS),
109109
menelaus_event:register_watcher(self()),
110110
erlang:send_after(WaitChange, self(), wait_expired),
111111
handle_pool_info_wait(Req, Id, LocalAddr, PassedETag, undefined)
112112
end.
113113

114+
pool_info(Id, Req, InfoLevel, Stability, LocalAddr, UpdateID) ->
115+
{struct,Info} = build_pool_info(Id, Req, InfoLevel, Stability,
116+
LocalAddr, UpdateID),
117+
Buckets = proplists:get_value(bucketNames, Info),
118+
FilteredBuckets = menelaus_auth:filter_accessible_buckets(
119+
fun ({struct, [{bucketName, B}, _UUID]}) ->
120+
{[{bucket, binary_to_list(B)}, settings], read}
121+
end,
122+
Buckets, Req),
123+
{struct, lists:keyreplace(bucketNames, 1, Info,
124+
{bucketNames, FilteredBuckets})}.
125+
114126
handle_pool_info_wait(Req, Id, LocalAddr, PassedETag, UpdateID) ->
115-
Info = build_pool_info(Id, Req, for_ui, stable, LocalAddr, UpdateID),
127+
Info = pool_info(Id, Req, for_ui, stable, LocalAddr, UpdateID),
116128
ETag = integer_to_list(erlang:phash2(Info)),
117129
if
118130
ETag =:= PassedETag ->
@@ -140,7 +152,7 @@ handle_pool_info_wait_tail(Req, Id, LocalAddr, ETag, UpdateID) ->
140152
%% consume all notifications
141153
LastID = menelaus_event:flush_watcher_notifications(UpdateID),
142154
%% and reply
143-
{struct, PList} = build_pool_info(Id, Req, for_ui, unstable, LocalAddr,
155+
{struct, PList} = pool_info(Id, Req, for_ui, unstable, LocalAddr,
144156
LastID),
145157
Info = {struct, [{etag, list_to_binary(ETag)} | PList]},
146158
reply_ok(Req, "application/json", encode_json(Info),
@@ -274,18 +286,21 @@ build_unstable_params(unstable, Config) ->
274286
ns_storage_conf:cluster_storage_info(Config)]}}].
275287

276288
build_buckets_info(Config, Id, UUID, Nodes) ->
289+
Buckets = ns_bucket:uuids(Config),
277290
BucketsVer =
278-
erlang:phash2(
279-
ns_bucket:get_bucket_names(ns_bucket:get_buckets(Config)))
291+
erlang:phash2(Buckets)
280292
bxor erlang:phash2(
281293
[{proplists:get_value(hostname, KV),
282294
proplists:get_value(status, KV)} || {struct, KV} <- Nodes]),
283-
{buckets, {struct,
284-
[{uri, bin_concat_path(["pools", Id, "buckets"],
285-
[{"v", BucketsVer},
286-
{"uuid", UUID}])},
287-
{terseBucketsBase, <<"/pools/default/b/">>},
288-
{terseStreamingBucketsBase, <<"/pools/default/bs/">>}]}}.
295+
[{buckets, {struct,
296+
[{uri, bin_concat_path(["pools", Id, "buckets"],
297+
[{"v", BucketsVer},
298+
{"uuid", UUID}])},
299+
{terseBucketsBase, <<"/pools/default/b/">>},
300+
{terseStreamingBucketsBase, <<"/pools/default/bs/">>}]}},
301+
{bucketNames, [{struct, [{bucketName, list_to_binary(BucketName)},
302+
{uuid, BucketUUID}]}
303+
|| {BucketName, BucketUUID} <- Buckets]}].
289304

290305
build_controller(Name, UUID) ->
291306
build_controller(Name, atom_to_list(Name), UUID).
@@ -346,7 +361,7 @@ build_one_alert({_Key, Msg, Time}) ->
346361
handle_pool_info_streaming(Id, Req) ->
347362
LocalAddr = local_addr(Req),
348363
F = fun(Stability, UpdateID) ->
349-
build_pool_info(Id, Req, normal, Stability, LocalAddr, UpdateID)
364+
pool_info(Id, Req, normal, Stability, LocalAddr, UpdateID)
350365
end,
351366
handle_streaming(F, Req).
352367

src/ns_bucket.erl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
get_bucket_names_of_type/2,
4343
get_buckets/0,
4444
get_buckets/1,
45+
uuids/1,
4546
is_persistent/1,
4647
is_ephemeral_bucket/1,
4748
is_valid_bucket_name/1,
@@ -825,6 +826,11 @@ bucket_uuid(Name, BucketConfigs) ->
825826
{ok, BucketConfig} = get_bucket_from_configs(Name, BucketConfigs),
826827
bucket_uuid(BucketConfig).
827828

829+
uuids(Config) ->
830+
BucketConfigs = get_buckets(Config),
831+
[{Name, bucket_uuid(Name, BucketConfigs)}
832+
|| Name <- get_bucket_names(BucketConfigs)].
833+
828834
filter_out_unknown_buckets(BucketsWithUUIDs, BucketConfigs) ->
829835
lists:filter(fun ({Name, UUID}) ->
830836
case get_bucket_from_configs(Name, BucketConfigs) of

0 commit comments

Comments
 (0)