public Optional<Credential> retrieve(Consumer<LogEvent> logger) throws IOException {
    if (!Files.exists(dockerConfigFile)) {
      return Optional.empty();
    }

    ObjectMapper objectMapper =
        JsonMapper.builder()
            .configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true)
            .build();
    try (InputStream fileIn = Files.newInputStream(dockerConfigFile)) {
      if (legacyConfigFormat) {
        // legacy config format is the value of the "auths":{ <map> } block of the new config (i.e.,
        // the <map> of string -> DockerConfigTemplate.AuthTemplate).
        Map<String, AuthTemplate> auths =
            objectMapper.readValue(fileIn, new TypeReference<Map<String, AuthTemplate>>() {});
        DockerConfig dockerConfig = new DockerConfig(new DockerConfigTemplate(auths));
        return retrieve(dockerConfig, logger);
      }

      DockerConfig dockerConfig =
          new DockerConfig(objectMapper.readValue(fileIn, DockerConfigTemplate.class));
      return retrieve(dockerConfig, logger);
    }
  }
Retrieves credentials for a registry. Tries all possible known aliases.

@param logger a consumer for handling log events
@return {@link Credential} found for {@code registry}, or {@link Optional#empty} if not found
@throws IOException if failed to parse the config JSON
jib-core/src/main/java/com/google/cloud/tools/jib/registry/credentials/DockerConfigCredentialRetriever.java