Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private ImageReference getImageReference(ContainerImageConfig containerImageConf
throw new IllegalArgumentException("The supplied container-image registry '" + registry + "' is invalid");
}

String repository = (containerImageConfig.group.map(s -> s + "/").orElse(""))
String repository = (containerImageConfig.getEffectiveGroup().map(s -> s + "/").orElse(""))
+ containerImageConfig.name.orElse(applicationInfo.getName());
if (!ImageReference.isValidRepository(repository)) {
throw new IllegalArgumentException("The supplied container-image repository '" + repository + "' is invalid");
Expand Down
6 changes: 6 additions & 0 deletions extensions/container-image/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-spi</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,20 @@ public class ContainerImageConfig {
*/
@ConfigItem
public boolean push;

/**
* Since user.name which is default value can be uppercase and uppercase values are not allowed
* in the repository part of image references, we need to make the username lowercase.
*
* We purposely don't change the value of an explicitly set group.
*/
public Optional<String> getEffectiveGroup() {
if (group.isPresent()) {
String originalGroup = group.get();
if (originalGroup.equals(System.getProperty("user.name"))) {
return Optional.of(originalGroup.toLowerCase());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we lowercase only in this case? I mean it will fail if the group has some uppercase character, won't it?

Copy link
Contributor Author

@geoand geoand Apr 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea is that it's better to fail if the user explicitly sets a group that is invalid (the error message is very explicit and actionable). I am thinking that if we start changing user supplied configuration it could be a very slippery slope...
If however the user did not set anything and the username was used implicitly, then only in that implicit case should we intervene.

}
}
return group;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public ContainerImageInfoBuildItem publishImageInfo(ApplicationInfoBuildItem app
ensureSingleContainerImageExtension(capabilities);

return new ContainerImageInfoBuildItem(containerImageConfig.registry,
containerImageConfig.group,
containerImageConfig.getEffectiveGroup(),
containerImageConfig.name.orElse(app.getName()),
containerImageConfig.tag.orElse(app.getVersion()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.quarkus.container.image.deployment;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Optional;

import org.junit.jupiter.api.Test;

class ContainerImageConfigEffectiveGroupTest {

public static final String USER_NAME_SYSTEM_PROPERTY = "user.name";

private ContainerImageConfig sut = new ContainerImageConfig();

@Test
void testFromLowercaseUsername() {
testWithNewUsername("test", () -> {
sut.group = Optional.of(System.getProperty(USER_NAME_SYSTEM_PROPERTY));
assertEquals(sut.getEffectiveGroup(), Optional.of("test"));
});
}

@Test
void testFromUppercaseUsername() {
testWithNewUsername("TEST", () -> {
sut.group = Optional.of(System.getProperty(USER_NAME_SYSTEM_PROPERTY));
assertEquals(sut.getEffectiveGroup(), Optional.of("test"));
});
}

@Test
void testFromOther() {
testWithNewUsername("WhateveR", () -> {
sut.group = Optional.of("OtheR");
assertEquals(sut.getEffectiveGroup(), Optional.of("OtheR"));
});
}

private void testWithNewUsername(String newUserName, Runnable test) {
String previousUsernameValue = System.getProperty(USER_NAME_SYSTEM_PROPERTY);
System.setProperty(USER_NAME_SYSTEM_PROPERTY, newUserName);

test.run();

System.setProperty(USER_NAME_SYSTEM_PROPERTY, previousUsernameValue);
}
}