Skip to content

Commit 5fd427b

Browse files
committed
enable to load resource from diff source
1 parent 95170ac commit 5fd427b

File tree

6 files changed

+24
-6
lines changed

6 files changed

+24
-6
lines changed

core/src/main/java/com/flowci/core/common/config/AppProperties.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public class AppProperties {
5252
@Length(max = 16, min = 16)
5353
private String secret;
5454

55+
// indicate load yaml template and plugin from where
56+
private String resourceDomain;
57+
5558
private boolean autoLocalAgentHost;
5659

5760
private boolean defaultSmtpConfig;

core/src/main/java/com/flowci/core/common/domain/Variables.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public abstract static class App {
2929

3030
public static final String Host = "FLOWCI_SERVER_HOST";
3131

32+
public static final String ResourceDomain = "FLOWCI_RESOURCE_DOMAIN";
3233
}
3334

3435
public abstract static class Flow {

core/src/main/java/com/flowci/core/flow/domain/Template.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.flowci.core.flow.domain;
22

3-
import com.fasterxml.jackson.annotation.JsonAlias;
3+
import com.fasterxml.jackson.annotation.JsonProperty;
44
import lombok.Getter;
55
import lombok.Setter;
66

@@ -10,7 +10,7 @@ public final class Template {
1010

1111
private String url;
1212

13-
@JsonAlias("url_cn")
13+
@JsonProperty("url_cn")
1414
private String urlCn;
1515

1616
private String desc;

core/src/main/java/com/flowci/core/plugin/domain/PluginRepoInfo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.flowci.core.plugin.domain;
1818

19-
import com.fasterxml.jackson.annotation.JsonAlias;
19+
import com.fasterxml.jackson.annotation.JsonProperty;
2020
import com.flowci.domain.Version;
2121
import lombok.EqualsAndHashCode;
2222
import lombok.Getter;
@@ -34,15 +34,15 @@
3434
@Getter
3535
@Setter
3636
@EqualsAndHashCode(of = {"name"})
37-
@ToString(of = {"name", "version", "source", "branch"})
37+
@ToString(of = {"name", "version", "branch"})
3838
public class PluginRepoInfo implements Serializable {
3939

4040
@Indexed(name = "index_plugins_name", unique = true)
4141
private String name;
4242

4343
private String source; // git repo url
4444

45-
@JsonAlias("source_cn")
45+
@JsonProperty("source_cn")
4646
private String sourceCn; // git repo url for cn
4747

4848
private String branch = "master";

core/src/main/java/com/flowci/core/plugin/service/PluginServiceImpl.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public class PluginServiceImpl implements PluginService {
7474
@Autowired
7575
private Path pluginDir;
7676

77+
@Autowired
78+
private AppProperties appProperties;
79+
7780
@Autowired
7881
private AppProperties.Plugin pluginProperties;
7982

@@ -247,7 +250,17 @@ private Plugin clone(PluginRepoInfo repo) throws Exception {
247250
log.info("Start to load plugin: {}", repo);
248251
Path dir = getPluginRepoDir(repo.getName(), repo.getVersion().toString());
249252

250-
GitClient client = new GitClient(repo.getSource(), null, null);
253+
String rd = appProperties.getResourceDomain().toLowerCase();
254+
String resource = repo.getSource();
255+
if (rd.equals("cn")) {
256+
resource = repo.getSourceCn();
257+
}
258+
259+
if (!StringHelper.hasValue(resource)) {
260+
throw new NotFoundException("Plugin {0} source is missing for domain {1}", repo.getName(), rd);
261+
}
262+
263+
GitClient client = new GitClient(resource, null, null);
251264
client.klone(dir, repo.getBranch());
252265

253266
return load(dir.toFile(), repo);

core/src/main/resources/flow.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ app.flow-dir=${app.workspace}/flows
33
app.site-dir=${app.workspace}/sites-static-resources
44
app.secret=${FLOWCI_SECRET:qazWSXedcRFV12#$}
55
app.auto-local-agent-host=${FLOWCI_AUTO_AGENT:true}
6+
app.resource-domain=${FLOWCI_RESOURCE_DOMAIN}
67
app.default-smtp-config=true
78
app.socket-container=true
89
app.core-pool-size=100

0 commit comments

Comments
 (0)