use of org.springframework.vault.core.VaultOperations in project spring-vault by spring-projects.
the class KeyValueV2 method versionedApi.
void versionedApi() {
// tag::versionedApi[]
VaultOperations operations = new VaultTemplate(new VaultEndpoint());
VaultVersionedKeyValueOperations versionedOperations = operations.opsForVersionedKeyValue("secret");
Versioned.Metadata metadata = // <1>
versionedOperations.put(// <1>
"elvis", Collections.singletonMap("social-security-number", "409-52-2002"));
// <2>
Version version = metadata.getVersion();
// <3>
Versioned<Object> ssn = versionedOperations.get("elvis", Version.from(42));
Versioned<SocialSecurityNumber> mappedSsn = // <4>
versionedOperations.get(// <4>
"elvis", Version.from(42), SocialSecurityNumber.class);
Versioned<Map<String, String>> versioned = Versioned.create(// <5>
Collections.singletonMap("social-security-number", "409-52-2002"), Version.from(42));
versionedOperations.put("elvis", version);
// end::versionedApi[]
}
use of org.springframework.vault.core.VaultOperations in project spring-vault by spring-projects.
the class KeyValueV2 method vaultOperations.
void vaultOperations() {
// tag::vaultOperations[]
VaultOperations operations = new VaultTemplate(new VaultEndpoint());
operations.write("secret/data/elvis", Collections.singletonMap("data", Collections.singletonMap("social-security-number", "409-52-2002")));
VaultResponse read = operations.read("secret/data/ykey");
Map<String, String> data = (Map<String, String>) read.getRequiredData().get("data");
data.get("social-security-number");
// end::vaultOperations[]
}
use of org.springframework.vault.core.VaultOperations in project spring-vault by spring-projects.
the class KeyValueV2 method keyValueApi.
void keyValueApi() {
// tag::keyValueApi[]
VaultOperations operations = new VaultTemplate(new VaultEndpoint());
VaultKeyValueOperations keyValueOperations = operations.opsForKeyValue("secret", VaultKeyValueOperationsSupport.KeyValueBackend.KV_2);
keyValueOperations.put("elvis", Collections.singletonMap("social-security-number", "409-52-2002"));
VaultResponse read = keyValueOperations.get("elvis");
read.getRequiredData().get("social-security-number");
// end::keyValueApi[]
}
use of org.springframework.vault.core.VaultOperations in project spring-vault by spring-projects.
the class PKI method pkiApi.
void pkiApi() {
// tag::pkiApi[]
VaultOperations operations = new VaultTemplate(new VaultEndpoint());
VaultPkiOperations pkiOperations = operations.opsForPki("pki");
VaultCertificateRequest request = // <1>
VaultCertificateRequest.builder().ttl(Duration.ofHours(48)).altNames(Arrays.asList("prod.dc-1.example.com", "prod.dc-2.example.com")).withIpSubjectAltName("1.2.3.4").commonName("hello.example.com").build();
// <2>
VaultCertificateResponse response = pkiOperations.issueCertificate("production", request);
CertificateBundle certificateBundle = response.getRequiredData();
// <3>
KeyStore keyStore = certificateBundle.createKeyStore("my-keystore");
// <4>
KeySpec privateKey = certificateBundle.getPrivateKeySpec();
X509Certificate certificate = certificateBundle.getX509Certificate();
X509Certificate caCertificate = certificateBundle.getX509IssuerCertificate();
// <5>
pkiOperations.revoke(certificateBundle.getSerialNumber());
// end::pkiApi[]
}
use of org.springframework.vault.core.VaultOperations in project spring-vault by spring-projects.
the class Token method tokenApi.
void tokenApi() {
// tag::tokenApi[]
VaultOperations operations = new VaultTemplate(new VaultEndpoint());
VaultTokenOperations tokenOperations = operations.opsForToken();
// <1>
VaultTokenResponse tokenResponse = tokenOperations.create();
VaultToken justAToken = tokenResponse.getToken();
VaultTokenRequest tokenRequest = VaultTokenRequest.builder().withPolicy("policy-for-myapp").displayName("Access tokens for myapp").renewable().ttl(Duration.ofHours(1)).build();
// <2>
VaultTokenResponse appTokenResponse = tokenOperations.create(tokenRequest);
VaultToken appToken = appTokenResponse.getToken();
// <3>
tokenOperations.renew(appToken);
// <4>
tokenOperations.revoke(appToken);
// end::tokenApi[]
}
Aggregations