jmeter - 如何在 JMeter 中使用 JGit 添加 ssh 密钥
问题描述
我正在尝试使用 JMeter 在 Bitbucket 服务器上进行负载测试。我提到了这个链接Jmeter and Bitbucket server load testing,但我不确定如何在 JMeter 的 JSR223 Sampler 中使用 JGit 传递 ssh-key 详细信息。
谢谢您的帮助!
解决方案
JGit 使用JSch库通过 SSH 通道进行 Git 连接,因此您需要调用JSch.addIdentity() 函数并提供您的私钥/公钥/密码的路径。
示例代码:
import com.jcraft.jsch.JSch
import com.jcraft.jsch.JSchException
import com.jcraft.jsch.Session
import org.eclipse.jgit.api.CloneCommand
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.TransportConfigCallback
import org.eclipse.jgit.transport.*
import org.eclipse.jgit.util.FS
CloneCommand cloneCommand = Git.cloneRepository()
cloneCommand.setURI("your Git SSH URL")
cloneCommand.setDirectory(new File('/path/to/local/folder'))
SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException {
JSch defaultJSch = super.createDefaultJSch(fs);
defaultJSch.addIdentity("/path/to/your/private/key");
return defaultJSch;
}
@Override
protected void configure(OpenSshConfig.Host host, Session session) {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sshSessionFactory);
}
}
cloneCommand.setTransportConfigCallback(new TransportConfigCallback() {
@Override
void configure(Transport transport) {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sshSessionFactory);
}
})
cloneCommand.call()
更多信息:
推荐阅读
- python - 你如何使用从`ImageFont.getmask`返回的`Image.core`?
- .net - 从当前正在构建的程序集中检索使用 GenericTypeParameterBuilder 类型的函数(委托)类型
- arrays - 创建一个函数,在数组中查找基于 Lat long 的最近对象
- python - 检查字符串是否包含特定的特殊字符、字母数字字符并以字母结尾
- django - 什么时候应该使用 POST 方法而不是 GET 方法来从表单提交数据?
- angular - WebEx JS 集成不显示来自主机的视频
- laravel - Laravel 项目 - 更新 .vue 文件时,更改不会实时显示
- visio - Visio 组织结构图 - 格式和数字通过
- python - 如何设置 QCheckBox 指标的拉伸因子?
- unit-testing - 如何为 Spring Boot 单元测试排除 Spring Security