================================================================
Apinizer API Portal - Standalone Distribution
================================================================

This package is self-contained; Java is NOT required on the target
machine. A bundled OpenJDK (Temurin) runtime ships inside runtime/.

Directory layout:
  bin/       Start/stop/install/encrypt scripts and systemd unit
  conf/      Configuration files (application.env, master.key)
  lib/       Spring Boot application jar (and lib/jasypt/ helper jar)
  runtime/   Bundled OpenJDK 25 (Temurin) JRE
  logs/      Runtime logs (created automatically on first start)

------------------------------------------------------------
1. Installation (one-time, requires sudo)
------------------------------------------------------------
The installer creates a dedicated 'apinizer' system user, sets
correct permissions, generates a random Jasypt master key, and
registers a systemd service. It needs root privileges via sudo —
no interactive root login is required.

  sudo ./bin/apiportal-install.sh

To delegate this to a non-root operator, add a sudoers entry:
  apinizer-admin ALL=(root) NOPASSWD: /opt/apinizer-portal/bin/apiportal-install.sh

------------------------------------------------------------
2. Configuration
------------------------------------------------------------
Edit conf/application.env and provide the following REQUIRED
parameters:

  API_PORTAL_ID
  API_PORTAL_MANAGEMENT_API_BASE_URL
  API_PORTAL_MANAGEMENT_API_KEY

If any of these values is missing, the application refuses to start
and prints a clear error message before exiting.

------------------------------------------------------------
3. Encrypting sensitive values (recommended for finance / regulated
   environments)
------------------------------------------------------------
Sensitive values such as API keys and keystore passwords can be
encrypted at rest using the Jasypt master key generated by the
installer (conf/master.key, AES-256, readable only by the
'apinizer' user).

To encrypt a value:
  ./bin/apiportal-encrypt.sh '<plaintext>'

Example:
  $ ./bin/apiportal-encrypt.sh 'mySecret123'
  ENC(eXq1J9z...kTu4=)

Paste the ENC(...) output into application.env in place of the
plaintext value:
  API_PORTAL_MANAGEMENT_API_KEY=ENC(eXq1J9z...kTu4=)

Plain (unencrypted) values continue to work, so encryption is
opt-in per field.

NOTES:
  - The master key file (conf/master.key) is the decryption key.
    Back it up securely. If lost, all ENC(...) values must be
    re-encrypted with a freshly generated key.
  - Never commit master.key to version control.
  - For a key rotation, re-run apiportal-encrypt.sh with the new
    key and replace all ENC(...) values in application.env.

------------------------------------------------------------
4. Starting and stopping (Linux / macOS)
------------------------------------------------------------
Via systemd (recommended after install):
  sudo systemctl start apinizer-apiportal
  sudo systemctl stop  apinizer-apiportal
  sudo systemctl status apinizer-apiportal
  sudo journalctl -u apinizer-apiportal -f

Manual:
  cd <APP_HOME>
  ./bin/apiportal-start.sh               # background, writes PID file
  ./bin/apiportal-start.sh --foreground  # foreground (debug)
  ./bin/apiportal-stop.sh                # graceful shutdown

Logs are written to the logs/ directory:
  - logs/apinizer-apiportal.out  (stdout/stderr)
  - logs/apinizer-apiportal.log  (logback)
  - logs/apinizer-apiportal.pid  (PID file)

------------------------------------------------------------
5. Configuration precedence (highest to lowest)
------------------------------------------------------------
  1) Environment variable    (export API_PORTAL_ID=...)
  2) conf/application.env    (ENC(...) values decrypted at startup)

------------------------------------------------------------
6. Version
------------------------------------------------------------
  bin/apiportal-start.sh --foreground 2>&1 | head -n 50
  The startup banner prints the Spring Boot and application version.
