public String artifactLocator(String filePath) { //TODO: we should make sure data is valid at the beginning instead of fixing it here if (filePath.startsWith("/")) { filePath = filePath.substring(1); } return UrlUtil.encodeInUtf8(String.format("%s/%s/%s", stageLocator(), buildName, filePath)); }
private String getUploadUrl(String buildId, String normalizedDestPath, int publishingAttempts) { String path = format("%s?attempt=%d&buildId=%s", UrlUtil.encodeInUtf8(normalizedDestPath), publishingAttempts, buildId); return UrlUtil.concatPath(artifactsBaseUrl, path); }
public String buildLocator() { //TODO: the encoding logic should be moved to presentation layer return UrlUtil.encodeInUtf8(String.format("%s/%s", stageLocator(), buildName)); }
private String getPropertiesUrl(String propertyName) { return UrlUtil.concatPath(propertyBaseUrl, UrlUtil.encodeInUtf8(propertyName)); }
public String propertyLocator(String propertyName) { return UrlUtil.encodeInUtf8(String.format("%s/%s/%s", stageLocator(), buildName, propertyName)); }
private List stageHistoryAsJson(PipelineInstanceModel pipelineInstanceModel, StageInstanceModels stageHistory) { List json = new ArrayList(); for (StageInstanceModel stageHistoryItem : stageHistory) { Map<String, Object> jsonMap = new LinkedHashMap<>(); jsonMap.put("stageName", stageHistoryItem.getName()); jsonMap.put("stageId", stageHistoryItem.getId()); jsonMap.put("stageStatus", stageHistoryItem.getState().toString()); StageIdentifier stageIdentifier = new StageIdentifier(pipelineInstanceModel.getPipelineIdentifier(), stageHistoryItem.getName(), stageHistoryItem.getCounter()); jsonMap.put("stageLocator", encodeInUtf8(stageIdentifier.stageLocator())); jsonMap.put("getCanRun", Boolean.toString(stageHistoryItem.getCanRun())); jsonMap.put("getCanCancel", Boolean.toString(stageHistoryItem.getCanCancel())); jsonMap.put("scheduled", Boolean.toString(stageHistoryItem.isScheduled())); jsonMap.put("stageCounter", stageHistoryItem.getCounter()); handleApproval(stageHistoryItem, jsonMap); json.add(jsonMap); } return json; }
@Test public void shouldEncodeAllPartsInUrl() { assertThat(UrlUtil.encodeInUtf8("a%b/c%d"), is("a%25b/c%25d")); }
@Test public void shouldKeepTrailingSlash() { assertThat(UrlUtil.encodeInUtf8("a%b/c%d/"), is("a%25b/c%25d/")); }
@Test public void shouldKeepPrecedingSlash() { assertThat(UrlUtil.encodeInUtf8("/a%b/c%d"), is("/a%25b/c%25d")); }
@Test public void shouldEncodeUrl() { assertThat(UrlUtil.encodeInUtf8("a%b"), is("a%25b")); }