public static List<CredentialRetriever> getToCredentialRetrievers(
      CommonCliOptions commonCliOptions, DefaultCredentialRetrievers defaultCredentialRetrievers)
      throws FileNotFoundException {
    // these are all mutually exclusive as enforced by the CLI
    commonCliOptions
        .getUsernamePassword()
        .ifPresent(
            credential ->
                defaultCredentialRetrievers.setKnownCredential(
                    credential, "--username/--password"));
    commonCliOptions
        .getToUsernamePassword()
        .ifPresent(
            credential ->
                defaultCredentialRetrievers.setKnownCredential(
                    credential, "--to-username/--to-password"));
    commonCliOptions
        .getCredentialHelper()
        .ifPresent(defaultCredentialRetrievers::setCredentialHelper);
    commonCliOptions
        .getToCredentialHelper()
        .ifPresent(defaultCredentialRetrievers::setCredentialHelper);

    return defaultCredentialRetrievers.asList();
  }
Gets credentials for a target image registry.

@param commonCliOptions common cli options
@param defaultCredentialRetrievers An initialized {@link DefaultCredentialRetrievers} to use
@return a list of credentials for a target image registry
@throws FileNotFoundException when a credential helper file cannot be found
jib-cli/src/main/java/com/google/cloud/tools/jib/cli/Credentials.java