/** * Deletes the element with the given name. An IOException is thrown if the key does not exist. We can not check the * existence of the key and then delete it atomically. So, there is no easy way to disambiguate between the key * not existing or a failure to delete because of some other reason apart from the message in the exception. * @param namespace The namespace this key belongs to. * @param name Name of the element to be deleted. * @throws NamespaceNotFoundException If the specified namespace does not exist. * @throws IOException If it failed to delete the key in the store. Unfortunately KeyProvider does not specify * the underlying cause except in the message, so we can not throw a more specific exception. */ @Override public void delete(String namespace, String name) throws Exception { checkNamespaceExists(namespace); try { provider.deleteKey(getKeyName(namespace, name)); } catch (IOException e) { throw new IOException("Failed to delete the key " + name + " under namespace " + namespace, e); } }
checkNamespaceExists(namespace); String prefix = namespace + NAME_SEPARATOR; List<String> keysInNamespace = new ArrayList<>();
public void put(String namespace, String name, String data, @Nullable String description, Map<String, String> properties) throws Exception { checkNamespaceExists(namespace); String keyName = getKeyName(namespace, name); if (provider.getMetadata(keyName) != null) {
/** * Returns the data stored in the secure store. Makes two calls to the provider, one to get the metadata and another * to get the data. * @param namespace The namespace this key belongs to. * @param name Name of the key. * @return An object representing the securely stored data associated with the name. * @throws NamespaceNotFoundException If the specified namespace does not exist. * @throws IOException If there was a problem getting the key or the metadata from the underlying key provider. */ // Unfortunately KeyProvider does not specify the underlying cause except in the message, so we can not throw a // more specific exception. @Override public SecureStoreData get(String namespace, String name) throws Exception { checkNamespaceExists(namespace); String keyName = getKeyName(namespace, name); KeyProvider.Metadata metadata = provider.getMetadata(keyName); // Provider returns null if the key is not found. if (metadata == null) { throw new NotFoundException(new SecureKeyId(namespace, name)); } SecureStoreMetadata meta = new SecureStoreMetadata(name, metadata.getDescription(), metadata.getCreated().getTime(), metadata.getAttributes()); KeyProvider.KeyVersion keyVersion = provider.getCurrentKey(keyName); return new SecureStoreData(meta, keyVersion.getMaterial()); }