forked from Tencent/CodeAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscmauthcheck.py
More file actions
64 lines (56 loc) · 2.44 KB
/
scmauthcheck.py
File metadata and controls
64 lines (56 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- encoding: utf-8 -*-
# Copyright (c) 2021-2025 Tencent
#
# This source code file is made available under MIT License
# See LICENSE for details
# ==============================================================================
"""
ScmAuthCheck
"""
from node.localtask.scmtoolcheck import ScmToolCheck
from util.cmdscm import ScmClient
from util.exceptions import NodeError
from util.errcode import E_NODE_TASK_CONFIG
class ScmAuthCheck(object):
def __init__(self, scm_info, scm_auth_info, source_dir):
self._scm_info = scm_info
self._source_dir = source_dir
self._ssh_file = scm_auth_info.ssh_file
self._scm_username = scm_auth_info.username
self._scm_password = scm_auth_info.password
def check_scm_authority(self):
"""
检查 username 和 password 权限
:return: True(有权限)|False(重新输入后仍无权限)
"""
# 先检查是否有安装svn|git命令行工具
ScmToolCheck.check_scm_cmd_tool(self._scm_info.scm_type)
# 2019-04-02 add
# 如果指定了本地代码目录,且是git类型,后续命令可以正常执行,可以不执行鉴权操作
# 原因:可能由于机器git配置问题,导致鉴权命令执行失败,但实际上执行其他git命令都是有权限的
if self._source_dir and self._scm_info.scm_type == "git":
return
# 校验账号密码是否有效
scm_auth = False
if self._ssh_file:
scm_client = ScmClient(
scm_type=self._scm_info.scm_type,
scm_url=self._scm_info.scm_url,
source_dir=self._source_dir,
ssh_file=self._ssh_file
)
else:
scm_client = ScmClient(
scm_type=self._scm_info.scm_type,
scm_url=self._scm_info.scm_url,
source_dir=self._source_dir,
scm_username=self._scm_username,
scm_password=self._scm_password)
if (self._scm_username and self._scm_password) or self._ssh_file:
# 有输入账号密码,或者指定了ssh_file时,验证账号权限是否有效
scm_auth = scm_client.check_auth()
else:
# 否则,验证缓存的账号权限是否有效
scm_auth = scm_client.check_auth_with_cache()
if not scm_auth:
raise NodeError(code=E_NODE_TASK_CONFIG, msg="未输入账号密码,或账号密码无权限!")