Browse Source

RemoteHost#remoteAgentConfig 的关系是 ManyToOne

reghao 2 months ago
parent
commit
be231ec084

+ 14 - 7
web/src/main/java/cn/reghao/bnt/web/devops/deployer/model/po/RemoteHost.java

@@ -4,10 +4,7 @@ import cn.reghao.bnt.web.devops.deployer.model.constant.SshAuthType;
 import cn.reghao.bnt.web.devops.deployer.model.dto.RemoteMachine;
 import cn.reghao.bnt.web.util.BaseEntity;
 import cn.reghao.jutil.jdk.web.result.NotAvailable;
-import jakarta.persistence.Column;
-import jakarta.persistence.Entity;
-import jakarta.persistence.OneToOne;
-import jakarta.persistence.Table;
+import jakarta.persistence.*;
 import jakarta.validation.constraints.NotBlank;
 import jakarta.validation.constraints.NotNull;
 import jakarta.validation.constraints.Size;
@@ -52,7 +49,7 @@ public class RemoteHost extends BaseEntity {
     @Size(max = 255, message = "最大长度不能超过 255 个字符")
     private String appVersion;
     @NotNull
-    @OneToOne
+    @ManyToOne
     private RemoteAgentConfig remoteAgentConfig;
 
     public RemoteHost() {
@@ -72,11 +69,21 @@ public class RemoteHost extends BaseEntity {
         this.remoteAgentConfig = remoteAgentConfig;
     }
 
-    public RemoteHost(String host, int port, String username, String password) {
+    public RemoteHost(String host, int port, String authType, String username, String password) {
         this.host = host;
         this.port = port;
-        this.authType = SshAuthType.password.name();
+        this.authType = authType;
         this.username = username;
         this.password = password;
+        this.appVersion = NotAvailable.na.getDesc();
+    }
+
+    public RemoteHost(String host, int port, String username, String privateKey) {
+        this.host = host;
+        this.port = port;
+        this.authType = SshAuthType.privateKey.name();
+        this.username = username;
+        this.privateKey = privateKey;
+        this.appVersion = NotAvailable.na.getDesc();
     }
 }

+ 2 - 1
web/src/test/java/devops/GitTest.java

@@ -3,6 +3,7 @@ package devops;
 import cn.reghao.bnt.web.devops.build.model.po.RepoAuthConfig;
 import cn.reghao.bnt.web.devops.builder.model.constant.RepoAuthType;
 import cn.reghao.bnt.web.devops.builder.tool.repo.GitImpl;
+import cn.reghao.bnt.web.devops.deployer.model.constant.SshAuthType;
 import cn.reghao.bnt.web.devops.deployer.model.po.RemoteHost;
 import cn.reghao.bnt.web.devops.deployer.util.Sftp;
 import cn.reghao.jutil.jdk.shell.ShellExecutor;
@@ -115,7 +116,7 @@ public class GitTest {
         int port = 22;
         String username = "root";
         String password = "gsh";
-        RemoteHost remoteHost = new RemoteHost(host, port, username, password);
+        RemoteHost remoteHost = new RemoteHost(host, port, SshAuthType.password.name(), username, password);
         Sftp sftp = new Sftp();
 
         String command = "docker ps -a";