Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/main/java/io/spaship/sidecar/sync/CurlUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ public class CurlUtility {
private static final Logger LOG = LoggerFactory.getLogger(CurlUtility.class);

static TriFunction<String, String, Boolean, Integer> execution = CurlUtility::processCommand;
static QuadFunction<String, String, String, String, String> command = CurlUtility::constructRemoteFileDownloadCommand;

public static QuadFunction<String, String, String, String, Integer> with(String executionDirectory, boolean debug) {
return command.andThen(res -> execution.apply(res, executionDirectory, debug));
public static QuadFunction<String, String, String, String, Integer> with(String executionDirectory, boolean debug,
String userAgentParam) {
return (url, fileName, noCacheParam, proxyParam) -> {
String cmd = constructRemoteFileDownloadCommand(url, fileName, noCacheParam, proxyParam, userAgentParam);
return execution.apply(cmd, executionDirectory, debug);
};
}

static int processCommand(String curlCommand, String executionDirectory, boolean debug) {
Expand Down Expand Up @@ -63,13 +66,16 @@ static void debugCommandOutput(Process process, String curlCommand) {
}

static String constructRemoteFileDownloadCommand(String url, String fileName,
String noCacheParam, String proxyParam) {
String noCacheParam, String proxyParam,
String userAgentParam) {
StringBuilder commandBuilder = new StringBuilder();
commandBuilder.append("curl~-k~");
if (Objects.nonNull(noCacheParam) && !noCacheParam.isEmpty())
commandBuilder.append(noCacheParam).append("~");
if (Objects.nonNull(proxyParam) && !proxyParam.isEmpty())
commandBuilder.append(proxyParam).append("~");
if (Objects.nonNull(userAgentParam) && !userAgentParam.isEmpty())
commandBuilder.append("-A~").append(userAgentParam).append("~");
commandBuilder.append(url).append("~").append("-o~").append(fileName);

return commandBuilder.toString();
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/io/spaship/sidecar/sync/SyncService.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,13 @@ private void copyAndReplace(String targetUrl, String fullyQualifiedDestPath, Str
null : ConfigProvider.getConfig().getValue("curl.proxy.param", String.class);
var debugCurl = ConfigProvider.getConfig()
.getValue("curl.command.debug", String.class).equalsIgnoreCase("true");
var userAgentParam = ConfigProvider.getConfig()
.getOptionalValue("sidecar.sync.user.agent", String.class)
.filter(v -> !v.equalsIgnoreCase("na"))
.orElse(null);

//execute curl command
var statusCodeOutcome = CurlUtility.with(fullyQualifiedDestPath, debugCurl)
var statusCodeOutcome = CurlUtility.with(fullyQualifiedDestPath, debugCurl, userAgentParam)
.apply(transformedTargetUrl, fileName, noCacheParam, proxyParam);
LOG.debug("curl return code is {}", statusCodeOutcome);

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ sidecar.sync.on=false
curl.nocache.param=-H~'Cache-Control: no-cache, no-store'
curl.proxy.param=--proxy~http://squid.corp.redhat.com:3128
curl.command.debug=true
#sidecar.sync.user.agent=
sidecar.sync.config=na
#sidecar.sync.config={ \"autosync\": { \"enabled\": true, \"targets\": [ { \"name\": \"chrome-head\", \"interval\": \"1m\", \"source\": { \"url\": \"https://access.dev.redhat.com/services/chrome/head?legacy=false\", \"sub_paths\": [ \"/en\", \"/ko\", \"/ja\", \"/zh_CN\" ] }, \"dest\": { \"path\": \"/var/www/html/.include/chrome/head\", \"filename\": \"head.html\" } }, { \"name\": \"chrome-header\", \"interval\": \"1m\", \"source\": { \"url\": \"https://access.dev.redhat.com/services/chrome/header?legacy=false\", \"sub_paths\": [ \"/en\", \"/ko\", \"/ja\", \"/zh_CN\" ] }, \"dest\": { \"path\": \"/var/www/html/.include/chrome/header\", \"filename\": \"header.html\" } }, { \"name\": \"chrome-footer\", \"interval\": \"1m\", \"source\": { \"url\": \"https://access.dev.redhat.com/services/chrome/footer?legacy=false\", \"sub_paths\": [ \"/en\", \"/ko\", \"/ja\", \"/zh_CN\" ] }, \"dest\": { \"path\": \"/var/www/html/.include/chrome/footer\", \"filename\": \"footer.html\" } } ] }}
Loading