Skip to content

Commit

Permalink
Improve error message for path
Browse files Browse the repository at this point in the history
  • Loading branch information
kghose committed Jul 21, 2020
1 parent 312aeb0 commit 9460bc1
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions sbpack/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from typing import Union
from copy import deepcopy
import json
import enum

from ruamel.yaml import YAML

Expand Down Expand Up @@ -278,13 +279,22 @@ def get_git_info(cwl_path: str) -> str:
return source_str


class AppIdCheck(enum.IntEnum):
VALID = 0
PATH_ERROR = 1
ILLEGAL_CHARACTERS = 2


def validate_id(app_id: str):
parts = app_id.split("/")
if len(parts) != 3:
return False
return AppIdCheck.PATH_ERROR

illegal = set(".!@#$%^&*()")
return not any((c in illegal) for c in parts[2])
if any((c in illegal) for c in parts[2]):
return AppIdCheck.ILLEGAL_CHARACTERS

return AppIdCheck.VALID


def print_usage():
Expand Down Expand Up @@ -333,8 +343,13 @@ def main():

profile, appid, cwl_path = sys.argv[1:]

if not validate_id(appid):
print("Illegal characters in app id")
app_id_check = validate_id(appid)
if app_id_check == AppIdCheck.ILLEGAL_CHARACTERS:
sys.stderr.write("Illegal characters in app id\n")
return

if app_id_check == AppIdCheck.PATH_ERROR:
sys.stderr.write("Incorrect path for app id\n")
return

cwl = pack(cwl_path)
Expand Down

0 comments on commit 9460bc1

Please sign in to comment.