Skip to content

Commit fac3035

Browse files
Chronicle Teamcopybara-github
authored andcommitted
Removes the non-required subject type parameter from the UpdateSubject RPCs
PiperOrigin-RevId: 404431228
1 parent ff66fa4 commit fac3035

2 files changed

Lines changed: 5 additions & 34 deletions

File tree

access_control/update_subject.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,44 +42,28 @@ def initialize_command_line_args(
4242
regions.add_argument_region(parser)
4343
parser.add_argument(
4444
"-n", "--name", type=str, required=True, help="subject ID")
45-
parser.add_argument(
46-
"-t",
47-
"--type",
48-
type=str,
49-
required=True,
50-
help=("the subject's type (ANALYST or IDP_GROUP)"))
5145
parser.add_argument(
5246
"-rs",
5347
"--roles",
5448
type=str,
5549
required=True,
5650
help=("the role(s) the subject must have after the update"))
5751

58-
# Sanity checks for the command-line arguments.
59-
6052
# No need for a sanity check for the subject name and roles because these
6153
# arguments convert the provided input into strings and accept a wide range
6254
# of values. If the subject name isn't passed in, the error will be thrown
6355
# from the argparse library.
6456

65-
# Check the subject type.
66-
parsed_args = parser.parse_args(args)
67-
if parsed_args.type not in ("ANALYST", "IDP_GROUP"):
68-
print("Error: invalid subject type")
69-
return None
70-
7157
return parser.parse_args(args)
7258

7359

7460
def update_subject(http_session: requests.AuthorizedSession, name: str,
75-
subject_type: str,
7661
roles: Sequence[str]) -> Mapping[str, Sequence[Any]]:
7762
"""Updates information about a subject.
7863
7964
Args:
8065
http_session: Authorized session for HTTP requests.
8166
name: The ID of the subject to retrieve information about.
82-
subject_type: The subject's type (ANALYST or IDP_GROUP).
8367
roles: The role(s) the subject must have after the update.
8468
8569
Returns:
@@ -117,7 +101,6 @@ def update_subject(http_session: requests.AuthorizedSession, name: str,
117101
url = f"{CHRONICLE_API_BASE_URL}/v1/subjects/{name}"
118102
body = {
119103
"name": name,
120-
"type": subject_type,
121104
"roles": roles,
122105
}
123106
update_fields = ["subject.roles"]
@@ -139,5 +122,4 @@ def update_subject(http_session: requests.AuthorizedSession, name: str,
139122
session = chronicle_auth.initialize_http_session(cli.credentials_file)
140123
print(
141124
json.dumps(
142-
update_subject(session, cli.name, cli.type, cli.roles.split(",")),
143-
indent=2))
125+
update_subject(session, cli.name, cli.roles.split(",")), indent=2))

access_control/update_subject_test.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,11 @@ class UpdateSubjectTest(unittest.TestCase):
2828

2929
def test_initialize_command_line_args(self):
3030
actual = update_subject.initialize_command_line_args(
31-
["--name=test@test.com", "--type=ANALYST", "--roles="])
31+
["--name=test@test.com", "--roles="])
3232
self.assertEqual(
3333
actual,
3434
argparse.Namespace(
35-
credentials_file=None,
36-
name="test@test.com",
37-
type="ANALYST",
38-
roles="",
39-
region="us"))
40-
41-
def test_initialize_command_line_args_invalid_type(self):
42-
actual = update_subject.initialize_command_line_args(
43-
["--name=test@test.com", "--type=INVALID", "--roles="])
44-
self.assertIsNone(actual)
35+
credentials_file=None, name="test@test.com", roles="", region="us"))
4536

4637
@mock.patch.object(requests, "AuthorizedSession", autospec=True)
4738
@mock.patch.object(requests.requests, "Response", autospec=True)
@@ -52,15 +43,14 @@ def test_update_subject_error(self, mock_response, mock_session):
5243
requests.requests.exceptions.HTTPError())
5344

5445
with self.assertRaises(requests.requests.exceptions.HTTPError):
55-
update_subject.update_subject(mock_session, "", "", [])
46+
update_subject.update_subject(mock_session, "", [])
5647

5748
@mock.patch.object(requests, "AuthorizedSession", autospec=True)
5849
@mock.patch.object(requests.requests, "Response", autospec=True)
5950
def test_update_subject(self, mock_response, mock_session):
6051
mock_session.request.return_value = mock_response
6152
type(mock_response).status_code = mock.PropertyMock(return_value=200)
6253
subject_id = "test@test.com"
63-
subject_type = "ANALYST"
6454
roles = ["Test"]
6555
expected = {
6656
"subject": {
@@ -89,8 +79,7 @@ def test_update_subject(self, mock_response, mock_session):
8979
},
9080
}
9181
mock_response.json.return_value = expected
92-
actual = update_subject.update_subject(mock_session, subject_id,
93-
subject_type, roles)
82+
actual = update_subject.update_subject(mock_session, subject_id, roles)
9483
self.assertEqual(actual, expected)
9584

9685

0 commit comments

Comments
 (0)