Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e9bbad6c authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Do not print "secret"-looking environments

Bug: 292141694
Flag: TEST_ONLY
Test: atest RavenwoodMinimumTest # and manually check the output
Change-Id: I549f5fb10d5adb7c2b60ba551d62b95519f9a0d2
parent 946af159
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
@@ -143,6 +144,10 @@ public class RavenwoodDriver {
    static final int DEFAULT_TIMEOUT_SECONDS = 10;
    private static final int TIMEOUT_MILLIS = getTimeoutSeconds() * 1000;

    /** Do not dump environments matching this pattern. */
    private static final Pattern sSecretEnvPattern = Pattern.compile(
            "(KEY|AUTH|API)", Pattern.CASE_INSENSITIVE);

    static int getTimeoutSeconds() {
        var e = System.getenv("RAVENWOOD_TIMEOUT_SECONDS");
        if (e == null || e.isEmpty()) {
@@ -789,7 +794,19 @@ public class RavenwoodDriver {

    private static void dumpEnvironment() {
        Log.i(TAG, "Environment:");
        dumpMap(System.getenv());

        // Dump the environments, but don't print the values for "secret" ones.
        dumpMap(System.getenv().entrySet().stream()
                .collect(Collectors.toMap(
                        // The key remains the same
                        Map.Entry::getKey,

                        // Hide the values as needed.
                        entry -> sSecretEnvPattern.matcher(entry.getKey()).find()
                                ? "[redacted]" : entry.getValue(),
                        (oldValue, newValue) -> newValue,
                        HashMap::new
                )));
    }

    private static void dumpMap(Map<?, ?> map) {