Skip to content

Commit

Permalink
Support access control specifications in volume binding strings..
Browse files Browse the repository at this point in the history
Signed-off-by: Elliot Metsger <emetsger@jhu.edu>
  • Loading branch information
emetsger committed Sep 6, 2017
1 parent 51ca2dd commit 8552deb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/main/java/io/fabric8/maven/docker/util/VolumeBindingUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import static io.fabric8.maven.docker.util.DockerPathUtil.resolveAbsolutely;
Expand Down Expand Up @@ -103,7 +104,6 @@ public static String resolveRelativeVolumeBinding(File baseDir, String bindingSt

String[] pathParts = bindingString.split(":");
String localPath = pathParts[0];
String serverPath = (pathParts.length > 1) ? pathParts[1] : "";

if (isRelativePath(localPath)) {
File resolvedFile;
Expand All @@ -119,8 +119,9 @@ public static String resolveRelativeVolumeBinding(File baseDir, String bindingSt
}
}

if (serverPath.length() > 0) {
return String.format("%s:%s", localPath, serverPath);
if (pathParts.length > 1) {
pathParts[0] = localPath;
return join(":", pathParts);
}

return localPath;
Expand Down Expand Up @@ -259,4 +260,17 @@ private static String prepareUserHomeRelativePath(String userHomePath) {

return "";
}

private static String join(String with, String... components) {
StringBuilder result = new StringBuilder();
int i = 0;
while (i < components.length) {
result.append(components[i++]);
if (i < components.length) {
result.append(with);
}
}

return result.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class VolumeBindingUtilTest {
private static final String USER_HOME = "~user";
private static final String CONTAINER_PATH = "/path/to/container/dir";
private final String BIND_STRING_FMT = "%s:%s";
private final String BIND_STRING_WITH_ACCESS_FMT = "%s:%s:%s";
private final String RO = "ro";
private final String RW = "rw";

@Test(expected = IllegalArgumentException.class)
public void relativeBaseDir() throws Exception {
Expand All @@ -44,6 +47,18 @@ public void testResolveRelativeVolumePath() throws Exception {
assertEquals(expectedBindingString, relativizedVolumeString);
}

@Test
public void testResolveRelativeVolumePathWithAccessSpecifications() throws Exception {
String volumeString = String.format(BIND_STRING_WITH_ACCESS_FMT, RELATIVE_PATH, CONTAINER_PATH, RO);

// './rel:/path/to/container/dir:ro' to '/absolute/basedir/rel:/path/to/container/dir:ro'
String relativizedVolumeString = resolveRelativeVolumeBinding(ABS_BASEDIR, volumeString);

String expectedBindingString = String.format(BIND_STRING_WITH_ACCESS_FMT,
new File(ABS_BASEDIR, stripLeadingPeriod(RELATIVE_PATH)), CONTAINER_PATH, RO);
assertEquals(expectedBindingString, relativizedVolumeString);
}

@Test
public void testResolveUserVolumePath() throws Exception {
String volumeString = String.format(BIND_STRING_FMT, USER_PATH, CONTAINER_PATH);
Expand Down

0 comments on commit 8552deb

Please sign in to comment.