Manage 'secret' property internally in S3/AzureDataStore
Azure - Closing stream and rereading the stored value such that the only key associated with the actual stored value used
@@ -267,12 +267,11 @@ public class AzureBlobStoreBackend extends AbstractSharedBackend {
} else {
byte[] key;
// Try reading from the metadata folder if it exists
- DataRecord rec = getMetadataRecord(REF_KEY);
- if (rec != null) {
- key = IOUtils.toByteArray(rec.getStream());
- } else {
+ key = readMetadataBytes(REF_KEY);
+ if (key == null) {
key = super.getOrCreateReferenceKey();
addMetadataRecord(new ByteArrayInputStream(key), REF_KEY);
+ key = readMetadataBytes(REF_KEY);
}
secret = key;
return secret;
@@ -282,6 +281,21 @@ public class AzureBlobStoreBackend extends AbstractSharedBackend {
}
}
+ private byte[] readMetadataBytes(String name) throws IOException, DataStoreException {
+ DataRecord rec = getMetadataRecord(name);
+ byte[] key = null;
+ if (rec != null) {
+ InputStream stream = null;
+ try {
+ stream = rec.getStream();
+ return IOUtils.toByteArray(stream);
+ } finally {
+ IOUtils.closeQuietly(stream);
+ }
+ }
+ return key;
+ }
+
@Override
public DataRecord getRecord(DataIdentifier identifier) throws DataStoreException {
if (null == identifier) {
