@Override public String getDescription() { return String.format("Azure storage account file resource [container='%s', file='%s']", this.fileShare.getName(), this.cloudFile.getName()); }
/** * Returns the canonical name for shared access. * * @return the canonical name for shared access. */ private String getSharedAccessCanonicalName() { String accountName = this.getServiceClient().getCredentials().getAccountName(); String shareName = this.getName(); return String.format("/%s/%s/%s", SR.FILE, accountName, shareName); }
/** * Returns the canonical name for shared access. * * @return the canonical name for shared access. */ private String getSharedAccessCanonicalName() { String accountName = this.getServiceClient().getCredentials().getAccountName(); String shareName = this.getName(); return String.format("/%s/%s/%s", SR.FILE, accountName, shareName); }
String shareName = share.getName() + delimiter;
String shareName = share.getName() + delimiter;
@Override public CloudFileShare preProcessResponse(CloudFileShare share, CloudFileClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_CREATED) { this.setNonExceptionedRetryableFailure(true); return null; } final String snapshotTime = FileResponse.getSnapshotTime(this.getConnection()); CloudFileShare snapshot = new CloudFileShare(share.getName(), snapshotTime, client); snapshot.setProperties(new FileShareProperties(share.properties)); // use the specified metadata if not null : otherwise share's metadata snapshot.setMetadata(metadata != null ? metadata : share.metadata); snapshot.updatePropertiesFromResponse(this.getConnection()); return snapshot; } };
@Override public CloudFileShare preProcessResponse(CloudFileShare share, CloudFileClient client, OperationContext context) throws Exception { if (this.getResult().getStatusCode() != HttpURLConnection.HTTP_CREATED) { this.setNonExceptionedRetryableFailure(true); return null; } final String snapshotTime = FileResponse.getSnapshotTime(this.getConnection()); CloudFileShare snapshot = new CloudFileShare(share.getName(), snapshotTime, client); snapshot.setProperties(new FileShareProperties(share.properties)); // use the specified metadata if not null : otherwise share's metadata snapshot.setMetadata(metadata != null ? metadata : share.metadata); snapshot.updatePropertiesFromResponse(this.getConnection()); return snapshot; } };
boolean snapshotFound = false; for (CloudFileShare listShareItem : listResult) { if (listShareItem.getName().equals(share.getName()) && !listShareItem.isSnapshot() && !originalFound) { count++; originalFound = true; assertEquals(share.getMetadata(), listShareItem.getMetadata()); assertEquals(share.getStorageUri(), listShareItem.getStorageUri()); } else if (listShareItem.getName().equals(share.getName()) && listShareItem.isSnapshot() && !snapshotFound) { count++;
CloudFileShare share2 = client.getShareReference(this.share.getName()); assertPermissionsEqual(permissions, share2.downloadPermissions());
@Test public void testFileSAS() throws InvalidKeyException, IllegalArgumentException, StorageException, URISyntaxException, InterruptedException { SharedAccessFilePolicy policy = createSharedAccessPolicy( EnumSet.of(SharedAccessFilePermissions.READ, SharedAccessFilePermissions.LIST), 300); FileSharePermissions perms = new FileSharePermissions(); perms.getSharedAccessPolicies().put("readperm", policy); this.share.uploadPermissions(perms); Thread.sleep(30000); CloudFile sasFile = new CloudFile( new URI(this.file.getUri().toString() + "?" + this.file.generateSharedAccessSignature(null, "readperm"))); sasFile.download(new ByteArrayOutputStream()); // do not give the client and check that the new file's client has the correct permissions CloudFile fileFromUri = new CloudFile(PathUtility.addToQuery(this.file.getStorageUri(), this.file.generateSharedAccessSignature(null, "readperm"))); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), fileFromUri.getServiceClient().getCredentials().getClass().toString()); // create credentials from sas StorageCredentials creds = new StorageCredentialsSharedAccessSignature( this.file.generateSharedAccessSignature(policy, null, null)); CloudFileClient client = new CloudFileClient(sasFile.getServiceClient().getStorageUri(), creds); CloudFile fileFromClient = client.getShareReference(this.file.getShare().getName()).getRootDirectoryReference() .getFileReference(this.file.getName()); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), fileFromClient.getServiceClient().getCredentials().getClass().toString()); assertEquals(client, fileFromClient.getServiceClient()); }
share.downloadAttributes(); assertEquals(CloudFileShare.class, share.getClass()); shareList.remove(share.getName()); share.delete();
/** * Test that Share Quota can be set, but only to allowable values. * * @throws StorageException * @throws URISyntaxException */ @Test public void testCloudFileShareQuotaListing() throws StorageException, URISyntaxException { int shareQuota = 16; this.share.getProperties().setShareQuota(shareQuota); this.share.createIfNotExists(); Iterable<CloudFileShare> shares = this.share.getServiceClient().listShares(this.share.getName()); for (CloudFileShare fileShare : shares) { assertEquals(shareQuota, fileShare.getProperties().getShareQuota().intValue()); } }
assertEquals("value1", this.share.getMetadata().get("key1")); CloudFileShare share2 = this.share.getServiceClient().getShareReference(this.share.getName()); share2.downloadAttributes(); assertEquals(1, share2.getMetadata().size()); assertEquals("value2", this.share.getMetadata().get("key2")); Iterable<CloudFileShare> shares = this.share.getServiceClient().listShares(this.share.getName(), EnumSet.of(ShareListingDetails.METADATA), null, null);
CloudFileClient client = new CloudFileClient(this.share.getServiceClient().getStorageUri(), creds); CloudFileShare shareFromClient = client.getShareReference(readListShare.getName()); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), shareFromClient.getServiceClient().getCredentials().getClass().toString());
URI sasUri = sasClient.getShareReference(share.getName()).getUri(); sasUri = sasClient.getCredentials().transformUri(sasUri); final CloudFileShare sasShare = new CloudFileShare(sasUri); (policy.getPermissions().contains(SharedAccessAccountPermissions.LIST))) { assertEquals(sasShare.getName(), sasClient.listShares(sasShare.getName()).iterator().next().getName()); sasClient.listShares(sasShare.getName()).iterator().next(); fail(); assertEquals(sasShare.getName(), this.fileClient.listShares(sasShare.getName()).iterator().next().getName());