The JVM SDK currently only supports legacy versions of Nitric prior to v1. This version is maintained for compatibility with existing projects and not recommended for new projects. New projects should be started using a supported SDK (presented automatically using the `nitric new` command) orget in touch to request an update to the latest version.
JVM - secret.latest()
Returns a reference to the latest
version of a secret, regardless of that version's ID.
import io.nitric.Nitric;
import io.nitric.resources.SecretPermission;
public class Application {
public static void main(String[] args) {
var secrets = Nitric.INSTANCE.secret("encryptionKey").with(SecretPermission.Access);
var latestRef = secrets.latest();
Nitric.INSTANCE.run();
}
}
Notes
latest()
is most useful when you always want the most recent secret values from the secrets manager. Database credentials and API keys are good examples of secrets where the latest value is usually what you want.
For symmetric encryption, you'll need to retrieve the version of the secret used to encrypt a value when you try to decrypt it again. In those cases latest()
isn't a good choice, use version() instead.
Examples
Get a reference to the latest secret version
import io.nitric.Nitric;
import io.nitric.resources.SecretPermission;
public class Application {
public static void main(String[] args) {
var secrets = Nitric.INSTANCE.secret("encryptionKey").with(SecretPermission.Access);
var latestRef = secrets.latest();
Nitric.INSTANCE.run();
}
}
Access the latest value of a secret
import io.nitric.Nitric;
import io.nitric.resources.SecretPermission;
public class Application {
public static void main(String[] args) {
var secrets = Nitric.INSTANCE.secret("encryptionKey").with(SecretPermission.Access);
var key = secrets.latest().access();
Nitric.INSTANCE.run();
}
}
See secret.version().access() for more details.