Class SecretsLifecycle
java.lang.Object
com.iizix.server.secrets.SecretsLifecycle
The life cycle of this process's secrets store (
SECRETS-STORE-DESIGN.md section 7, build order SK-3): which store is installed in SecretsStores, when it is opened, and when it is disposed of. One store per process.- iiziServer, production and development:
installServerStore(PropFactory)inJettyRunConfigurationafter the run mode and the logging are set, before any configuration file is loaded;dispose()inServerShell.disposeafter every consumer is gone and before the server logger closes. The store's change listener takes the values another process writes into the loaded properties (P-9 (a),SecretsContexts.storeChanged(Set)). - iiziGo:
installDesignerStore(PropFactory)at start;dispose()at stop, after the projects are disposed of and before the console stops. The Designer does not take other processes' changes into loaded properties: it never overwrites them either, since a save commits only the values it changed (decision SK3-D-6).
Opened at the first secret (decision SK3-D-2): the installed store opens the file at the first secret-marked member resolved or the first value committed. A process whose files mark nothing never creates the store's directory or lock file - an iiziGo, a server without secrets, and every test rig that starts a server through JettyRunConfiguration. A file that cannot be opened is SEVERE once, and the process runs without a store: every secret-marked member stays unconfigured, reported once per key per load (P-15).
Whoever saves a file that holds secrets calls SecretsContexts.commit(PropCnr) and then flush(): a save is an explicit act, and a development server launched right after it must read the values (decision SK3-D-7).
Thread-safe.
- Author:
- Christopher Mindus
Method Summary
Modifier and TypeMethodDescriptionstatic voiddispose()Disposes of the store this class installed: uninstalls it, unless another store replaced it meanwhile, and disposes of it, which writes what is pending.static SecretsStorefileStore(ISecretsStore store) Gets the file store behind a store: the store itself when it is aSecretsStore, the file store a lazy store of this class has opened, else null - a store of another class, or a lazy store that has not opened its file yet.static booleanflush()Writes the pending changes of the installed store now, when this class installed it and it is open.static ISecretsStoreGets the store this class installed.static ISecretsStoreinstallDesignerStore(PropFactory factory) Installs the store of iiziGo: this machine's file, opened at its first use.static ISecretsStoreinstallDesignerStore(Path file, PropFactory factory, long flushDelay, boolean watch) Installs the store of iiziGo, opened at its first use; seeinstallDesignerStore(PropFactory).static ISecretsStoreinstallServerStore(PropFactory factory) Installs the store of a server: this machine's file - named by-D"iizi.secrets.file", else the default belowuser.home- with the flush delay of 10000L ms and a watcher, opened at its first use, its change listener taking other processes' changes into the loaded properties.static ISecretsStoreinstallServerStore(Path file, PropFactory factory, long flushDelay, boolean watch) Installs the store of a server, opened at its first use; seeinstallServerStore(PropFactory).static SecretsStoreopenServerStore(Path file, PropFactory factory, long flushDelay, boolean watch) Opens a store file at once and installs it, with the server's change listener: for a process that needs the file now, such as the command-line tool.
Method Details
installServerStore
Installs the store of a server: this machine's file - named by-D"iizi.secrets.file", else the default belowuser.home- with the flush delay of 10000L ms and a watcher, opened at its first use, its change listener taking other processes' changes into the loaded properties. A store this class installed before is disposed of first.- Parameters:
factory- The server's property factory.- Returns:
- The installed store, not opened yet.
installServerStore
public static ISecretsStore installServerStore(Path file, PropFactory factory, long flushDelay, boolean watch) Installs the store of a server, opened at its first use; seeinstallServerStore(PropFactory).- Parameters:
file- The store file, null for this machine's: read when the store is opened.factory- The server's property factory.flushDelay- The flush delay in milliseconds.watch- true to watch the file for other processes' changes.- Returns:
- The installed store, not opened yet.
installDesignerStore
Installs the store of iiziGo: this machine's file, opened at its first use. A store this class installed before is disposed of first.- Parameters:
factory- The Designer's property factory.- Returns:
- The installed store, not opened yet.
installDesignerStore
public static ISecretsStore installDesignerStore(Path file, PropFactory factory, long flushDelay, boolean watch) Installs the store of iiziGo, opened at its first use; seeinstallDesignerStore(PropFactory).- Parameters:
file- The store file, null for this machine's: read when the store is opened.factory- The Designer's property factory.flushDelay- The flush delay in milliseconds.watch- true to watch the file for other processes' changes.- Returns:
- The installed store, not opened yet.
openServerStore
public static SecretsStore openServerStore(Path file, PropFactory factory, long flushDelay, boolean watch) Opens a store file at once and installs it, with the server's change listener: for a process that needs the file now, such as the command-line tool. A store this class installed before is disposed of first.- Parameters:
file- The store file.factory- The property factory.flushDelay- The flush delay in milliseconds.watch- true to watch the file for other processes' changes.- Returns:
- The store, or null when it cannot be opened (logged SEVERE): the process runs without one.
flush
public static boolean flush()Writes the pending changes of the installed store now, when this class installed it and it is open.- Returns:
- true when nothing is pending afterwards, false when the flush failed (logged SEVERE by the store, the changes kept) or the store is read-only with changes.
dispose
public static void dispose()Disposes of the store this class installed: uninstalls it, unless another store replaced it meanwhile, and disposes of it, which writes what is pending. Idempotent; does nothing when this class installed no store.getInstalled
Gets the store this class installed.- Returns:
- The store, null for none.
fileStore
Gets the file store behind a store: the store itself when it is aSecretsStore, the file store a lazy store of this class has opened, else null - a store of another class, or a lazy store that has not opened its file yet. For a caller that needs what theISecretsStorecontract does not give, thekindof an entry, after a read that opened the store (CC-FIX-DBCONF-SECRET-PASSWORD-KIND: the kind of adbconf.propertiespassword was read only from the file store class, never through the lazy store a server installs, and a password entry reached the pool obfuscated).- Parameters:
store- The store, null for none.- Returns:
- The file store, or null.