public static void main()

in sources/src/main/java/com/google/solutions/jitaccess/Main.java [44:105]


  public static void main(String... args) {
    try {
      //
      // Create a logger. We can't rely on CDI injection as we're not
      // in a CDI context here.
      //
      var logger = new StructuredLogger(System.out);
      var configuration = new ApplicationConfiguration(System.getenv());

      if (!configuration.isSmtpConfigured()) {
        logger.warn(
          EventIds.STARTUP,
          "The SMTP configuration is incomplete");
      }

      var runtime = ApplicationRuntime.detect(new HashSet<>(List.of(
        IamCredentialsClient.OAUTH_SCOPE,
        SecretManagerClient.OAUTH_SCOPE,
        CloudIdentityGroupsClient.OAUTH_GROUPS_SCOPE,
        CloudIdentityGroupsClient.OAUTH_SETTINGS_SCOPE)));

      //
      // Eagerly initialize the application so that we can fail
      // fast if the configuration is incomplete or invalid.
      //
      // If we relied on CDI to trigger initialization, any
      // configuration issue would cause a failed injection,
      // which in turn produces long, difficult to interpret
      // stack traces.
      //
      Application.initialize(runtime, configuration, logger);

      if (runtime.type() == ApplicationRuntime.Type.DEVELOPMENT) {
        logger.warn(
          EventIds.STARTUP,
          String.format("Running in development mode as %s", runtime.applicationPrincipal()));
      }
      else {
        logger.info(
          EventIds.STARTUP,
          String.format("Running in project %s (%s) as %s, version %s",
            runtime.projectId(),
            runtime.projectNumber(),
            runtime.applicationPrincipal(),
            ApplicationVersion.VERSION_STRING));
      }
    }
    catch (Throwable e) {
      System.err.printf(
        "The application encountered a fatal error during initialization, aborting startup: %s\n\n",
        Exceptions.fullMessage(e));
      e.printStackTrace(System.err);
      System.exit(1);
    }

    //
    // Initialize Quarkus. This will cause the JAX-RS
    // resources to be loaded, which in turn kicks off
    // a cascade of CDI injections.
    //
    Quarkus.run(Main.class, args);
  }