Skip to content

Commit

Permalink
refactor(config): enhance password validation and method naming in Gl…
Browse files Browse the repository at this point in the history
…obalConfig

Improve the password validation logic by adding a check for blank strings
before attempting encryption. This prevents potential encryption of null orempty values. Also, rename the `getIsLoadImage` method to `isLoadImage` for
better readability and consistency with Java naming conventions.
  • Loading branch information
FT-Fetters committed Jul 6, 2024
1 parent 69106fc commit 1482217
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void end() {
}
});

if (GlobalConfig.getIsLoadImage()) {
if (GlobalConfig.isLoadImage()) {
loadToDocker(targetPath, imageFile.getName(),
buildChannelExec(sshHost, Integer.valueOf(sshPort), sshUser, sshPassword));
}
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/com/heybcat/docker/pull/web/config/GlobalConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.heybcat.docker.pull.web.config;

import com.heybcat.docker.pull.util.CryptoUtil;
import xyz.ldqc.tightcall.util.StringUtil;

/**
* @author Fetters
Expand Down Expand Up @@ -76,11 +77,14 @@ public static void setSshUser(String sshUser) {
}

public static String getSshPassword() {
if (sshPassword.matches("^[_+]+$")){
return sshPassword;

if (StringUtil.isNotBlank(sshPassword)){
if (sshPassword.matches("^[_+]+$")){
return sshPassword;
}else {
return CryptoUtil.moduloEncrypt(sshPassword);
}
}else {
return CryptoUtil.moduloEncrypt(sshPassword);
return "";
}
}

Expand All @@ -100,11 +104,15 @@ public static void setSshSavePath(String sshSavePath) {
GlobalConfig.sshSavePath = sshSavePath;
}

public static boolean getIsLoadImage() {
public static boolean isLoadImage() {
return isLoadImage.equals("true");
}

public static void setIsLoadImage(String isLoadImage) {
GlobalConfig.isLoadImage = isLoadImage;
}

public static String getIsLoadImage(){
return isLoadImage;
}
}

0 comments on commit 1482217

Please sign in to comment.