class RegistryClient {

  private boolean doBearerAuth(boolean readOnlyBearerAuth) throws IOException, RegistryException {
    String registry = registryEndpointRequestProperties.getServerUrl();
    String repository = registryEndpointRequestProperties.getImageName();
    String image = registry + "/" + repository;
    eventHandlers.dispatch(LogEvent.debug("attempting bearer auth for " + image + "..."));

    Optional<RegistryAuthenticator> authenticator =
        callRegistryEndpoint(
            new AuthenticationMethodRetriever(
                registryEndpointRequestProperties, getUserAgent(), httpClient));
    if (!authenticator.isPresent()) {
      eventHandlers.dispatch(LogEvent.debug("server requires basic auth for " + image));
      return false; // server returned "WWW-Authenticate: Basic ..."
    }

    doBearerAuth(readOnlyBearerAuth, authenticator.get());
    return true;
  }

  private  RegistryClient(
      EventHandlers eventHandlers,
      @Nullable Credential credential,
      RegistryEndpointRequestProperties registryEndpointRequestProperties,
      @Nullable String userAgent,
      FailoverHttpClient httpClient);

}