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
2 changes: 1 addition & 1 deletion .github/workflows/deploy-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
MAVEN_GPG_KEY: ${{ secrets.MAVEN_GPG_KEY }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
run: mvn clean deploy --no-transfer-progress
run: mvn clean deploy -Pci-publish --no-transfer-progress
- name: Get current version
id: version
run: echo "::set-output name=prop::$(mvn -f pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout)"
Expand Down
Binary file modified docs/console.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/console_banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
176 changes: 176 additions & 0 deletions docs/illustration.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/illustrationColoree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 54 additions & 42 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>io.github.fbibonne</groupId>
<artifactId>boot-properties-logger-starter</artifactId>
<version>2.1.0</version>
<version>2.2.0</version>
<packaging>jar</packaging>

<properties>
Expand Down Expand Up @@ -107,6 +107,59 @@
</dependency>
</dependencies>

<profiles>
<profile>
<id>ci-publish</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg-plugin.version}</version>
<configuration>
<signer>bc</signer>
</configuration>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>install</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>dev.sigstore</groupId>
<artifactId>sigstore-maven-plugin</artifactId>
<version>${sigstore-maven-plugin.version}</version>
<executions>
<execution>
<id>sign</id>
<phase>install</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>${central-publishing-maven-plugin.version}</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<deploymentName>Properties-Logger</deploymentName>
<autoPublish>true</autoPublish>
</configuration>
</plugin>
</plugins>

</build>
</profile>
</profiles>

<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -152,47 +205,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg-plugin.version}</version>
<configuration>
<signer>bc</signer>
</configuration>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>install</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>dev.sigstore</groupId>
<artifactId>sigstore-maven-plugin</artifactId>
<version>${sigstore-maven-plugin.version}</version>
<executions>
<execution>
<id>sign</id>
<phase>install</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>${central-publishing-maven-plugin.version}</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<deploymentName>Properties-Logger</deploymentName>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@

/**
* Class doing the real stuff for logging properties. The collect of properties to log, their value and the logging is done
* inside the {@link this#doLogProperties()} method.
* inside the <code>doLogProperties</code> method.
* The state of the class stores {@link PropertySource} found, and a reference to an operator providing the origin of a property
* which is found while scanning propertySources
*/
class PropertiesLogger {
public class PropertiesLogger {

public static final String SEPARATION_LINE = "================================================================================";
public static final String MASK = "******";
private static final LocalLogger log = new LocalLogger(PropertiesLogger.class);
public static final String ANSI_CYAN_BOLD_SEQUENCE = "\u001B[1;36m";
public static final String ANSI_NORMAL_SEQUENCE = "\u001B[0m";
public static final String ANSI_BROWN_UNDERLINE_SEQUENCE = "\u001B[4;33m";
public static final String AINSI_PURPLE_ITALIC_SEQUENCE = "\u001B[1;3;35m";
public static final String AINSI_GREEN_BOLD_SEQUENCE = "\u001B[1;32m";

final PropertiesWithHiddenValues propertiesWithHiddenValues;
final AllowedPrefixForProperties allowedPrefixForProperties;
Expand All @@ -46,7 +51,7 @@ class PropertiesLogger {
* <li>debug message is logged if the propertySource is ignored</li>
* <li>warn message is logged if the propertySource is a {@link org.springframework.boot.ansi.AnsiPropertySource} (whose processing is not implmented).
* in such case, it will be ignored</li>

*
* <li>If propertySource has an unknown type, a warning is logged</li>
* </ul>
* </li>
Expand All @@ -58,14 +63,14 @@ class PropertiesLogger {
* </ol>
*
*/
public void doLogProperties() {
void doLogProperties() {
debugStarting();
final StringBuilder stringWithPropertiesToDisplay = new StringBuilder();

Map<String, String[]> propertyNamesBySource = propertyNamesBySourceFromEnvironment();
final Set<String> propertySourceNames = propertyNamesBySource.keySet();

stringWithPropertiesToDisplay.append( headerBlock(propertySourceNames))
stringWithPropertiesToDisplay.append(headerBlock(propertySourceNames))
.append(toKeyValuesBlock(propertyNamesBySource))
.append(System.lineSeparator())
.append(SEPARATION_LINE);
Expand All @@ -77,10 +82,10 @@ private String headerBlock(Set<String> propertySourceNames) {
return """

%1$s
Values of properties from sources :
%2$s
%2$sValues of properties from sources :%3$s
%4$s
====
""".formatted(SEPARATION_LINE, insertPropretySourceNamesOnePerLine(propertySourceNames));
""".formatted(SEPARATION_LINE, AINSI_GREEN_BOLD_SEQUENCE, ANSI_NORMAL_SEQUENCE, propretySourceNamesOnePerLine(propertySourceNames));
}

private String toKeyValuesBlock(Map<String, String[]> propertyNamesBySource) {
Expand Down Expand Up @@ -113,7 +118,7 @@ private void debugStarting() {
+ ignoredPropertySources + ". Values masked for properties whose keys contain " + propertiesWithHiddenValues);
}

private String insertPropretySourceNamesOnePerLine(Set<String> propertySourceNames) {
private String propretySourceNamesOnePerLine(Set<String> propertySourceNames) {
return propertySourceNames.stream().sorted().map(name -> "- " + name).collect(Collectors.joining(System.lineSeparator()));
}

Expand Down Expand Up @@ -141,12 +146,13 @@ private static void traceIgnored(PropertySource<?> propertySource) {
}

private String toDisplayedLine(String key) {
return key + " = " + resolveValueThenMaskItIfSecret(key, this.abstractEnvironment)
return ANSI_CYAN_BOLD_SEQUENCE + key + ANSI_NORMAL_SEQUENCE + " = "
+ ANSI_BROWN_UNDERLINE_SEQUENCE + resolveValueThenMaskItIfSecret(key, this.abstractEnvironment) + ANSI_NORMAL_SEQUENCE
+ this.originFinder.findOriginFor(key).map(PropertiesLogger::originAsLine).orElse("");
}

private static String originAsLine(String origin) {
return " ### " + origin + " ###";
return " ### " + AINSI_PURPLE_ITALIC_SEQUENCE + origin + ANSI_NORMAL_SEQUENCE + " ###";
}

private @Nullable String resolveValueThenMaskItIfSecret(String key, EnvironmentPreparedEventForPropertiesLogging.CustomAbstractEnvironment environment) {
Expand All @@ -163,19 +169,20 @@ private boolean mustBeMasked(String key) {
/**
* Implementation of a String#containsIgnoreCase based the algorithm of String#contains
* but using String#equalsIgnoreCase to test equality
*
* @param container the string which is supposed to contain the argument passed to the predicate.
* Must be not null
* @return a predicate such as <code>container::containsIgnoreCase</code>
* (if String#containsIgnoreCase would exist)
*/
Predicate<? super String> isValueContainedIgnoringCaseIn(String container) {
return value -> {
if (value.isEmpty()){
if (value.isEmpty()) {
return true;
}
int valueLength = value.length();
for(int i = 0; i <= container.length()- valueLength; i++) {
if (container.substring(i, i+valueLength).equalsIgnoreCase(value)){
for (int i = 0; i <= container.length() - valueLength; i++) {
if (container.substring(i, i + valueLength).equalsIgnoreCase(value)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.nio.file.Files;
import java.nio.file.Path;

import static io.github.fbibonne.springaddons.boot.propertieslogger.PropertiesLogger.*;
import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(classes = ExcludedPropertySourcesTest.class, properties = {
Expand Down Expand Up @@ -63,11 +64,11 @@ void contextLoad_shouldNotPrintExcludedPropertySources(@Autowired Environment en
assertThat(environment.getProperty("properties.logger.sources-ignored")).hasToString("systemProperties, systemEnvironment,[application.properties],[otherProps/application.properties],commandLineArgs,Inlined Test Properties,["+ externalPropertiesPath.toAbsolutePath()+"]");
assertThat(environment.getProperty("io.github.fbibonne.shared")).hasToString("dynamicPropertySource");
assertThat(environment.getProperty("io.github.fbibonne.specific.nonExcludedFile")).hasToString("nonExcludedFile");
assertThat(logOutput).contains("io.github.fbibonne.shared = inlineTestProperties")
assertThat(logOutput).contains("io.github.fbibonne.shared"+ANSI_NORMAL_SEQUENCE+" = "+ANSI_BROWN_UNDERLINE_SEQUENCE+"inlineTestProperties")
.doesNotContain("io.github.fbibonne.specific.dynamicPropertySource")
.contains("io.github.fbibonne.specific.nonExcludedFile = nonExcludedFile")
.contains("io.github.fbibonne.specific.nonExcludedFile"+ANSI_NORMAL_SEQUENCE+" = "+ANSI_BROWN_UNDERLINE_SEQUENCE+"nonExcludedFile")
.doesNotContain("io.github.fbibonne.sharedWithExternal = nonExcludedFile")
.contains("io.github.fbibonne.sharedWithExternal = inFileSystem")
.contains("io.github.fbibonne.sharedWithExternal"+ANSI_NORMAL_SEQUENCE+" = "+ANSI_BROWN_UNDERLINE_SEQUENCE+"inFileSystem")
.doesNotContain("io.github.fbibonne.specific.inFileSystem = inFileSystem")
.doesNotContain("io.github.fbibonne.specific.applicationproperties")
.doesNotContain("io.github.fbibonne.specific.additionalPropsInClasspath")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.io.IOException;
import java.nio.file.Path;

import static io.github.fbibonne.springaddons.boot.propertieslogger.PropertiesLogger.ANSI_BROWN_UNDERLINE_SEQUENCE;
import static io.github.fbibonne.springaddons.boot.propertieslogger.PropertiesLogger.ANSI_NORMAL_SEQUENCE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

Expand Down Expand Up @@ -40,22 +42,22 @@ void startingSpringBootApplicationWithExternalOptionalPropertiesFilesAndUnexisti
"--spring.main.web-application-type=none")).doesNotThrowAnyException();
Environment environment = contextRef.context.getEnvironment();
assertThatCode(()->environment.getProperty("spring.config.location")).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Could not resolve placeholder 'unexisting'");
assertThat(capturedOutput.toString()).contains("spring.config.location = optional:file:/${unexisting}/application.properties");
assertThat(capturedOutput.toString()).contains("spring.config.location"+ANSI_NORMAL_SEQUENCE+" = "+ANSI_BROWN_UNDERLINE_SEQUENCE+"optional:file:/${unexisting}/application.properties");
//otherProps/application.properties
/*
* io.github.fbibonne.shared = additionalPropsInClasspath
* io.github.fbibonne.specific.additionalPropsInClasspath = additionalPropsInClasspath
*/
assertThat(environment.getProperty("io.github.fbibonne.specific.additionalPropsInClasspath")).hasToString("additionalPropsInClasspath");
assertThat(capturedOutput.toString()).contains("io.github.fbibonne.specific.additionalPropsInClasspath = additionalPropsInClasspath");
assertThat(capturedOutput.toString()).contains("io.github.fbibonne.specific.additionalPropsInClasspath"+ANSI_NORMAL_SEQUENCE+" = "+ANSI_BROWN_UNDERLINE_SEQUENCE+"additionalPropsInClasspath");
// /${existing}/application.properties => nonExcluded/application.properties
/*
* io.github.fbibonne.shared = nonExcludedFile
* io.github.fbibonne.specific.nonExcludedFile = nonExcludedFile
* io.github.fbibonne.sharedWithExternal = nonExcludedFile
*/
assertThat(environment.getProperty("io.github.fbibonne.specific.nonExcludedFile")).hasToString("nonExcludedFile");
assertThat(capturedOutput.toString()).contains("io.github.fbibonne.specific.nonExcludedFile = nonExcludedFile");
assertThat(capturedOutput.toString()).contains("io.github.fbibonne.specific.nonExcludedFile"+ANSI_NORMAL_SEQUENCE+" = "+ANSI_BROWN_UNDERLINE_SEQUENCE+"nonExcludedFile");
// /${existing:"+ ignoredPath +"}/application.properties => not /ignored/application.properties
assertThat(environment.getProperty("io.github.fbibonne.specific.ignoredFile")).isNull();
assertThat(capturedOutput.toString()).doesNotContain("io.github.fbibonne.specific.ignoredFile");
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/io/github/fbibonne/test/MaskedValuesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.context.annotation.Configuration;

import static io.github.fbibonne.springaddons.boot.propertieslogger.ConstantsForTests.MASK;
import static io.github.fbibonne.springaddons.boot.propertieslogger.PropertiesLogger.*;
import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(classes = ExcludedPropertySourcesTest.class, properties = {
Expand All @@ -21,7 +22,7 @@ class MaskedValuesTest {
@Test
void checkMaskValuesIgnoreCase(CapturedOutput output) {
assertThat(output.toString()).doesNotContain("verysecretpassword")
.contains("com.mycompany.serviceContactPassword = "+MASK);
.contains(ANSI_CYAN_BOLD_SEQUENCE+"com.mycompany.serviceContactPassword"+ANSI_NORMAL_SEQUENCE+" = "+ANSI_BROWN_UNDERLINE_SEQUENCE+MASK);
}

}
Loading