From c5139d854e143fe0ec9620a581e0a46ee3b877d7 Mon Sep 17 00:00:00 2001 From: Idan Kinory Date: Sun, 10 Jun 2018 07:41:15 +0000 Subject: [PATCH] Template delete-validate uuid format check input for valid uuid format before query. Change-Id: I3e3f4d006381766f8882af1617038bd2e91dfbb5 --- vitrageclient/v1/cli/template.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/vitrageclient/v1/cli/template.py b/vitrageclient/v1/cli/template.py index cd7e6e9..5bb5f00 100644 --- a/vitrageclient/v1/cli/template.py +++ b/vitrageclient/v1/cli/template.py @@ -11,7 +11,9 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import re +import argparse from cliff import command from cliff import lister from cliff import show @@ -126,7 +128,10 @@ class TemplateDelete(command.Command): def get_parser(self, prog_name): parser = super(TemplateDelete, self).get_parser(prog_name) - parser.add_argument('uuid', help='ID of a template', nargs='+') + parser.add_argument('uuid', + help='ID of a template', + nargs='+', + type=TemplateDelete.vaild_uuid) return parser @property @@ -136,3 +141,13 @@ class TemplateDelete(command.Command): def take_action(self, parsed_args): uuid = parsed_args.uuid utils.get_client(self).template.delete(uuid=uuid) + + @staticmethod + def vaild_uuid(uuids): + rege = '^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$' + if type(uuids) != list: + uuids = [uuids] + for uuid in uuids: + if not re.match(rege, uuid): + raise argparse.ArgumentTypeError("Not a uuid format") + return uuids