Skip to content

Commit c14c8b3

Browse files
dandyecopybara-github
authored andcommitted
Enable setting of data RBAC scope_info for ref list
PiperOrigin-RevId: 676424265
1 parent d847461 commit c14c8b3

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lists/v1alpha/patch_list.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def patch_list(
9191
content_lines: Sequence[str],
9292
syntax_type: Optional[str] = None,
9393
description: Optional[str] = None,
94+
scope_name: Optional[str] = None,
9495
) -> Dict[str, Any]:
9596
"""Updates a Reference List.
9697
@@ -107,6 +108,7 @@ def patch_list(
107108
content_lines: Array containing each line of the list's content.
108109
syntax_type: (Optional) List content type; how to interpret this list.
109110
description: (Optional) Description of the list.
111+
scope_name: (Optional) Data RBAC scope name.
110112
Returns:
111113
Dictionary representation of the updated Reference List.
112114
@@ -118,20 +120,30 @@ def patch_list(
118120
CHRONICLE_API_BASE_URL,
119121
proj_region
120122
)
123+
121124
# pylint: disable-next=line-too-long
122125
parent = f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}"
123126
url = f"{base_url_with_region}/v1alpha/{parent}/referenceLists/{name}"
124127
body = {
125128
"entries": [{"value": line.strip()} for line in content_lines],
126-
"scope_info": None, # assumes Data RBAC is disabled
127129
}
130+
if scope_name:
131+
body["scope_info"] = {
132+
"referenceListScope": {
133+
"scopeNames": [
134+
f"projects/{proj_id}/locations/{proj_region}/instances/{proj_instance}/dataAccessScopes/{scope_name}"
135+
]
136+
}
137+
}
138+
else:
139+
body["scope_info"] = None # does *not* remove scope_info
128140
if description:
129141
body["description"] = description
130142
if syntax_type:
131143
body["syntax_type"] = syntax_type
144+
132145
params = {"updateMask": ",".join(body.keys())}
133146
body["name"] = name
134-
135147
response = http_session.request("PATCH", url, params=params, json=body)
136148
if response.status_code >= 400:
137149
print(response.text)
@@ -156,6 +168,9 @@ def parse_arguments():
156168
help="path of a file containing the list content")
157169
parser.add_argument("-d", "--description", type=str,
158170
help="description of the list")
171+
parser.add_argument(
172+
"-s", "--scope_name", type=str, help="data RBAC scope name for the list"
173+
)
159174
parser.add_argument("-t", "--syntax_type", type=str, default=None,
160175
choices=SYNTAX_TYPE_ENUM,
161176
help="syntax type of the list, used for validation")
@@ -248,6 +263,7 @@ def main():
248263
content_lines,
249264
args.syntax_type,
250265
args.description,
266+
args.scope_name,
251267
)
252268
updated_list, ts = get_current_state(auth_session, args)
253269
# no need to compare sets if updated ts matches

0 commit comments

Comments
 (0)