我正在研究如何使用 Vault 0.11.1 和 Spring Vault 2.0.2.RELEASE。我已经建立了一个开发保险库:
vault server -dev
并添加了一些数据
vault kv put secret/certs/jan cert=ABCD
我可以用 Spring Vault 阅读
@Autowired
private VaultOperations operations;
String path = "secret/data/certs/jan";
System.out.println(operations.read(path).getData());
请注意,奇怪的是,我必须在路径中插入“data/”才能再次找到它。
删除数据也可以正常工作:
operations.delete(path);
但是用
Secret secret = new Secret("ABCD");
operations.write(path, secret);
失败了
org.springframework.vault.VaultException: Status 400 secret/data/certs/jan: no data provided
Secret 是一个简单的 bean:
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Secret {
String cert;
}
并且 jason 转换似乎很顺利:
DEBUG org.springframework.web.client.RestTemplate - Writing [Secret(cert=ABCD)] using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@add0edd]
只是试图写一个字符串
operations.write(path, "foo=bar");
也失败了:
Status 400 secret/data/certs/jan: failed to parse JSON input: invalid character 'o' in literal false (expecting 'a')