初始化scm实例的公共函数 :return: 返回一个新的scm实例
(self)
| 42 | self._scm_client = self.__init_scm_client() |
| 43 | |
| 44 | def __init_scm_client(self): |
| 45 | """ |
| 46 | 初始化scm实例的公共函数 |
| 47 | :return: 返回一个新的scm实例 |
| 48 | """ |
| 49 | if self._print_enable: |
| 50 | stdout_filepath = None |
| 51 | stderr_filepath = None |
| 52 | else: |
| 53 | stdout_filepath = "cmdgit_stdout.log" |
| 54 | stderr_filepath = "cmdgit_stderr.log" |
| 55 | |
| 56 | if self._scm_auth_info: # 使用传递的鉴权方式 |
| 57 | self._ssh_file = self.__get_ssh_file() |
| 58 | if self._ssh_file: # 使用ssh方式 |
| 59 | scm_client = ScmClient( |
| 60 | self._scm_type, |
| 61 | self._scm_url, |
| 62 | self._dest_dir, |
| 63 | ssh_file=self._ssh_file, |
| 64 | print_enable=self._print_enable, |
| 65 | stdout_filepath=stdout_filepath, |
| 66 | stderr_filepath=stderr_filepath |
| 67 | ) |
| 68 | else: # 使用账号密码/oauth方式 |
| 69 | password = Crypto(settings.PASSWORD_KEY).decrypt( |
| 70 | self._scm_auth_info["scm_password"]) |
| 71 | scm_client = ScmClient( |
| 72 | self._scm_type, |
| 73 | self._scm_url, |
| 74 | self._dest_dir, |
| 75 | self._scm_auth_info["scm_username"], |
| 76 | password, |
| 77 | print_enable=self._print_enable, |
| 78 | stdout_filepath=stdout_filepath, |
| 79 | stderr_filepath=stderr_filepath |
| 80 | ) |
| 81 | else: |
| 82 | if settings.TOOL_LOAD_ACCOUNT["USERNAME"] and settings.TOOL_LOAD_ACCOUNT["PASSWORD"]: |
| 83 | username = settings.TOOL_LOAD_ACCOUNT["USERNAME"] |
| 84 | password = settings.TOOL_LOAD_ACCOUNT["PASSWORD"] |
| 85 | else: |
| 86 | username = "" |
| 87 | password = "" |
| 88 | # raise NodeError(code=E_NODE_TASK_SCM_FAILED, msg="请先在config.ini中配置TOOL_LOAD_ACCOUNT信息") |
| 89 | scm_client = ScmClient( |
| 90 | scm_type="git", |
| 91 | scm_url=self._scm_url, |
| 92 | source_dir=self._dest_dir, |
| 93 | scm_username=username, |
| 94 | scm_password=password, |
| 95 | print_enable=self._print_enable, |
| 96 | stdout_filepath=stdout_filepath, |
| 97 | stderr_filepath=stderr_filepath |
| 98 | ) |
| 99 | return scm_client |
| 100 | |
| 101 | def __get_ssh_file(self): |
no test coverage detected