From: tierno Date: Tue, 4 Aug 2020 12:48:15 +0000 (+0000) Subject: enhanced role permission validation X-Git-Tag: release-v9.0-start~24 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=commitdiff_plain;h=97639b4032606caf5909e20dc6da20a9b18a137d;hp=ee00275276c75cb1737539b48db33952177ec777 enhanced role permission validation this commit avoid incompleted permission keys. For example command: osm role-update --add "vim_accoun: true" must fais, as it should be "vim_accounts: true" Change-Id: Ib5a5d88ae35120e99a43c80d20ccf8b207701780 Signed-off-by: tierno --- diff --git a/osm_nbi/admin_topics.py b/osm_nbi/admin_topics.py index 998c12f..6e9f078 100644 --- a/osm_nbi/admin_topics.py +++ b/osm_nbi/admin_topics.py @@ -1078,9 +1078,9 @@ class RoleTopicAuth(BaseTopic): if role_def[-1] == ":": raise ValidationError("Operation cannot end with ':'") - role_def_matches = [op for op in operations if op.startswith(role_def)] + match = next((op for op in operations if op == role_def or op.startswith(role_def + ":")), None) - if len(role_def_matches) == 0: + if not match: raise ValidationError("Invalid permission '{}'".format(role_def)) def _validate_input_new(self, input, force=False):