mirror of
https://github.com/valitydev/adapter-common-lib.git
synced 2024-11-06 02:05:18 +00:00
add write version secret (#58)
Co-authored-by: ggmaleva <ggmaleva@yandex.ru>
This commit is contained in:
parent
28aa598613
commit
68ec296ea6
2
pom.xml
2
pom.xml
@ -12,7 +12,7 @@
|
||||
</parent>
|
||||
|
||||
<artifactId>adapter-common-lib</artifactId>
|
||||
<version>1.2.11</version>
|
||||
<version>1.2.12</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>adapter-common-lib</name>
|
||||
|
@ -74,4 +74,13 @@ public interface SecretService {
|
||||
*/
|
||||
void writeSecret(String serviceName, SecretObj secretObj);
|
||||
|
||||
/**
|
||||
* Сохраняет секреты для терминала
|
||||
*
|
||||
* @param serviceName - имя сервиса, для которого сохраняются секреты. Хранится в настройках сервиса.
|
||||
* @param secretObj - объект с секретами, {@link SecretObj}
|
||||
* @return Возвращает версию созданного хранилища для терминала
|
||||
*/
|
||||
Integer writeVersionSecret(String serviceName, SecretObj secretObj);
|
||||
|
||||
}
|
||||
|
@ -70,6 +70,13 @@ public class VaultSecretService implements SecretService {
|
||||
vaultTemplate.opsForVersionedKeyValue(serviceName).put(secretObj.getPath(), secretObj.getValues());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer writeVersionSecret(String serviceName, SecretObj secretObj) {
|
||||
Versioned.Metadata metadata =
|
||||
vaultTemplate.opsForVersionedKeyValue(serviceName).put(secretObj.getPath(), secretObj.getValues());
|
||||
return metadata.getVersion().getVersion();
|
||||
}
|
||||
|
||||
private String getSecretString(String serviceName, SecretRef secretRef) throws SecretNotFoundException {
|
||||
var map = vaultTemplate.opsForVersionedKeyValue(serviceName).get(secretRef.getPath());
|
||||
if (map == null || map.getData() == null || map.getData().get(secretRef.getKey()) == null) {
|
||||
|
@ -144,4 +144,23 @@ public class VaultSecretServiceTest {
|
||||
assertEquals(TOKEN_EXP_DATE_VALUE, secret.get(TOKEN_EXP_DATE).getValue());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void writeMultipleVersionSecret() {
|
||||
SecretObj secretObj = new SecretObj(
|
||||
TEST_TOKEN_PATH,
|
||||
Map.of(
|
||||
TOKEN, TOKEN_VALUE,
|
||||
TOKEN_EXP_DATE, TOKEN_EXP_DATE_VALUE
|
||||
)
|
||||
);
|
||||
Integer version = vaultService.writeVersionSecret(SERVICE_NAME, secretObj);
|
||||
|
||||
VersionedSecret versionSecrets = vaultService.getVersionSecrets(SERVICE_NAME, TEST_TOKEN_PATH);
|
||||
|
||||
assertNotNull(versionSecrets);
|
||||
assertEquals(version, versionSecrets.getVersion());
|
||||
assertEquals(TOKEN_VALUE, versionSecrets.getSecretes().get(TOKEN).getValue());
|
||||
assertEquals(TOKEN_EXP_DATE_VALUE, versionSecrets.getSecretes().get(TOKEN_EXP_DATE).getValue());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user