Skip to content

Commit dccf981

Browse files
author
Yang Guo
committed
api add empty space check when create agent
1 parent beac08e commit dccf981

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

platform-api/src/main/java/com/flow/platform/api/service/AgentServiceImpl.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.flow.platform.api.service.job.JobService;
2727
import com.flow.platform.api.util.PlatformURL;
2828
import com.flow.platform.core.exception.HttpException;
29+
import com.flow.platform.core.exception.IllegalParameterException;
2930
import com.flow.platform.core.exception.IllegalStatusException;
3031
import com.flow.platform.core.service.ApplicationEventService;
3132
import com.flow.platform.domain.Agent;
@@ -38,6 +39,7 @@
3839
import com.flow.platform.domain.Jsonable;
3940
import com.flow.platform.util.CollectionUtil;
4041
import com.flow.platform.util.Logger;
42+
import com.flow.platform.util.StringUtil;
4143
import com.flow.platform.util.http.HttpClient;
4244
import com.flow.platform.util.http.HttpResponse;
4345
import com.flow.platform.util.http.HttpURL;
@@ -144,6 +146,10 @@ public Boolean shutdown(String zone, String name, String password) {
144146

145147
@Override
146148
public AgentWithFlow create(AgentPath agentPath) {
149+
if (StringUtil.hasSpace(agentPath.getZone()) || StringUtil.hasSpace(agentPath.getName())) {
150+
throw new IllegalParameterException("Zone name or agent name cannot contain empty space");
151+
}
152+
147153
try {
148154
AgentPathWithWebhook pathWithWebhook = new AgentPathWithWebhook(agentPath, buildAgentWebhook());
149155

@@ -158,9 +164,7 @@ public AgentWithFlow create(AgentPath agentPath) {
158164
}
159165

160166
Agent agent = Agent.parse(response.getBody(), Agent.class);
161-
162-
AgentWithFlow agentWithFlow = new AgentWithFlow(agent, null);
163-
return agentWithFlow;
167+
return new AgentWithFlow(agent, null);
164168

165169
} catch (UnsupportedEncodingException | JsonSyntaxException e) {
166170
throw new IllegalStatusException("Unable to create agent", e);

platform-util/src/main/java/com/flow/platform/util/StringUtil.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class StringUtil {
2525

2626
public final static String EMPTY = "";
2727

28+
public static boolean hasSpace(final String str) {
29+
return str.contains(" ");
30+
}
31+
2832
public static boolean isNullOrEmptyForItems(final String... strings) {
2933
if (CollectionUtil.isNullOrEmpty(strings)) {
3034
return true;

0 commit comments

Comments
 (0)