use of com.microsoft.azure.storage.SharedAccessAccountPolicy in project beam by apache.
the class AzureBlobStoreFileSystem method generateSasToken.
@VisibleForTesting
/**
* Generate an SAS Token if the user did not provide one through pipeline options
*/
String generateSasToken() throws IOException {
if (!Strings.isNullOrEmpty(options.getSasToken())) {
return options.getSasToken();
}
SharedAccessAccountPolicy sharedAccessAccountPolicy = new SharedAccessAccountPolicy();
long date = new Date().getTime();
long expiryDate = new Date(date + DEFAULT_EXPIRY_TIME).getTime();
sharedAccessAccountPolicy.setPermissionsFromString(DEFAULT_PERMISSIONS);
sharedAccessAccountPolicy.setSharedAccessStartTime(new Date(date));
sharedAccessAccountPolicy.setSharedAccessExpiryTime(new Date(expiryDate));
sharedAccessAccountPolicy.setResourceTypeFromString(DEFAULT_RESOURCE_TYPES);
sharedAccessAccountPolicy.setServiceFromString(DEFAULT_SERVICES);
String storageConnectionString;
if (!Strings.isNullOrEmpty(options.getAzureConnectionString())) {
storageConnectionString = options.getAzureConnectionString();
} else if (!Strings.isNullOrEmpty(options.getAccessKey())) {
storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=" + client.get().getAccountName() + ";AccountKey=" + options.getAccessKey() + ";EndpointSuffix=core.windows.net";
} else {
throw new IOException("Copying blobs requires that a SAS token, connection string, or account key be provided.");
}
try {
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
return "?" + storageAccount.generateSharedAccessSignature(sharedAccessAccountPolicy);
} catch (Exception e) {
throw (IOException) e.getCause();
}
}
use of com.microsoft.azure.storage.SharedAccessAccountPolicy in project hadoop by apache.
the class LocalSASKeyGeneratorImpl method getDefaultAccountAccessPolicy.
/**
* Helper method to generate Access Policy for the Storage Account SAS Key
* @return SharedAccessAccountPolicy
*/
private SharedAccessAccountPolicy getDefaultAccountAccessPolicy() {
SharedAccessAccountPolicy ap = new SharedAccessAccountPolicy();
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
cal.setTime(new Date());
cal.add(Calendar.HOUR, (int) getSasKeyExpiryPeriod() * HOURS_IN_DAY);
ap.setSharedAccessExpiryTime(cal.getTime());
ap.setPermissions(getDefaultAccoutSASKeyPermissions());
ap.setResourceTypes(EnumSet.of(SharedAccessAccountResourceType.CONTAINER, SharedAccessAccountResourceType.OBJECT));
ap.setServices(EnumSet.of(SharedAccessAccountService.BLOB));
return ap;
}
Aggregations