public Integer call()

in quarkus/admin/src/main/java/org/apache/polaris/admintool/BootstrapCommand.java [77:148]


  public Integer call() {
    try {
      RootCredentialsSet rootCredentialsSet;
      List<String> realms; // TODO Iterable

      if (inputOptions.fileOptions != null) {
        rootCredentialsSet =
            RootCredentialsSet.fromUrl(inputOptions.fileOptions.file.toUri().toURL());
        realms = rootCredentialsSet.credentials().keySet().stream().toList();
      } else {
        realms = inputOptions.stdinOptions.realms;
        rootCredentialsSet =
            inputOptions.stdinOptions.credentials == null
                    || inputOptions.stdinOptions.credentials.isEmpty()
                ? RootCredentialsSet.EMPTY
                : RootCredentialsSet.fromList(inputOptions.stdinOptions.credentials);
        if (inputOptions.stdinOptions.credentials == null
            || inputOptions.stdinOptions.credentials.isEmpty()) {
          if (!inputOptions.stdinOptions.printCredentials) {
            spec.commandLine()
                .getErr()
                .println(
                    "Specify either `--credentials` or `--print-credentials` to ensure"
                        + " the root user is accessible after bootstrapping.");
            return EXIT_CODE_BOOTSTRAP_ERROR;
          }
        }
      }

      // Execute the bootstrap
      Map<String, PrincipalSecretsResult> results =
          metaStoreManagerFactory.bootstrapRealms(realms, rootCredentialsSet);

      // Log any errors:
      boolean success = true;
      for (Map.Entry<String, PrincipalSecretsResult> result : results.entrySet()) {
        if (result.getValue().isSuccess()) {
          String realm = result.getKey();
          spec.commandLine().getOut().printf("Realm '%s' successfully bootstrapped.%n", realm);
          if (inputOptions.stdinOptions != null && inputOptions.stdinOptions.printCredentials) {
            String msg =
                String.format(
                    "realm: %1s root principal credentials: %2s:%3s",
                    result.getKey(),
                    result.getValue().getPrincipalSecrets().getPrincipalClientId(),
                    result.getValue().getPrincipalSecrets().getMainSecret());
            spec.commandLine().getOut().println(msg);
          }
        } else {
          String realm = result.getKey();
          spec.commandLine()
              .getErr()
              .printf(
                  "Bootstrapping '%s' failed: %s%n",
                  realm, result.getValue().getReturnStatus().toString());
          success = false;
        }
      }

      if (success) {
        spec.commandLine().getOut().println("Bootstrap completed successfully.");
        return 0;
      } else {
        spec.commandLine().getErr().println("Bootstrap encountered errors during operation.");
        return EXIT_CODE_BOOTSTRAP_ERROR;
      }
    } catch (Exception e) {
      e.printStackTrace(spec.commandLine().getErr());
      spec.commandLine().getErr().println("Bootstrap encountered errors during operation.");
      return EXIT_CODE_BOOTSTRAP_ERROR;
    }
  }