提交 b38b120a 编写于 作者: C chenyanpan

user and password must be within the latin1 character set

https://gitee.com/chenyanpanHW/pkgmnt/issues/I1TC8R
上级 48b1d691
......@@ -44,15 +44,15 @@ def password_strength_check(password):
}
ret = password_strength_check(sys.argv[1])
if not ret['ok']:
print("Password strength is not satisfied.")
for item in ret['error']:
if ret['error'][item]:
print("{} not satisfied.".format(item))
def usage():
""" usage """
print(
"""
password strength require:
"""usage:
generate_password PASSWORD
PASSWORD must be within the latin1 character set
PASSWORD strength require:
6 characters or more
at least 1 digit [0-9]
at least 1 alphabet [a-z]
......@@ -60,5 +60,36 @@ password strength require:
at least 1 special character from [~!@#%^*_+=-]
"""
)
else:
print(generate_password_hash(sys.argv[1]))
def latin1_encode(text):
""" latin1 encode """
try:
text.encode("latin1")
except UnicodeEncodeError as err:
return str(err)
return None
if __name__ == "__main__":
if len(sys.argv) != 2:
usage()
sys.exit(1)
password_ = sys.argv[1]
err = latin1_encode(password_)
if err:
print("password: outside the 'latin-1' character set range")
sys.exit(1)
ret = password_strength_check(password_)
if not ret['ok']:
usage()
print("Password strength is not satisfied:")
for item in ret['error']:
if ret['error'][item]:
print("{} not satisfied.".format(item))
sys.exit(1)
else:
print(generate_password_hash(password_))
......@@ -112,6 +112,15 @@ def repo_branch_check(url):
return 'error', ret.text
def latin1_encode(text):
""" latin1 encode """
try:
text.encode("latin1")
except UnicodeEncodeError as err:
return str(err)
return None
def params_input_track(params, file_path=None):
"""
load tracking from command line arguments
......@@ -132,6 +141,13 @@ def params_input_track(params, file_path=None):
user = params['user']
password = params['password']
err = latin1_encode(user)
if err:
return "error", "user: outside the 'latin-1' character set range"
err = latin1_encode(password)
if err:
return "error", "password: outside the 'latin-1' character set range"
enabled = bool(enabled == 'true')
url = '/'.join(['https:/', server, 'tracking'])
......@@ -165,7 +181,11 @@ def check_add_param(params):
miss_params.append(param)
success = False
if not success:
print("patch_tracking_cli add: error: the following arguments are required: --{}".format(", --".join(miss_params)))
print(
"patch_tracking_cli add: error: the following arguments are required: --{}".format(
", --".join(miss_params)
)
)
return success
......@@ -215,6 +235,13 @@ def delete(args):
user = args.user
password = args.password
err = latin1_encode(user)
if err:
return "error", "user: outside the 'latin-1' character set range"
err = latin1_encode(password)
if err:
return "error", "password: outside the 'latin-1' character set range"
url = '/'.join(['https:/', server, 'tracking'])
if args.branch:
params = {'repo': args.repo, 'branch': args.branch}
......@@ -329,16 +356,14 @@ parser_add.add_argument('--file', help='import patch tracking from file')
parser_add.add_argument('--dir', help='import patch tracking from files in directory')
# delete
del_usage = """
%(prog)s --server SERVER --table TABLE --repo REPO [--branch BRANCH]"""
parser_delete = subparsers.add_parser('delete', parents=[common_parser, authentication_parser], help="delete tracking", allow_abbrev=False)
parser_delete = subparsers.add_parser(
'delete', parents=[common_parser, authentication_parser], help="delete tracking", allow_abbrev=False
)
parser_delete.set_defaults(func=delete)
parser_delete.add_argument("--repo", required=True, help="source package repository")
parser_delete.add_argument("--branch", help="source package branch")
# query
query_usage = """
%(prog)s --server SERVER --table {tracking,issue} [--repo REPO] [--branch BRANCH]"""
parser_query = subparsers.add_parser('query', parents=[common_parser], help="query tracking/issue", allow_abbrev=False)
parser_query.set_defaults(func=query)
parser_query.add_argument("--table", required=True, choices=["tracking", "issue"], help="query tracking or issue")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册