@@ 1049-1137 (lines=89) @@ | ||
1046 | preferences=preferences, |
|
1047 | ) |
|
1048 | ||
1049 | def modify_permission( |
|
1050 | self, |
|
1051 | permission_id: str, |
|
1052 | *, |
|
1053 | comment: Optional[str] = None, |
|
1054 | name: Optional[str] = None, |
|
1055 | resource_id: Optional[str] = None, |
|
1056 | resource_type: Optional[EntityType] = None, |
|
1057 | subject_id: Optional[str] = None, |
|
1058 | subject_type: Optional[PermissionSubjectType] = None, |
|
1059 | ) -> Any: |
|
1060 | """Modifies an existing permission. |
|
1061 | ||
1062 | Arguments: |
|
1063 | permission_id: UUID of permission to be modified. |
|
1064 | comment: The comment on the permission. |
|
1065 | name: Permission name, currently the name of a command. |
|
1066 | subject_id: UUID of subject to whom the permission is granted |
|
1067 | subject_type: Type of the subject user, group or role |
|
1068 | resource_id: UUID of entity to which the permission applies |
|
1069 | resource_type: Type of the resource. For Super permissions user, |
|
1070 | group or role |
|
1071 | ||
1072 | Returns: |
|
1073 | The response. See :py:meth:`send_command` for details. |
|
1074 | """ |
|
1075 | if not permission_id: |
|
1076 | raise RequiredArgument( |
|
1077 | function=self.modify_permission.__name__, |
|
1078 | argument='permission_id', |
|
1079 | ) |
|
1080 | ||
1081 | cmd = XmlCommand("modify_permission") |
|
1082 | cmd.set_attribute("permission_id", permission_id) |
|
1083 | ||
1084 | if comment: |
|
1085 | cmd.add_element("comment", comment) |
|
1086 | ||
1087 | if name: |
|
1088 | cmd.add_element("name", name) |
|
1089 | ||
1090 | if resource_id or resource_type: |
|
1091 | if not resource_id: |
|
1092 | raise RequiredArgument( |
|
1093 | function=self.modify_permission.__name__, |
|
1094 | argument='resource_id', |
|
1095 | ) |
|
1096 | ||
1097 | if not resource_type: |
|
1098 | raise RequiredArgument( |
|
1099 | function=self.modify_permission.__name__, |
|
1100 | argument='resource_type', |
|
1101 | ) |
|
1102 | ||
1103 | if not isinstance(resource_type, self.types.EntityType): |
|
1104 | raise InvalidArgumentType( |
|
1105 | function=self.modify_permission.__name__, |
|
1106 | argument='resource_type', |
|
1107 | arg_type=self.types.EntityType.__name__, |
|
1108 | ) |
|
1109 | ||
1110 | _xmlresource = cmd.add_element( |
|
1111 | "resource", attrs={"id": resource_id} |
|
1112 | ) |
|
1113 | _actual_resource_type = resource_type |
|
1114 | if resource_type.value == EntityType.AUDIT.value: |
|
1115 | _actual_resource_type = EntityType.TASK |
|
1116 | elif resource_type.value == EntityType.POLICY.value: |
|
1117 | _actual_resource_type = EntityType.SCAN_CONFIG |
|
1118 | _xmlresource.add_element("type", _actual_resource_type.value) |
|
1119 | ||
1120 | if subject_id or subject_type: |
|
1121 | if not subject_id: |
|
1122 | raise RequiredArgument( |
|
1123 | function=self.modify_permission.__name__, |
|
1124 | argument='subject_id', |
|
1125 | ) |
|
1126 | ||
1127 | if not isinstance(subject_type, PermissionSubjectType): |
|
1128 | raise InvalidArgumentType( |
|
1129 | function=self.modify_permission.__name__, |
|
1130 | argument='subject_type', |
|
1131 | arg_type=PermissionSubjectType.__name__, |
|
1132 | ) |
|
1133 | ||
1134 | _xmlsubject = cmd.add_element("subject", attrs={"id": subject_id}) |
|
1135 | _xmlsubject.add_element("type", subject_type.value) |
|
1136 | ||
1137 | return self._send_xml_command(cmd) |
|
1138 | ||
1139 | def modify_policy_set_nvt_preference( |
|
1140 | self, |
@@ 1170-1258 (lines=89) @@ | ||
1167 | preferences=preferences, |
|
1168 | ) |
|
1169 | ||
1170 | def modify_permission( |
|
1171 | self, |
|
1172 | permission_id: str, |
|
1173 | *, |
|
1174 | comment: Optional[str] = None, |
|
1175 | name: Optional[str] = None, |
|
1176 | resource_id: Optional[str] = None, |
|
1177 | resource_type: Optional[EntityType] = None, |
|
1178 | subject_id: Optional[str] = None, |
|
1179 | subject_type: Optional[PermissionSubjectType] = None, |
|
1180 | ) -> Any: |
|
1181 | """Modifies an existing permission. |
|
1182 | ||
1183 | Arguments: |
|
1184 | permission_id: UUID of permission to be modified. |
|
1185 | comment: The comment on the permission. |
|
1186 | name: Permission name, currently the name of a command. |
|
1187 | subject_id: UUID of subject to whom the permission is granted |
|
1188 | subject_type: Type of the subject user, group or role |
|
1189 | resource_id: UUID of entity to which the permission applies |
|
1190 | resource_type: Type of the resource. For Super permissions user, |
|
1191 | group or role |
|
1192 | ||
1193 | Returns: |
|
1194 | The response. See :py:meth:`send_command` for details. |
|
1195 | """ |
|
1196 | if not permission_id: |
|
1197 | raise RequiredArgument( |
|
1198 | function=self.modify_permission.__name__, |
|
1199 | argument='permission_id', |
|
1200 | ) |
|
1201 | ||
1202 | cmd = XmlCommand("modify_permission") |
|
1203 | cmd.set_attribute("permission_id", permission_id) |
|
1204 | ||
1205 | if comment: |
|
1206 | cmd.add_element("comment", comment) |
|
1207 | ||
1208 | if name: |
|
1209 | cmd.add_element("name", name) |
|
1210 | ||
1211 | if resource_id or resource_type: |
|
1212 | if not resource_id: |
|
1213 | raise RequiredArgument( |
|
1214 | function=self.modify_permission.__name__, |
|
1215 | argument='resource_id', |
|
1216 | ) |
|
1217 | ||
1218 | if not resource_type: |
|
1219 | raise RequiredArgument( |
|
1220 | function=self.modify_permission.__name__, |
|
1221 | argument='resource_type', |
|
1222 | ) |
|
1223 | ||
1224 | if not isinstance(resource_type, self.types.EntityType): |
|
1225 | raise InvalidArgumentType( |
|
1226 | function=self.modify_permission.__name__, |
|
1227 | argument='resource_type', |
|
1228 | arg_type=self.types.EntityType.__name__, |
|
1229 | ) |
|
1230 | ||
1231 | _xmlresource = cmd.add_element( |
|
1232 | "resource", attrs={"id": resource_id} |
|
1233 | ) |
|
1234 | _actual_resource_type = resource_type |
|
1235 | if resource_type.value == EntityType.AUDIT.value: |
|
1236 | _actual_resource_type = EntityType.TASK |
|
1237 | elif resource_type.value == EntityType.POLICY.value: |
|
1238 | _actual_resource_type = EntityType.SCAN_CONFIG |
|
1239 | _xmlresource.add_element("type", _actual_resource_type.value) |
|
1240 | ||
1241 | if subject_id or subject_type: |
|
1242 | if not subject_id: |
|
1243 | raise RequiredArgument( |
|
1244 | function=self.modify_permission.__name__, |
|
1245 | argument='subject_id', |
|
1246 | ) |
|
1247 | ||
1248 | if not isinstance(subject_type, PermissionSubjectType): |
|
1249 | raise InvalidArgumentType( |
|
1250 | function=self.modify_permission.__name__, |
|
1251 | argument='subject_type', |
|
1252 | arg_type=PermissionSubjectType.__name__, |
|
1253 | ) |
|
1254 | ||
1255 | _xmlsubject = cmd.add_element("subject", attrs={"id": subject_id}) |
|
1256 | _xmlsubject.add_element("type", subject_type.value) |
|
1257 | ||
1258 | return self._send_xml_command(cmd) |
|
1259 | ||
1260 | def modify_policy_set_nvt_preference( |
|
1261 | self, |