本办法是工厂方法,故意做成类是一个类来使用。 :param scm_type: svn, git :param scm_url: 源码路径 :param auth_type: str, 鉴权类型 :param username: str, 用户名 :param password: str, 凭证 :param ssh_key: str, SSH密钥 :param ssh_password: str,SSH密钥口令 :param scm_platform: int,代码库管理平台
(scm_type, scm_url, auth_type=None, username=None, password=None,
ssh_key=None, ssh_password=None, scm_platform=ScmPlatformEnum.GIT_OA, **kwargs)
| 19 | |
| 20 | |
| 21 | def ScmClient(scm_type, scm_url, auth_type=None, username=None, password=None, |
| 22 | ssh_key=None, ssh_password=None, scm_platform=ScmPlatformEnum.GIT_OA, **kwargs): |
| 23 | """本办法是工厂方法,故意做成类是一个类来使用。 |
| 24 | |
| 25 | :param scm_type: svn, git |
| 26 | :param scm_url: 源码路径 |
| 27 | :param auth_type: str, 鉴权类型 |
| 28 | :param username: str, 用户名 |
| 29 | :param password: str, 凭证 |
| 30 | :param ssh_key: str, SSH密钥 |
| 31 | :param ssh_password: str,SSH密钥口令 |
| 32 | :param scm_platform: int,代码库管理平台 |
| 33 | """ |
| 34 | if password: |
| 35 | password = decrypt(password, settings.PASSWORD_KEY) |
| 36 | if ssh_key: |
| 37 | ssh_key = decrypt(ssh_key, settings.PASSWORD_KEY) |
| 38 | if ssh_password: |
| 39 | ssh_password = decrypt(ssh_password, settings.PASSWORD_KEY) |
| 40 | if isinstance(scm_platform, str): |
| 41 | scm_platform_name = scm_platform |
| 42 | else: |
| 43 | scm_platform_name = SCM_PLATFORM_NUM_AS_KEY.get(scm_platform, "tgit") |
| 44 | if scm_type == "svn": |
| 45 | return ErrorCatcher(SvnRemoteClient(scm_url, username, password, ssh_key, ssh_password), |
| 46 | ScmErrorHandler.svn_error_handler) |
| 47 | elif scm_type == "git": |
| 48 | if auth_type == "oauth": |
| 49 | username = "oauth2" |
| 50 | return ErrorCatcher(GitRemoteClient(scm_url, username, password, ssh_key, ssh_password, scm_platform_name), |
| 51 | ScmErrorHandler.git_error_handler) |
| 52 | else: |
| 53 | raise Exception("not yet support scm_type: %s" % scm_type) |
no test coverage detected