Kaynağa Gözat

deployer 从 csv 文件的第二行开始读取 server 的帐号密码, csv 文件的第一行作为注释

reghao 2 yıl önce
ebeveyn
işleme
eb003543cc

+ 9 - 6
deployer/src/main/java/cn/reghao/devops/deployer/util/Sftp.java

@@ -11,7 +11,6 @@ import java.io.*;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
-import java.util.stream.Collectors;
 
 /**
  * @author reghao
@@ -180,24 +179,28 @@ public class Sftp {
     }
 
     public List<RemoteHost> getRemoteHost(String filePath) {
-        return textFile.read(filePath).stream().map(line -> {
+        List<String> list = textFile.read(filePath);
+        List<RemoteHost> remoteHosts = new ArrayList<>();
+        for (int i = 1; i < list.size(); i++) {
+            // 从 csv 文件的第二行开始读, 第一行为注释
+            String line = list.get(i);
             String[] arr = line.split(",");
             if (arr.length == 4) {
                 String host = arr[0];
                 int port = Integer.parseInt(arr[1]);
                 String username = arr[2];
                 String password = arr[3];
-                return new RemoteHost(host, port, username, password, null);
+                remoteHosts.add(new RemoteHost(host, port, username, password, null));
             } else if (arr.length == 5) {
                 String host = arr[0];
                 int port = Integer.parseInt(arr[1]);
                 String username = arr[2];
                 String prikeyPath = arr[4];
-                return new RemoteHost(host, port, username, null, prikeyPath);
+                remoteHosts.add(new RemoteHost(host, port, username, null, prikeyPath));
             }
+        }
 
-            return null;
-        }).filter(Objects::nonNull).collect(Collectors.toList());
+        return remoteHosts;
     }
 
     public void deploy(String localDir, String remoteDir, RemoteHost remoteHost) throws Exception {