Skip to content
Snippets Groups Projects
Commit 15e2ef71 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Add image property name checks in add_property

When adding a new image property, check if the property already exists
or if it contains invalid characters.
parent 2005768d
No related branches found
No related tags found
No related merge requests found
...@@ -41,6 +41,7 @@ import os ...@@ -41,6 +41,7 @@ import os
import textwrap import textwrap
import StringIO import StringIO
import json import json
import re
from image_creator import __version__ as version from image_creator import __version__ as version
from image_creator.util import MD5, FatalError from image_creator.util import MD5, FatalError
...@@ -471,9 +472,11 @@ def add_property(session): ...@@ -471,9 +472,11 @@ def add_property(session):
"""Add a new property to the image""" """Add a new property to the image"""
d = session['dialog'] d = session['dialog']
regexp = re.compile('^[A-Za-z_]+$')
while 1: while 1:
(code, answer) = d.inputbox("Please provide a name for a new image" (code, answer) = d.inputbox("Please provide a case-insensitive name "
" property:", width=WIDTH) "for a new image property:", width=WIDTH)
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
return False return False
...@@ -482,11 +485,22 @@ def add_property(session): ...@@ -482,11 +485,22 @@ def add_property(session):
d.msgbox("A property name cannot be empty", width=SMALL_WIDTH) d.msgbox("A property name cannot be empty", width=SMALL_WIDTH)
continue continue
if not re.match(regexp, name):
d.msgbox("Allowed characters for name: [a-zA-Z0-9_]", width=WIDTH)
continue
# Image properties are case-insensitive
name = name.upper()
if name in session['metadata']:
d.msgbox("Image property: `%s' already exists" % name, width=WIDTH)
continue
break break
while 1: while 1:
(code, answer) = d.inputbox("Please provide a value for image " (code, answer) = d.inputbox("Please provide a value for image "
"property %s" % name, width=WIDTH) "property: `%s'" % name, width=WIDTH)
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
return False return False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment