Skip to content

Commit 57637bf

Browse files
committed
MB-46881: Audit for updating scope limits
Change-Id: I640d0b29128f29d3e2476039de128bf02282acd7 Reviewed-on: http://review.couchbase.org/c/ns_server/+/159833 Tested-by: Abhijeeth Nuthan <[email protected]> Well-Formed: Build Bot <[email protected]> Reviewed-by: Artem Stemkovski <[email protected]>
1 parent 9d9b768 commit 57637bf

File tree

4 files changed

+62
-11
lines changed

4 files changed

+62
-11
lines changed

etc/audit_descriptor.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,7 @@
11861186
"new_manifest_uid" : ""
11871187
},
11881188
"optional_fields" : {
1189+
"limits" : "",
11891190
"sessionid" : ""
11901191
}
11911192
},
@@ -1341,7 +1342,27 @@
13411342
"optional_fields" : {
13421343
"sessionid" : ""
13431344
}
1345+
},
1346+
{
1347+
"id" : 8268,
1348+
"name" : "update scope",
1349+
"description" : "Scope properties were updated",
1350+
"sync" : false,
1351+
"enabled" : true,
1352+
"filtering_permitted" : false,
1353+
"mandatory_fields" : {
1354+
"timestamp" : "",
1355+
"real_userid" : {"domain" : "", "user" : ""},
1356+
"remote" : {"ip" : "", "port" : 1},
1357+
"local" : {"ip" : "", "port" : 1},
1358+
"bucket_name" : "",
1359+
"scope_name" : "",
1360+
"new_manifest_uid" : ""
1361+
},
1362+
"optional_fields" : {
1363+
"limits" : "",
1364+
"sessionid" : ""
1365+
}
13441366
}
1345-
13461367
]
13471368
}

src/collections.erl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
get_scopes/1,
5353
get_collections/1,
5454
diff_manifests/2,
55+
jsonify_limits/1,
5556
last_seen_ids_key/2,
5657
last_seen_ids_set/3]).
5758

@@ -232,6 +233,9 @@ manifest_json(Identity, Bucket, Snapshot) ->
232233
Manifest),
233234
jsonify_manifest(FilteredManifest, true).
234235

236+
jsonify_limits(Limits) ->
237+
{[{S, {L}} || {S, L} <- Limits]}.
238+
235239
jsonify_manifest(Manifest, WithDefaults) ->
236240
ScopesJson =
237241
lists:map(
@@ -240,8 +244,7 @@ jsonify_manifest(Manifest, WithDefaults) ->
240244
[] ->
241245
[];
242246
Limits ->
243-
[{limits,
244-
{[{S, {L}} || {S, L} <- Limits]}}]
247+
[{limits, jsonify_limits(Limits)}]
245248
end,
246249
{[{name, list_to_binary(ScopeName)},
247250
{uid, uid(Scope)},

src/menelaus_web_collections.erl

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ handle_get(Bucket, Req) ->
3131
Req, collections:manifest_json(menelaus_auth:get_identity(Req),
3232
Bucket, direct)).
3333

34+
get_scope_audit_props(Limits) ->
35+
Limits1 = case Limits of
36+
no_limits ->
37+
[];
38+
_ ->
39+
Limits
40+
end,
41+
LimitsJson = ejson:encode(collections:jsonify_limits(Limits1)),
42+
[{limits, LimitsJson}].
43+
3444
handle_post_scope(Bucket, Req) ->
3545
assert_api_available(Bucket),
3646

@@ -41,11 +51,17 @@ handle_post_scope(Bucket, Req) ->
4151
RV = collections:create_scope(Bucket, Name, Limits),
4252
case {RV, Limits} of
4353
{{scope_already_exists, _}, L} when L =/= no_limits ->
44-
RV1 = collections:update_limits(Bucket, Name, Limits),
45-
handle_rv(RV1, Req);
54+
Ret = collections:update_limits(Bucket, Name, Limits),
55+
maybe_audit(Ret, Req,
56+
ns_audit:update_scope(
57+
_, Bucket, Name,
58+
get_scope_audit_props(Limits), _)),
59+
handle_rv(Ret, Req);
4660
_ ->
4761
maybe_audit(RV, Req,
48-
ns_audit:create_scope(_, Bucket, Name, _)),
62+
ns_audit:create_scope(
63+
_, Bucket, Name,
64+
get_scope_audit_props(Limits), _)),
4965
handle_rv(RV, Req)
5066
end
5167
end, Req, form,

src/ns_audit.erl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
modify_bucket/4,
3232
delete_bucket/2,
3333
flush_bucket/2,
34-
create_scope/4,
34+
create_scope/5,
35+
update_scope/5,
3536
drop_scope/4,
3637
create_collection/5,
3738
drop_collection/5,
@@ -370,7 +371,9 @@ code(rbac_info_retrieved) ->
370371
code(admin_password_reset) ->
371372
8266;
372373
code(modify_analytics_settings) ->
373-
8267.
374+
8267;
375+
code(update_scope) ->
376+
8268.
374377

375378
to_binary({list, List}) ->
376379
[to_binary(A) || A <- List];
@@ -885,10 +888,18 @@ failover_settings(Req, Settings) ->
885888
put(failover_settings, Req,
886889
[{settings, {prepare_list(Settings1)}}]).
887890

888-
create_scope(Req, BucketName, ScopeName, Uid) ->
891+
get_scope_params(BucketName, ScopeName, Props, Uid) ->
892+
[{bucket_name, BucketName},
893+
{scope_name, ScopeName},
894+
{new_manifest_uid, Uid}] ++ Props.
895+
896+
update_scope(Req, BucketName, ScopeName, Props, Uid) ->
897+
put(update_scope, Req,
898+
get_scope_params(BucketName, ScopeName, Props, Uid)).
899+
900+
create_scope(Req, BucketName, ScopeName, Props, Uid) ->
889901
put(create_scope, Req,
890-
[{bucket_name, BucketName}, {scope_name, ScopeName},
891-
{new_manifest_uid, Uid}]).
902+
get_scope_params(BucketName, ScopeName, Props, Uid)).
892903

893904
drop_scope(Req, BucketName, ScopeName, Uid) ->
894905
put(drop_scope, Req,

0 commit comments

Comments
 (0)