Java Code Examples for org.springframework.vault.support.Versioned#Metadata
The following examples show how to use
org.springframework.vault.support.Versioned#Metadata .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyValueOperationsDelegateTest.java From tessera with Apache License 2.0 | 6 votes |
@Test public void set() { String secretName = "secretName"; HashicorpSetSecretData setSecretData = mock(HashicorpSetSecretData.class); when(setSecretData.getSecretName()).thenReturn(secretName); Map nameValuePairs = mock(Map.class); when(setSecretData.getNameValuePairs()).thenReturn(nameValuePairs); Versioned.Metadata metadata = mock(Versioned.Metadata.class); when(keyValueOperations.put(secretName, nameValuePairs)).thenReturn(metadata); Versioned.Metadata result = delegate.set(setSecretData); verify(keyValueOperations).put(secretName, nameValuePairs); assertThat(result).isEqualTo(metadata); }
Example 2
Source File: VaultKeyValueMetadataTemplateIntegrationTests.java From spring-vault with Apache License 2.0 | 6 votes |
@Test void shouldReadMetadataForANewKVEntry() { VaultMetadataResponse metadataResponse = this.vaultKeyValueMetadataOperations.get(SECRET_NAME); assertThat(metadataResponse.getMaxVersions()).isEqualTo(0); assertThat(metadataResponse.getCurrentVersion()).isEqualTo(1); assertThat(metadataResponse.getVersions()).hasSize(1); assertThat(metadataResponse.isCasRequired()).isFalse(); assertThat(metadataResponse.getCreatedTime().isBefore(Instant.now())).isTrue(); assertThat(metadataResponse.getUpdatedTime().isBefore(Instant.now())).isTrue(); Versioned.Metadata version1 = metadataResponse.getVersions().get(0); if (prepare().getVersion().isGreaterThanOrEqualTo(Version.parse("1.2.0"))) { assertThat(metadataResponse.getDeleteVersionAfter()).isEqualTo(Duration.ZERO); assertThat(version1.getDeletedAt()).isNull(); assertThat(version1.getCreatedAt()).isBefore(Instant.now()); } assertThat(version1.getVersion().getVersion()).isEqualTo(1); }
Example 3
Source File: HashicorpKeyVaultServiceTest.java From tessera with Apache License 2.0 | 5 votes |
@Test public void setSecretReturnsMetadataObject() { HashicorpSetSecretData setSecretData = new HashicorpSetSecretData("engine", "name", Collections.emptyMap()); Versioned.Metadata metadata = mock(Versioned.Metadata.class); when(delegate.set(setSecretData)).thenReturn(metadata); Object result = keyVaultService.setSecret(setSecretData); assertThat(result).isInstanceOf(Versioned.Metadata.class); assertThat(result).isEqualTo(metadata); }
Example 4
Source File: VaultKeyValueMetadataTemplate.java From spring-vault with Apache License 2.0 | 5 votes |
private static Versioned.Metadata buildVersion(String version, Map<String, Object> versionData) { Instant createdTime = toInstant((String) versionData.get("created_time")); Instant deletionTime = toInstant((String) versionData.get("deletion_time")); boolean destroyed = (Boolean) versionData.get("destroyed"); Versioned.Version kvVersion = Versioned.Version.from(Integer.parseInt(version)); return Versioned.Metadata.builder().createdAt(createdTime).deletedAt(deletionTime).destroyed(destroyed) .version(kvVersion).build(); }
Example 5
Source File: VaultKeyValueMetadataTemplateIntegrationTests.java From spring-vault with Apache License 2.0 | 5 votes |
@Test void shouldDeleteMetadata() { this.kvOperations.delete(SECRET_NAME); VaultMetadataResponse metadataResponse = this.vaultKeyValueMetadataOperations.get(SECRET_NAME); Versioned.Metadata version1 = metadataResponse.getVersions().get(0); assertThat(version1.getDeletedAt()).isBefore(Instant.now()); this.vaultKeyValueMetadataOperations.delete(SECRET_NAME); VaultResponse response = this.kvOperations.get(SECRET_NAME); assertThat(response).isNull(); }
Example 6
Source File: KeyValueOperationsDelegate.java From tessera with Apache License 2.0 | 4 votes |
Versioned.Metadata set(HashicorpSetSecretData setSecretData) { return keyValueOperations.put(setSecretData.getSecretName(), setSecretData.getNameValuePairs()); }
Example 7
Source File: VaultKeyValueMetadataTemplate.java From spring-vault with Apache License 2.0 | 4 votes |
private static List<Versioned.Metadata> buildVersions(Map<String, Map<String, Object>> versions) { return versions.entrySet().stream().map(entry -> buildVersion(entry.getKey(), entry.getValue())) .collect(Collectors.toList()); }