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.version.access()
Retrieves the value from a version 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 contents = secrets.latest().access();
System.out.println(contents.toString());
Nitric.INSTANCE.run();
}
}
Examples
Access the latest version 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 contents = secrets.latest().access();
System.out.println(contents.toString());
Nitric.INSTANCE.run();
}
}
Access a specific version 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 contents = secrets.version("the-version-id").access();
System.out.println(contents.toString());
Nitric.INSTANCE.run();
}
}