Skip to content

Commit

Permalink
Merge pull request #40 from BigNuoLi/master
Browse files Browse the repository at this point in the history
show Job name when checking infrabox.json format failed
  • Loading branch information
meranos authored Aug 26, 2020
2 parents ceaf9f7 + 59e79dc commit d345aac
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ ENV/

# exuberant ctags
tags

.vscode

5 changes: 4 additions & 1 deletion infraboxcli/job_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def load_infrabox_file(path):
data = json.load(f)
except ValueError:
f.seek(0)
data = yaml.load(f)
if (sys.version_info.major == 2) or (yaml.__version__ < "5.1"):
data = yaml.load(f)
else:
data = yaml.load(f, Loader=yaml.FullLoader)
validate_json(data)
return data

Expand Down
5 changes: 4 additions & 1 deletion infraboxcli/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def validate_infrabox_file(args):
data = json.load(f)
except ValueError:
f.seek(0)
data = yaml.load(f)
if (sys.version_info.major == 2) or (yaml.__version__ < "5.1"):
data = yaml.load(f)
else:
data = yaml.load(f, Loader=yaml.FullLoader)
validate_json(data)

def validate(args):
Expand Down
30 changes: 24 additions & 6 deletions infraboxcli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,36 @@ def print_cluster(name, cluster, indent=' '):
label=cluster['name'].split('/')[-1],
indent=indent))
elif len(cluster) == 1:
for inner_name, inner_cluster in cluster.iteritems():
print_cluster(inner_name, inner_cluster, indent)
if (sys.version_info.major == 2):
for inner_name, inner_cluster in cluster.iteritems():
print_cluster(inner_name, inner_cluster, indent)
elif (sys.version_info.major == 3):
for inner_name, inner_cluster in cluster.items():
print_cluster(inner_name, inner_cluster, indent)
else:
raise Exception('Unsupport python version')
else:
print('{indent}subgraph "cluster_{name}" {{'.format(name=name, indent=indent))

for inner_name, inner_cluster in cluster.iteritems():
print_cluster(inner_name, inner_cluster, indent + ' ')
if (sys.version_info.major == 2):
for inner_name, inner_cluster in cluster.iteritems():
print_cluster(inner_name, inner_cluster, indent + ' ')
elif (sys.version_info.major == 3):
for inner_name, inner_cluster in cluster.items():
print_cluster(inner_name, inner_cluster, indent + ' ')
else:
raise Exception('Unsupport python version')

print('{indent}}}'.format(indent=indent))

for name, cluster in index.iteritems():
print_cluster(name, cluster)
if (sys.version_info.major == 2):
for name, cluster in index.iteritems():
print_cluster(name, cluster)
elif (sys.version_info.major == 3):
for name, cluster in index.items():
print_cluster(name, cluster)
else:
raise Exception('Unsupport python version')

for j in self.jobs:
name = j['name']
Expand Down
22 changes: 19 additions & 3 deletions pyinfrabox/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,29 @@ def check_text(t, path, allowEmpty=False):
if not allowEmpty and not t:
raise ValidationError(path, "empty string not allowed")


def check_allowed_properties(d, path, allowed):
if not isinstance(d, dict):
raise ValidationError(path, "must be an object")

for key in d:
if key not in allowed:
raise ValidationError(path, "invalid property '%s'" % key)
if 'name' in d.keys():
raise ValidationError('%s(%s)' % (path, d['name']), "invalid property '%s'" % key)
else:
raise ValidationError(path, "invalid property '%s'" % key)


def check_required_properties(d, path, required):
if not isinstance(d, dict):
raise ValidationError(path, "must be an object")

for key in required:
if key not in d:
raise ValidationError(path, "property '%s' is required" % key)
if 'name' in d.keys():
raise ValidationError('%s(%s)' % (path, d['name']), "property '%s' is required" % key)
else:
raise ValidationError(path, "property '%s' is required" % key)

def check_string_array(e, path):
if not isinstance(e, list):
Expand All @@ -50,33 +58,41 @@ def check_string_array(e, path):
path = "%s[%s]" % (path, i)
check_text(elem, path)


def check_boolean(d, path):
if not isinstance(d, bool):
raise ValidationError(path, "must be a boolean")


def check_number(d, path):
if not isinstance(d, int):
raise ValidationError(path, "must be a integer")


def check_int_or_float(d, path):
if not isinstance(d, float) and not isinstance(d, int):
raise ValidationError(path, "must be a float")


def check_color(d, path):
if d not in ("red", "green", "blue", "yellow", "orange", "white", "black", "grey"):
if d not in ("red", "green", "blue", "yellow", "orange", "white", "black",
"grey"):
raise ValidationError(path, "not a valid value")


def get_remote_url(url):
parsed_url = urlparse(url)
return parsed_url.scheme + '://' + parsed_url.netloc


def validate_url(url):
try:
result = urlparse(url)
return result.scheme and result.netloc
except:
return False


def validate_uuid(uuid_string):
try:
val = uuid.UUID(uuid_string)
Expand Down

0 comments on commit d345aac

Please sign in to comment.