示例#1
0
    def _prepareSshKeys(self, manager, temp_dir_path):
        key_path = None
        if self._sshKey is not None:
            ssh_key_data = yield manager.renderSecrets(self._sshKey)

            key_path = os.path.join(temp_dir_path, 'ssh-key')
            misc.writeLocalFile(key_path, ssh_key_data, mode=stat.S_IRUSR)

        known_hosts_path = None
        if self._sshHostKey is not None:
            ssh_host_key_data = yield manager.renderSecrets(self._sshHostKey)
            ssh_host_key_data = getSshKnownHostsContents(ssh_host_key_data)

            known_hosts_path = os.path.join(temp_dir_path, 'ssh-known-hosts')
            misc.writeLocalFile(known_hosts_path, ssh_host_key_data)

        defer.returnValue((key_path, known_hosts_path))
示例#2
0
文件: git.py 项目: vvscloud/buildbot
    def _downloadSshPrivateKeyIfNeeded(self):
        if self.sshPrivateKey is None:
            defer.returnValue(RC_SUCCESS)

        p = Properties()
        p.master = self.master
        private_key = yield p.render(self.sshPrivateKey)
        host_key = yield p.render(self.sshHostKey)

        # not using self.workdir because it may be changed depending on step
        # options
        workdir = self._getSshDataWorkDir()

        rel_key_path = self.build.path_module.relpath(
                self._getSshPrivateKeyPath(), workdir)
        rel_host_key_path = self.build.path_module.relpath(
                self._getSshHostKeyPath(), workdir)
        rel_wrapper_script_path = self.build.path_module.relpath(
                self._getSshWrapperScriptPath(), workdir)

        yield self.runMkdir(self._getSshDataPath())

        if not self.supportsSshPrivateKeyAsEnvOption:
            yield self.downloadFileContentToWorker(rel_wrapper_script_path,
                                                   self._getSshWrapperScript(),
                                                   workdir=workdir, mode=0o700)

        yield self.downloadFileContentToWorker(rel_key_path, private_key,
                                               workdir=workdir, mode=0o400)

        if self.sshHostKey is not None:
            known_hosts_contents = getSshKnownHostsContents(host_key)
            yield self.downloadFileContentToWorker(rel_host_key_path,
                                                   known_hosts_contents,
                                                   workdir=workdir, mode=0o400)

        self.didDownloadSshPrivateKey = True
        defer.returnValue(RC_SUCCESS)
示例#3
0
    def test(self):
        key = 'ssh-rsa AAAA<...>WsHQ=='

        expected = '* ssh-rsa AAAA<...>WsHQ=='
        self.assertEqual(expected, getSshKnownHostsContents(key))
示例#4
0
 def _downloadSshKnownHosts(self, path):
     writeLocalFile(path, getSshKnownHostsContents(self.sshHostKey))
示例#5
0
 def _downloadSshKnownHosts(self, path):
     if self.sshKnownHosts is not None:
         contents = self.sshKnownHosts
     else:
         contents = getSshKnownHostsContents(self.sshHostKey)
     writeLocalFile(path, contents)
示例#6
0
    def test(self):
        key = 'ssh-rsa AAAA<...>WsHQ=='

        expected = '* ssh-rsa AAAA<...>WsHQ=='
        self.assertEqual(expected, getSshKnownHostsContents(key))
示例#7
0
 def _downloadSshKnownHosts(self, path):
     if self.sshKnownHosts is not None:
         contents = self.sshKnownHosts
     else:
         contents = getSshKnownHostsContents(self.sshHostKey)
     writeLocalFile(path, contents)
示例#8
0
 def _downloadSshKnownHosts(self, path):
     writeLocalFile(path, getSshKnownHostsContents(self.sshHostKey))