Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -99,36 +99,39 @@ public static Bind parse(String serialized) {
try {
String[] parts = serialized.split(":");
switch (parts.length) {
case 2: {
return new Bind(parts[0], new Volume(parts[1]));
}
case 3: {
String[] flags = parts[2].split(",");
AccessMode accessMode = AccessMode.DEFAULT;
SELContext seMode = SELContext.DEFAULT;
Boolean nocopy = null;
PropagationMode propagationMode = PropagationMode.DEFAULT_MODE;
for (String p : flags) {
if (p.length() == 2) {
accessMode = AccessMode.valueOf(p.toLowerCase());
} else if ("nocopy".equals(p)) {
nocopy = true;
} else if (PropagationMode.SHARED.toString().equals(p)) {
propagationMode = PropagationMode.SHARED;
} else if (PropagationMode.SLAVE.toString().equals(p)) {
propagationMode = PropagationMode.SLAVE;
} else if (PropagationMode.PRIVATE.toString().equals(p)) {
propagationMode = PropagationMode.PRIVATE;
} else {
seMode = SELContext.fromString(p);
}
case 2: {
return new Bind(parts[0], new Volume(parts[1]));
}
case 4: {
Comment thread
bsideup marked this conversation as resolved.
Outdated
parts = new String[]{parts[0] + ":" + parts[1], parts[2], parts[3]};
}
case 3: {
String[] flags = parts[2].split(",");
AccessMode accessMode = AccessMode.DEFAULT;
SELContext seMode = SELContext.DEFAULT;
Boolean nocopy = null;
PropagationMode propagationMode = PropagationMode.DEFAULT_MODE;
for (String p : flags) {
if (p.length() == 2) {
accessMode = AccessMode.valueOf(p.toLowerCase());
} else if ("nocopy".equals(p)) {
nocopy = true;
} else if (PropagationMode.SHARED.toString().equals(p)) {
propagationMode = PropagationMode.SHARED;
} else if (PropagationMode.SLAVE.toString().equals(p)) {
propagationMode = PropagationMode.SLAVE;
} else if (PropagationMode.PRIVATE.toString().equals(p)) {
propagationMode = PropagationMode.PRIVATE;
} else {
seMode = SELContext.fromString(p);
}
}

return new Bind(parts[0], new Volume(parts[1]), accessMode, seMode, nocopy, propagationMode);
}
default: {
throw new IllegalArgumentException();
}
return new Bind(parts[0], new Volume(parts[1]), accessMode, seMode, nocopy, propagationMode);
}
default: {
throw new IllegalArgumentException();
}
}
} catch (Exception e) {
throw new IllegalArgumentException("Error parsing Bind '" + serialized + "'", e);
Expand Down
1 change: 1 addition & 0 deletions docker-java-transport-zerodep/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
Comment thread
bsideup marked this conversation as resolved.
Outdated
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,113 @@ public void parseUsingDefaultAccessMode() {
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}

@Test
public void parseReadWriteWindows() {
Bind bind = Bind.parse("C:\\host:/container:rw");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}

@Test
public void parseReadWriteNoCopyWindows() {
Bind bind = Bind.parse("C:\\host:/container:rw,nocopy");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), is(true));
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}

@Test
public void parseReadWriteSharedWindows() {
Bind bind = Bind.parse("C:\\host:/container:rw,shared");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.SHARED));
}

@Test
public void parseReadWriteSlaveWindows() {
Bind bind = Bind.parse("C:\\host:/container:rw,slave");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.SLAVE));
}

@Test
public void parseReadWritePrivateWindows() {
Bind bind = Bind.parse("C:\\host:/container:rw,private");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.PRIVATE));
}

@Test
public void parseReadOnlyWindows() {
Bind bind = Bind.parse("C:\\host:/container:ro");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(ro));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}

@Test
public void parseSELOnlyWindows() {
Bind bind = Bind.parse("C:\\host:/container:Z");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(AccessMode.DEFAULT));
assertThat(bind.getSecMode(), is(SELContext.single));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));

bind = Bind.parse("C:\\host:/container:z");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(AccessMode.DEFAULT));
assertThat(bind.getSecMode(), is(SELContext.shared));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}

@Test
public void parseReadWriteSELWindows() {
Bind bind = Bind.parse("C:\\host:/container:rw,Z");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.single));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}

@Test
public void parseReadOnlySELWindows() {
Bind bind = Bind.parse("C:\\host:/container:ro,z");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(ro));
assertThat(bind.getSecMode(), is(SELContext.shared));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}

@Test
public void parseReadWrite() {
Bind bind = Bind.parse("/host:/container:rw");
Expand Down