Skip to content

Commit

Permalink
Remove project name validation (#741)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoenig10 authored Feb 9, 2024
1 parent e77946e commit 2e999cb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 43 deletions.
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-741.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: improvement
improvement:
description: Project names are no longer validation. Any value can be used for a
project name.
links:
- https://github.com/palantir/docker-compose-rule/pull/741
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@
*/
package com.palantir.docker.compose.configuration;

import static com.google.common.base.Preconditions.checkState;

import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import org.immutables.value.Value.Check;
import org.immutables.value.Value.Immutable;
import org.immutables.value.Value.Parameter;

Expand All @@ -35,29 +30,6 @@ public abstract class ProjectName {
@Parameter
protected abstract Optional<String> projectName();

@Check
protected void validate() {
if (!projectName().isPresent()) {
return;
}

checkState(
projectName().get().trim().length() > 0,
"ProjectName must not be blank. If you want to omit the project name, use ProjectName.omit()");

checkState(
validCharacters(projectName().get()),
"ProjectName '%s' not allowed, please use lowercase letters and numbers only.",
projectName().get());
}

// Only allows strings that docker-compose-cli would not modify
// https://github.com/docker/compose/blob/85e2fb63b3309280a602f1f76d77d3a82e53b6c2/compose/cli/command.py#L84
protected boolean validCharacters(String projectName) {
Predicate<String> illegalCharacters = Pattern.compile("[^a-z0-9]").asPredicate();
return !illegalCharacters.test(projectName);
}

public String asString() {
return projectName()
.orElseThrow(() -> new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,6 @@ public void return_empty_command_when_omitted() {
assertThat(command).isEmpty();
}

@Test
public void reject_blanks_in_from_string() {
exception.expect(IllegalStateException.class);
exception.expectMessage("ProjectName must not be blank.");
ProjectName.fromString(" ");
}

@Test
public void match_validation_behavior_of_docker_compose_cli() {
exception.expect(IllegalStateException.class);
exception.expectMessage(
"ProjectName 'Crazy#Proj ect!Name' not allowed, please use lowercase letters and numbers only.");
ProjectName.fromString("Crazy#Proj ect!Name");
}

@Test
public void should_return_the_project_name_when_asString_called() {
String projectName = ProjectName.fromString("projectname").asString();
Expand Down

0 comments on commit 2e999cb

Please sign in to comment.