diff --git a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakePathAsyncClient.java b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakePathAsyncClient.java index 7ea9eba95b8c..3c98de200e06 100644 --- a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakePathAsyncClient.java +++ b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakePathAsyncClient.java @@ -52,6 +52,9 @@ import com.azure.storage.file.datalake.models.DataLakeAclChangeFailedException; import com.azure.storage.file.datalake.models.DataLakeRequestConditions; import com.azure.storage.file.datalake.models.DataLakeStorageException; +import com.azure.storage.file.datalake.models.LeaseDurationType; +import com.azure.storage.file.datalake.models.LeaseStatusType; +import com.azure.storage.file.datalake.models.LeaseStateType; import com.azure.storage.file.datalake.models.PathAccessControl; import com.azure.storage.file.datalake.models.PathAccessControlEntry; import com.azure.storage.file.datalake.models.PathHttpHeaders; @@ -59,6 +62,7 @@ import com.azure.storage.file.datalake.models.PathItem; import com.azure.storage.file.datalake.models.PathPermissions; import com.azure.storage.file.datalake.models.PathProperties; +import com.azure.storage.file.datalake.models.PathStatus; import com.azure.storage.file.datalake.models.PathRemoveAccessControlEntry; import com.azure.storage.file.datalake.models.UserDelegationKey; import com.azure.storage.file.datalake.options.DataLakePathCreateOptions; @@ -1603,6 +1607,87 @@ Mono> getAccessControlWithResponse(boolean userPrinc response.getDeserializedHeaders().getXMsGroup(), response.getDeserializedHeaders().getXMsOwner()))); } + /** + * Returns the system defined properties for a resource. + * + *

Code Samples

+ * + * + *
+     * client.getStatus().subscribe(
+     *     response -> System.out.printf("Creation Time: %s, Group: %s, Owner: %s, Permissions: %s",
+     *         response.getCreationTime(), response.getGroup(),
+     *         response.getOwner(), response.getPermissions()));
+     * 
+ * + * + *

For more information, see the + * Azure Docs

+ * + * @return A response containing the resource status. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getStatus() { + return getStatusWithResponse(null, Context.NONE).flatMap(FluxUtil::toMono); + } + + /** + * Returns the system defined properties for a resource. + * + *

Code Samples

+ * + * + *
+     * DataLakeRequestConditions requestConditions = new DataLakeRequestConditions().setLeaseId(leaseId);
+     *
+     * client.getStatusWithResponse(requestConditions).subscribe(
+     *     response -> System.out.printf("Creation Time: %s, Group: %s, Owner: %s, Permissions: %s",
+     *         response.getValue().getCreationTime(),
+     *         response.getValue().getGroup(), response.getValue().getOwner(), response.getValue().getPermissions()));
+     * 
+ * + * + *

For more information, see the + * Azure Docs

+ * + * @param requestConditions {@link DataLakeRequestConditions} + * @return A response containing the resource status. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getStatusWithResponse(DataLakeRequestConditions requestConditions) { + try { + return withContext(context -> getStatusWithResponse(requestConditions, context)); + } catch (RuntimeException ex) { + return monoError(LOGGER, ex); + } + } + + Mono> getStatusWithResponse(DataLakeRequestConditions requestConditions, Context context) { + requestConditions = requestConditions == null ? new DataLakeRequestConditions() : requestConditions; + + LeaseAccessConditions lac = new LeaseAccessConditions().setLeaseId(requestConditions.getLeaseId()); + ModifiedAccessConditions mac = new ModifiedAccessConditions().setIfMatch(requestConditions.getIfMatch()) + .setIfNoneMatch(requestConditions.getIfNoneMatch()) + .setIfModifiedSince(requestConditions.getIfModifiedSince()) + .setIfUnmodifiedSince(requestConditions.getIfUnmodifiedSince()); + + context = context == null ? Context.NONE : context; + return this.dataLakeStorage.getPaths() + .getPropertiesWithResponseAsync(null, null, PathGetPropertiesAction.GET_STATUS, false, lac, mac, context) + .map(response -> new SimpleResponse<>(response, new PathStatus(response.getDeserializedHeaders().getDate(), + response.getDeserializedHeaders().getLastModified(), response.getDeserializedHeaders().getETag(), + response.getDeserializedHeaders().getContentLength(), + LeaseStatusType.fromString(response.getDeserializedHeaders().getXMsLeaseStatus()), + LeaseStateType.fromString(response.getDeserializedHeaders().getXMsLeaseState()), + LeaseDurationType.fromString(response.getDeserializedHeaders().getXMsLeaseDuration()), + response.getDeserializedHeaders().isServerEncrypted(), + response.getDeserializedHeaders().getXMsEncryptionKeySha256(), + response.getDeserializedHeaders().getXMsEncryptionScope(), + response.getDeserializedHeaders().getXMsEncryptionContext(), + response.getDeserializedHeaders().getXMsOwner(), response.getDeserializedHeaders().getXMsGroup(), + response.getDeserializedHeaders().getXMsPermissions(), response.getDeserializedHeaders().getXMsAcl()))); + } + /** * Package-private rename method for use by {@link DataLakeFileAsyncClient} and {@link DataLakeDirectoryAsyncClient} * diff --git a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakePathClient.java b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakePathClient.java index 4b806ec8aaf2..706da6992c16 100644 --- a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakePathClient.java +++ b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakePathClient.java @@ -47,12 +47,16 @@ import com.azure.storage.file.datalake.models.DataLakeAclChangeFailedException; import com.azure.storage.file.datalake.models.DataLakeRequestConditions; import com.azure.storage.file.datalake.models.DataLakeStorageException; +import com.azure.storage.file.datalake.models.LeaseDurationType; +import com.azure.storage.file.datalake.models.LeaseStatusType; +import com.azure.storage.file.datalake.models.LeaseStateType; import com.azure.storage.file.datalake.models.PathAccessControl; import com.azure.storage.file.datalake.models.PathAccessControlEntry; import com.azure.storage.file.datalake.models.PathHttpHeaders; import com.azure.storage.file.datalake.models.PathInfo; import com.azure.storage.file.datalake.models.PathPermissions; import com.azure.storage.file.datalake.models.PathProperties; +import com.azure.storage.file.datalake.models.PathStatus; import com.azure.storage.file.datalake.models.PathRemoveAccessControlEntry; import com.azure.storage.file.datalake.models.UserDelegationKey; import com.azure.storage.file.datalake.options.DataLakePathCreateOptions; @@ -1371,6 +1375,90 @@ public Response getAccessControlWithResponse(boolean userPrin response.getDeserializedHeaders().getXMsGroup(), response.getDeserializedHeaders().getXMsOwner())); } + /** + * Returns the system defined properties for a resource. + * + *

Code Samples

+ * + * + *
+     * PathStatus response = client.getStatus();
+     * System.out.printf("CreationTime: %s, Group: %s, Owner: %s, Permissions: %s",
+     *     response.getCreationTime(), response.getGroup(),
+     *     response.getOwner(), response.getPermissions());
+     * 
+ * + * + *

For more information, see the + * Azure Docs

+ * + * @return A response containing the resource status. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public PathStatus getStatus() { + return getStatusWithResponse(null, null, Context.NONE).getValue(); + } + + /** + * Returns the system defined properties for a resource. + * + *

Code Samples

+ * + * + *
+     * DataLakeRequestConditions requestConditions = new DataLakeRequestConditions().setLeaseId(leaseId);
+     *
+     * Response<PathStatus> response = client.getStatusWithResponse(
+     *     requestConditions, timeout, new Context(key1, value1));
+     *
+     * PathStatus ps = response.getValue();
+     *
+     * System.out.printf("CreationTime: %s, Group: %s, Owner: %s, Permissions: %s",
+     *     ps.getCreationTime(), ps.getGroup(), ps.getOwner(),
+     *     ps.getPermissions());
+     * 
+ * + * + *

For more information, see the + * Azure Docs

+ * + * @param requestConditions {@link DataLakeRequestConditions} + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @param context Additional context that is passed through the Http pipeline during the service call. + * @return A response containing the resource status. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getStatusWithResponse(DataLakeRequestConditions requestConditions, Duration timeout, + Context context) { + requestConditions = requestConditions == null ? new DataLakeRequestConditions() : requestConditions; + + LeaseAccessConditions lac = new LeaseAccessConditions().setLeaseId(requestConditions.getLeaseId()); + ModifiedAccessConditions mac = new ModifiedAccessConditions().setIfMatch(requestConditions.getIfMatch()) + .setIfNoneMatch(requestConditions.getIfNoneMatch()) + .setIfModifiedSince(requestConditions.getIfModifiedSince()) + .setIfUnmodifiedSince(requestConditions.getIfUnmodifiedSince()); + + Context finalContext = context == null ? Context.NONE : context; + Callable> operation = () -> this.dataLakeStorage.getPaths() + .getPropertiesWithResponse(null, null, PathGetPropertiesAction.GET_STATUS, false, lac, mac, finalContext); + ResponseBase response + = sendRequest(operation, timeout, DataLakeStorageException.class); + + return new SimpleResponse<>(response, + new PathStatus(response.getDeserializedHeaders().getDate(), + response.getDeserializedHeaders().getLastModified(), response.getDeserializedHeaders().getETag(), + response.getDeserializedHeaders().getContentLength(), + LeaseStatusType.fromString(response.getDeserializedHeaders().getXMsLeaseStatus()), + LeaseStateType.fromString(response.getDeserializedHeaders().getXMsLeaseState()), + LeaseDurationType.fromString(response.getDeserializedHeaders().getXMsLeaseDuration()), + response.getDeserializedHeaders().isServerEncrypted(), + response.getDeserializedHeaders().getXMsEncryptionKeySha256(), + response.getDeserializedHeaders().getXMsEncryptionScope(), + response.getDeserializedHeaders().getXMsEncryptionContext(), + response.getDeserializedHeaders().getXMsOwner(), response.getDeserializedHeaders().getXMsGroup(), + response.getDeserializedHeaders().getXMsPermissions(), response.getDeserializedHeaders().getXMsAcl())); + } + Response renameWithResponseWithTimeout(String destinationFileSystem, String destinationPath, DataLakeRequestConditions sourceRequestConditions, DataLakeRequestConditions destinationRequestConditions, Duration timeout, Context context) { diff --git a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/models/PathsGetPropertiesHeaders.java b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/models/PathsGetPropertiesHeaders.java index 5a9ca7cb4486..45376b01e72f 100644 --- a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/models/PathsGetPropertiesHeaders.java +++ b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/models/PathsGetPropertiesHeaders.java @@ -130,6 +130,26 @@ public final class PathsGetPropertiesHeaders { */ private String contentType; + /* + * The x-ms-server-encrypted property. + */ + private Boolean xMsServerEncrypted; + + /* + * The x-ms-encryption-key-sha256 property. + */ + private String xMsEncryptionKeySha256; + + /* + * The x-ms-encryption-scope property. + */ + private String xMsEncryptionScope; + + /* + * The x-ms-encryption-context property. + */ + private String xMsEncryptionContext; + private static final HttpHeaderName X_MS_GROUP = HttpHeaderName.fromString("x-ms-group"); private static final HttpHeaderName X_MS_VERSION = HttpHeaderName.fromString("x-ms-version"); @@ -150,10 +170,19 @@ public final class PathsGetPropertiesHeaders { private static final HttpHeaderName X_MS_OWNER = HttpHeaderName.fromString("x-ms-owner"); + private static final HttpHeaderName X_MS_SERVER_ENCRYPTED = HttpHeaderName.fromString("x-ms-server-encrypted"); + + private static final HttpHeaderName X_MS_ENCRYPTION_KEY_SHA256 + = HttpHeaderName.fromString("x-ms-encryption-key-sha256"); + + private static final HttpHeaderName X_MS_ENCRYPTION_SCOPE = HttpHeaderName.fromString("x-ms-encryption-scope"); + + private static final HttpHeaderName X_MS_ENCRYPTION_CONTEXT = HttpHeaderName.fromString("x-ms-encryption-context"); + // HttpHeaders containing the raw property values. /** * Creates an instance of PathsGetPropertiesHeaders class. - * + * * @param rawHeaders The raw HttpHeaders that will be used to create the property values. */ public PathsGetPropertiesHeaders(HttpHeaders rawHeaders) { @@ -189,11 +218,18 @@ public PathsGetPropertiesHeaders(HttpHeaders rawHeaders) { this.contentLanguage = rawHeaders.getValue(HttpHeaderName.CONTENT_LANGUAGE); this.xMsOwner = rawHeaders.getValue(X_MS_OWNER); this.contentType = rawHeaders.getValue(HttpHeaderName.CONTENT_TYPE); + String xMsServerEncrypted = rawHeaders.getValue(X_MS_SERVER_ENCRYPTED); + if (xMsServerEncrypted != null) { + this.xMsServerEncrypted = Boolean.valueOf(xMsServerEncrypted); + } + this.xMsEncryptionKeySha256 = rawHeaders.getValue(X_MS_ENCRYPTION_KEY_SHA256); + this.xMsEncryptionScope = rawHeaders.getValue(X_MS_ENCRYPTION_SCOPE); + this.xMsEncryptionContext = rawHeaders.getValue(X_MS_ENCRYPTION_CONTEXT); } /** * Get the xMsGroup property: The x-ms-group property. - * + * * @return the xMsGroup value. */ public String getXMsGroup() { @@ -202,7 +238,7 @@ public String getXMsGroup() { /** * Set the xMsGroup property: The x-ms-group property. - * + * * @param xMsGroup the xMsGroup value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -213,7 +249,7 @@ public PathsGetPropertiesHeaders setXMsGroup(String xMsGroup) { /** * Get the xMsVersion property: The x-ms-version property. - * + * * @return the xMsVersion value. */ public String getXMsVersion() { @@ -222,7 +258,7 @@ public String getXMsVersion() { /** * Set the xMsVersion property: The x-ms-version property. - * + * * @param xMsVersion the xMsVersion value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -233,7 +269,7 @@ public PathsGetPropertiesHeaders setXMsVersion(String xMsVersion) { /** * Get the xMsLeaseStatus property: The x-ms-lease-status property. - * + * * @return the xMsLeaseStatus value. */ public String getXMsLeaseStatus() { @@ -242,7 +278,7 @@ public String getXMsLeaseStatus() { /** * Set the xMsLeaseStatus property: The x-ms-lease-status property. - * + * * @param xMsLeaseStatus the xMsLeaseStatus value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -253,7 +289,7 @@ public PathsGetPropertiesHeaders setXMsLeaseStatus(String xMsLeaseStatus) { /** * Get the contentRange property: The Content-Range property. - * + * * @return the contentRange value. */ public String getContentRange() { @@ -262,7 +298,7 @@ public String getContentRange() { /** * Set the contentRange property: The Content-Range property. - * + * * @param contentRange the contentRange value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -273,7 +309,7 @@ public PathsGetPropertiesHeaders setContentRange(String contentRange) { /** * Get the xMsLeaseState property: The x-ms-lease-state property. - * + * * @return the xMsLeaseState value. */ public String getXMsLeaseState() { @@ -282,7 +318,7 @@ public String getXMsLeaseState() { /** * Set the xMsLeaseState property: The x-ms-lease-state property. - * + * * @param xMsLeaseState the xMsLeaseState value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -293,7 +329,7 @@ public PathsGetPropertiesHeaders setXMsLeaseState(String xMsLeaseState) { /** * Get the xMsAcl property: The x-ms-acl property. - * + * * @return the xMsAcl value. */ public String getXMsAcl() { @@ -302,7 +338,7 @@ public String getXMsAcl() { /** * Set the xMsAcl property: The x-ms-acl property. - * + * * @param xMsAcl the xMsAcl value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -313,7 +349,7 @@ public PathsGetPropertiesHeaders setXMsAcl(String xMsAcl) { /** * Get the lastModified property: The Last-Modified property. - * + * * @return the lastModified value. */ public OffsetDateTime getLastModified() { @@ -325,7 +361,7 @@ public OffsetDateTime getLastModified() { /** * Set the lastModified property: The Last-Modified property. - * + * * @param lastModified the lastModified value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -340,7 +376,7 @@ public PathsGetPropertiesHeaders setLastModified(OffsetDateTime lastModified) { /** * Get the xMsProperties property: The x-ms-properties property. - * + * * @return the xMsProperties value. */ public String getXMsProperties() { @@ -349,7 +385,7 @@ public String getXMsProperties() { /** * Set the xMsProperties property: The x-ms-properties property. - * + * * @param xMsProperties the xMsProperties value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -360,7 +396,7 @@ public PathsGetPropertiesHeaders setXMsProperties(String xMsProperties) { /** * Get the date property: The Date property. - * + * * @return the date value. */ public OffsetDateTime getDate() { @@ -372,7 +408,7 @@ public OffsetDateTime getDate() { /** * Set the date property: The Date property. - * + * * @param date the date value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -387,7 +423,7 @@ public PathsGetPropertiesHeaders setDate(OffsetDateTime date) { /** * Get the xMsResourceType property: The x-ms-resource-type property. - * + * * @return the xMsResourceType value. */ public String getXMsResourceType() { @@ -396,7 +432,7 @@ public String getXMsResourceType() { /** * Set the xMsResourceType property: The x-ms-resource-type property. - * + * * @param xMsResourceType the xMsResourceType value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -407,7 +443,7 @@ public PathsGetPropertiesHeaders setXMsResourceType(String xMsResourceType) { /** * Get the contentMD5 property: The Content-MD5 property. - * + * * @return the contentMD5 value. */ public String getContentMD5() { @@ -416,7 +452,7 @@ public String getContentMD5() { /** * Set the contentMD5 property: The Content-MD5 property. - * + * * @param contentMD5 the contentMD5 value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -427,7 +463,7 @@ public PathsGetPropertiesHeaders setContentMD5(String contentMD5) { /** * Get the acceptRanges property: The Accept-Ranges property. - * + * * @return the acceptRanges value. */ public String getAcceptRanges() { @@ -436,7 +472,7 @@ public String getAcceptRanges() { /** * Set the acceptRanges property: The Accept-Ranges property. - * + * * @param acceptRanges the acceptRanges value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -447,7 +483,7 @@ public PathsGetPropertiesHeaders setAcceptRanges(String acceptRanges) { /** * Get the cacheControl property: The Cache-Control property. - * + * * @return the cacheControl value. */ public String getCacheControl() { @@ -456,7 +492,7 @@ public String getCacheControl() { /** * Set the cacheControl property: The Cache-Control property. - * + * * @param cacheControl the cacheControl value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -467,7 +503,7 @@ public PathsGetPropertiesHeaders setCacheControl(String cacheControl) { /** * Get the eTag property: The ETag property. - * + * * @return the eTag value. */ public String getETag() { @@ -476,7 +512,7 @@ public String getETag() { /** * Set the eTag property: The ETag property. - * + * * @param eTag the eTag value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -487,7 +523,7 @@ public PathsGetPropertiesHeaders setETag(String eTag) { /** * Get the contentDisposition property: The Content-Disposition property. - * + * * @return the contentDisposition value. */ public String getContentDisposition() { @@ -496,7 +532,7 @@ public String getContentDisposition() { /** * Set the contentDisposition property: The Content-Disposition property. - * + * * @param contentDisposition the contentDisposition value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -507,7 +543,7 @@ public PathsGetPropertiesHeaders setContentDisposition(String contentDisposition /** * Get the contentEncoding property: The Content-Encoding property. - * + * * @return the contentEncoding value. */ public String getContentEncoding() { @@ -516,7 +552,7 @@ public String getContentEncoding() { /** * Set the contentEncoding property: The Content-Encoding property. - * + * * @param contentEncoding the contentEncoding value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -527,7 +563,7 @@ public PathsGetPropertiesHeaders setContentEncoding(String contentEncoding) { /** * Get the xMsPermissions property: The x-ms-permissions property. - * + * * @return the xMsPermissions value. */ public String getXMsPermissions() { @@ -536,7 +572,7 @@ public String getXMsPermissions() { /** * Set the xMsPermissions property: The x-ms-permissions property. - * + * * @param xMsPermissions the xMsPermissions value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -547,7 +583,7 @@ public PathsGetPropertiesHeaders setXMsPermissions(String xMsPermissions) { /** * Get the xMsLeaseDuration property: The x-ms-lease-duration property. - * + * * @return the xMsLeaseDuration value. */ public String getXMsLeaseDuration() { @@ -556,7 +592,7 @@ public String getXMsLeaseDuration() { /** * Set the xMsLeaseDuration property: The x-ms-lease-duration property. - * + * * @param xMsLeaseDuration the xMsLeaseDuration value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -567,7 +603,7 @@ public PathsGetPropertiesHeaders setXMsLeaseDuration(String xMsLeaseDuration) { /** * Get the contentLength property: The Content-Length property. - * + * * @return the contentLength value. */ public Long getContentLength() { @@ -576,7 +612,7 @@ public Long getContentLength() { /** * Set the contentLength property: The Content-Length property. - * + * * @param contentLength the contentLength value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -587,7 +623,7 @@ public PathsGetPropertiesHeaders setContentLength(Long contentLength) { /** * Get the xMsRequestId property: The x-ms-request-id property. - * + * * @return the xMsRequestId value. */ public String getXMsRequestId() { @@ -596,7 +632,7 @@ public String getXMsRequestId() { /** * Set the xMsRequestId property: The x-ms-request-id property. - * + * * @param xMsRequestId the xMsRequestId value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -607,7 +643,7 @@ public PathsGetPropertiesHeaders setXMsRequestId(String xMsRequestId) { /** * Get the contentLanguage property: The Content-Language property. - * + * * @return the contentLanguage value. */ public String getContentLanguage() { @@ -616,7 +652,7 @@ public String getContentLanguage() { /** * Set the contentLanguage property: The Content-Language property. - * + * * @param contentLanguage the contentLanguage value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -627,7 +663,7 @@ public PathsGetPropertiesHeaders setContentLanguage(String contentLanguage) { /** * Get the xMsOwner property: The x-ms-owner property. - * + * * @return the xMsOwner value. */ public String getXMsOwner() { @@ -636,7 +672,7 @@ public String getXMsOwner() { /** * Set the xMsOwner property: The x-ms-owner property. - * + * * @param xMsOwner the xMsOwner value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -647,7 +683,7 @@ public PathsGetPropertiesHeaders setXMsOwner(String xMsOwner) { /** * Get the contentType property: The Content-Type property. - * + * * @return the contentType value. */ public String getContentType() { @@ -656,7 +692,7 @@ public String getContentType() { /** * Set the contentType property: The Content-Type property. - * + * * @param contentType the contentType value to set. * @return the PathsGetPropertiesHeaders object itself. */ @@ -664,4 +700,84 @@ public PathsGetPropertiesHeaders setContentType(String contentType) { this.contentType = contentType; return this; } + + /** + * Get the xMsServerEncrypted property: The x-ms-server-encrypted property. + * + * @return the xMsServerEncrypted value. + */ + public Boolean isServerEncrypted() { + return this.xMsServerEncrypted; + } + + /** + * Set the xMsServerEncrypted property: The x-ms-server-encrypted property. + * + * @param xMsServerEncrypted the xMsServerEncrypted value to set. + * @return the PathsGetPropertiesHeaders object itself. + */ + public PathsGetPropertiesHeaders setServerEncrypted(Boolean xMsServerEncrypted) { + this.xMsServerEncrypted = xMsServerEncrypted; + return this; + } + + /** + * Get the xMsEncryptionKeySha256 property: The x-ms-encryption-key-sha-256 property. + * + * @return the xMsEncryptionKeySha256 value. + */ + public String getXMsEncryptionKeySha256() { + return this.xMsEncryptionKeySha256; + } + + /** + * Set the xMsEncryptionKeySha256 property: The x-ms-encryption-key-sha-256 property. + * + * @param xMsEncryptionKeySha256 the xMsEncryptionKeySha256 value to set + * @return the PathsGetPropertiesHeaders object itself. + */ + public PathsGetPropertiesHeaders setXMsEncryptionKeySha256(String xMsEncryptionKeySha256) { + this.xMsEncryptionKeySha256 = xMsEncryptionKeySha256; + return this; + } + + /** + * Get the xMsEncryptionScope property: The x-ms-encryption-scope property. + * + * @return the xMsEncryptionScope value. + */ + public String getXMsEncryptionScope() { + return this.xMsEncryptionScope; + } + + /** + * Set the xMsEncryptionScope property: The x-ms-encryption-scope property. + * + * @param xMsEncryptionScope the xMsEncryptionScope value to set + * @return the PathsGetPropertiesHeaders object itself. + */ + public PathsGetPropertiesHeaders setXMsEncryptionScope(String xMsEncryptionScope) { + this.xMsEncryptionScope = xMsEncryptionScope; + return this; + } + + /** + * Get the xMsEncryptionContext property: The x-ms-encryption-context property. + * + * @return the xMsEncryptionContext value. + */ + public String getXMsEncryptionContext() { + return this.xMsEncryptionContext; + } + + /** + * Set the xMsEncryptionContext property: The x-ms-encryption-context property. + * + * @param xMsEncryptionContext the xMsEncryptionContext value to set. + * @return the PathsGetPropertiesHeaders object itself. + */ + public PathsGetPropertiesHeaders setXMsEncryptionContext(String xMsEncryptionContext) { + this.xMsEncryptionContext = xMsEncryptionContext; + return this; + } } diff --git a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/util/AccessorUtility.java b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/util/AccessorUtility.java index 8f061876df96..a63e4d69eb55 100644 --- a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/util/AccessorUtility.java +++ b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/implementation/util/AccessorUtility.java @@ -97,5 +97,4 @@ public static void setPathItemAccessor(PathItemAccessor accessor) { public static PathItemAccessor getPathItemAccessor() { return pathItemAccessor; } - } diff --git a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/models/PathStatus.java b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/models/PathStatus.java new file mode 100644 index 000000000000..2f6553996ea5 --- /dev/null +++ b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/models/PathStatus.java @@ -0,0 +1,248 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.storage.file.datalake.models; + +import java.time.OffsetDateTime; +import java.util.List; + +/** + * This class contains the response information returned from the service when getting path properties. + */ +public class PathStatus { + private final OffsetDateTime creationTime; + private final OffsetDateTime lastModified; + private final String eTag; + private final long fileSize; + private final LeaseStatusType leaseStatus; + private final LeaseStateType leaseState; + private final LeaseDurationType leaseDuration; + private final Boolean isServerEncrypted; + private final String encryptionKeySha256; + private final OffsetDateTime expiresOn; + private final String encryptionScope; + private final String encryptionContext; + private final String owner; + private final String group; + private final String permissions; + private final List accessControlList; + + /** + * Constructs a {@link PathStatus}. + * + * @param creationTime Creation time of the file. + * @param lastModified Datetime when the file was last modified. + * @param eTag ETag of the file. + * @param fileSize Size of the file. + * @param leaseStatus Status of the lease on the file. + * @param leaseState State of the lease on the file. + * @param leaseDuration Type of lease on the file. + * @param isServerEncrypted Flag indicating if the file's content is encrypted on the server. + * @param encryptionKeySha256 SHA256 of the customer provided encryption key used to encrypt the file on the server. + * @param encryptionScope The encryption scope of the file. + * @param encryptionContext The encryption context of the file. + * @param owner The owner of the file. + * @param group The group of the file. + * @param permissions The permissions of the file. + * @param accessControlList The access control list of the file. + * pass {@code null}. + */ + public PathStatus(final OffsetDateTime creationTime, final OffsetDateTime lastModified, final String eTag, + final long fileSize, final LeaseStatusType leaseStatus, final LeaseStateType leaseState, + final LeaseDurationType leaseDuration, final Boolean isServerEncrypted, final String encryptionKeySha256, + final String encryptionScope, final String encryptionContext, final String owner, final String group, + final String permissions, final String accessControlList) { + this(creationTime, lastModified, eTag, fileSize, leaseStatus, leaseState, leaseDuration, isServerEncrypted, + encryptionKeySha256, encryptionScope, encryptionContext, owner, group, permissions, accessControlList, + null); + } + + /** + * Constructs a {@link PathStatus}. + * + * @param creationTime Creation time of the file. + * @param lastModified Datetime when the file was last modified. + * @param eTag ETag of the file. + * @param fileSize Size of the file. + * @param leaseStatus Status of the lease on the file. + * @param leaseState State of the lease on the file. + * @param leaseDuration Type of lease on the file. + * @param isServerEncrypted Flag indicating if the file's content is encrypted on the server. + * @param encryptionKeySha256 SHA256 of the customer provided encryption key used to encrypt the file on the server. + * @param encryptionScope The encryption scope of the file. + * @param encryptionContext The encryption context of the file. + * @param owner The owner of the file. + * @param group The group of the file. + * @param permissions The permissions of the file. + * @param accessControlList The access control list of the file. + * pass {@code null}. + * @param expiresOn the time when the path is going to expire. + */ + public PathStatus(final OffsetDateTime creationTime, final OffsetDateTime lastModified, final String eTag, + final long fileSize, final LeaseStatusType leaseStatus, final LeaseStateType leaseState, + final LeaseDurationType leaseDuration, final Boolean isServerEncrypted, final String encryptionKeySha256, + final String encryptionScope, final String encryptionContext, final String owner, final String group, + final String permissions, final String accessControlList, final OffsetDateTime expiresOn) { + this.creationTime = creationTime; + this.lastModified = lastModified; + this.eTag = eTag; + this.fileSize = fileSize; + this.leaseStatus = leaseStatus; + this.leaseState = leaseState; + this.leaseDuration = leaseDuration; + this.isServerEncrypted = isServerEncrypted; + this.encryptionKeySha256 = encryptionKeySha256; + this.encryptionScope = encryptionScope; + this.encryptionContext = encryptionContext; + this.owner = owner; + this.group = group; + this.permissions = permissions; + this.accessControlList = PathAccessControlEntry.parseList(accessControlList); + this.expiresOn = expiresOn; + } + + /** + * Gets the time when the path was created. + * + * @return the time when the path was created + */ + public OffsetDateTime getCreationTime() { + return creationTime; + } + + /** + * Gets the time when the path was last modified. + * + * @return the time when the path was last modified + */ + public OffsetDateTime getLastModified() { + return lastModified; + } + + /** + * Gets the eTag of the path. + * + * @return the eTag of the path + */ + public String getETag() { + return eTag; + } + + /** + * Gets the size of the file in bytes. + * + * @return the size of the file in bytes + */ + public long getFileSize() { + return fileSize; + } + + /** + * Gets the lease status of the path. + * + * @return the lease status of the path + */ + public LeaseStatusType getLeaseStatus() { + return leaseStatus; + } + + /** + * Gets the lease state of the path. + * + * @return the lease state of the path + */ + public LeaseStateType getLeaseState() { + return leaseState; + } + + /** + * Gets the lease duration if the path is leased. + * + * @return the lease duration if the path is leased + */ + public LeaseDurationType getLeaseDuration() { + return leaseDuration; + } + + /** + * Gets the status of the path being encrypted on the server. + * + * @return the status of the path being encrypted on the server + */ + public Boolean isServerEncrypted() { + return isServerEncrypted; + } + + /** + * Gets the SHA256 of the encryption key used to encrypt the path. + * + * @return the key used to encrypt the path + */ + public String getEncryptionKeySha256() { + return encryptionKeySha256; + } + + /** + * Gets the time when the path is going to expire. + * + * @return the time when the path is going to expire. + */ + public OffsetDateTime getExpiresOn() { + return expiresOn; + } + + /** + * Gets the path's encryption scope. + * + * @return the path's encryption scope. + */ + public String getEncryptionScope() { + return encryptionScope; + } + + /** + * Gets the encryption context for this path. Only applicable for files. + * + * @return the encryption context for this path. Only applicable for files. + */ + public String getEncryptionContext() { + return encryptionContext; + } + + /** + * Get the owner property of the path: The owner property. + * + * @return the owner value. + */ + public String getOwner() { + return owner; + } + + /** + * Get the group property of the path: The group property. + * + * @return the group value. + */ + public String getGroup() { + return group; + } + + /** + * Get the permissions property of the path: The permissions property. + * + * @return the permissions value. + */ + public String getPermissions() { + return permissions; + } + + /** + * Optional. The POSIX access control list for the file or directory. + * + * @return the access control list. + */ + public List getAccessControlList() { + return accessControlList; + } + +} diff --git a/sdk/storage/azure-storage-file-datalake/src/samples/java/com/azure/storage/file/datalake/PathAsyncClientJavaDocCodeSamples.java b/sdk/storage/azure-storage-file-datalake/src/samples/java/com/azure/storage/file/datalake/PathAsyncClientJavaDocCodeSamples.java index 74e99b89e3d0..07e860d63af4 100644 --- a/sdk/storage/azure-storage-file-datalake/src/samples/java/com/azure/storage/file/datalake/PathAsyncClientJavaDocCodeSamples.java +++ b/sdk/storage/azure-storage-file-datalake/src/samples/java/com/azure/storage/file/datalake/PathAsyncClientJavaDocCodeSamples.java @@ -448,6 +448,32 @@ public void getAccessControlWithResponseCodeSnippets() { // END: com.azure.storage.file.datalake.DataLakePathAsyncClient.getAccessControlWithResponse#boolean-DataLakeRequestConditions } + /** + * Code snippets for {@link DataLakePathAsyncClient#getStatus()} + */ + public void getStatusCodeSnippets() { + // BEGIN: com.azure.storage.file.datalake.DataLakePathAsyncClient.getStatus + client.getStatus().subscribe( + response -> System.out.printf("Creation Time: %s, Group: %s, Owner: %s, Permissions: %s", + response.getCreationTime(), response.getGroup(), + response.getOwner(), response.getPermissions())); + // END: com.azure.storage.file.datalake.DataLakePathAsyncClient.getStatus + } + + /** + * Code snippets for {@link DataLakePathAsyncClient#getStatusWithResponse(DataLakeRequestConditions)} + */ + public void getStatusWithResponseCodeSnippets() { + // BEGIN: com.azure.storage.file.datalake.DataLakePathAsyncClient.getStatusWithResponse#DataLakeRequestConditions + DataLakeRequestConditions requestConditions = new DataLakeRequestConditions().setLeaseId(leaseId); + + client.getStatusWithResponse(requestConditions).subscribe( + response -> System.out.printf("Creation Time: %s, Group: %s, Owner: %s, Permissions: %s", + response.getValue().getCreationTime(), + response.getValue().getGroup(), response.getValue().getOwner(), response.getValue().getPermissions())); + // END: com.azure.storage.file.datalake.DataLakePathAsyncClient.getStatusWithResponse#DataLakeRequestConditions + } + /** * Code snippet for {@link DataLakePathAsyncClient#generateUserDelegationSas(DataLakeServiceSasSignatureValues, UserDelegationKey)} * and {@link DataLakePathAsyncClient#generateSas(DataLakeServiceSasSignatureValues)} diff --git a/sdk/storage/azure-storage-file-datalake/src/samples/java/com/azure/storage/file/datalake/PathClientJavaDocCodeSamples.java b/sdk/storage/azure-storage-file-datalake/src/samples/java/com/azure/storage/file/datalake/PathClientJavaDocCodeSamples.java index e38a6e3d67e5..1e1015351515 100644 --- a/sdk/storage/azure-storage-file-datalake/src/samples/java/com/azure/storage/file/datalake/PathClientJavaDocCodeSamples.java +++ b/sdk/storage/azure-storage-file-datalake/src/samples/java/com/azure/storage/file/datalake/PathClientJavaDocCodeSamples.java @@ -16,6 +16,7 @@ import com.azure.storage.file.datalake.models.PathInfo; import com.azure.storage.file.datalake.models.PathPermissions; import com.azure.storage.file.datalake.models.PathProperties; +import com.azure.storage.file.datalake.models.PathStatus; import com.azure.storage.file.datalake.models.PathRemoveAccessControlEntry; import com.azure.storage.file.datalake.models.RolePermissions; import com.azure.storage.file.datalake.models.UserDelegationKey; @@ -549,6 +550,36 @@ public void getAccessControlWithResponseCodeSnippets() { // END: com.azure.storage.file.datalake.DataLakePathClient.getAccessControlWithResponse#boolean-DataLakeRequestConditions-Duration-Context } + /** + * Code snippets for {@link DataLakePathClient#getStatus()} + */ + public void getStatusCodeSnippets() { + // BEGIN: com.azure.storage.file.datalake.DataLakePathClient.getStatus + PathStatus response = client.getStatus(); + System.out.printf("CreationTime: %s, Group: %s, Owner: %s, Permissions: %s", + response.getCreationTime(), response.getGroup(), + response.getOwner(), response.getPermissions()); + // END: com.azure.storage.file.datalake.DataLakePathClient.getStatus + } + + /** + * Code snippets for {@link DataLakePathClient#getStatusWithResponse(DataLakeRequestConditions, Duration, Context)} + */ + public void getStatusWithResponseCodeSnippets() { + // BEGIN: com.azure.storage.file.datalake.DataLakePathClient.getStatusWithResponse#DataLakeRequestConditions-Duration-Context + DataLakeRequestConditions requestConditions = new DataLakeRequestConditions().setLeaseId(leaseId); + + Response response = client.getStatusWithResponse( + requestConditions, timeout, new Context(key1, value1)); + + PathStatus ps = response.getValue(); + + System.out.printf("CreationTime: %s, Group: %s, Owner: %s, Permissions: %s", + ps.getCreationTime(), ps.getGroup(), ps.getOwner(), + ps.getPermissions()); + // END: com.azure.storage.file.datalake.DataLakePathClient.getStatusWithResponse#DataLakeRequestConditions-Duration-Context + } + /** * Code snippet for {@link DataLakePathClient#generateUserDelegationSas(DataLakeServiceSasSignatureValues, UserDelegationKey)} * and {@link DataLakePathClient#generateSas(DataLakeServiceSasSignatureValues)} diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/CpkTests.java b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/CpkTests.java index b2046327fa2a..0b48ca990e98 100644 --- a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/CpkTests.java +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/CpkTests.java @@ -8,6 +8,8 @@ import com.azure.storage.file.datalake.models.CustomerProvidedKey; import com.azure.storage.file.datalake.models.PathInfo; import com.azure.storage.file.datalake.models.PathProperties; +import com.azure.storage.file.datalake.models.PathStatus; +import com.azure.storage.file.datalake.options.DataLakePathCreateOptions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -81,6 +83,23 @@ public void pathSetMetadata() { response.getHeaders().getValue(Constants.HeaderConstants.ENCRYPTION_KEY_SHA256_HEADER_NAME)); } + @Test + public void pathSetEncryptionContext() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions(); + options.setEncryptionContext("encryption-context"); + cpkFile.createWithResponse(options, null, null); + + // The getStatus API returns the System defined properties of the Path. The encryption key is not required for + // this API. + Response response + = cpkFile.getCustomerProvidedKeyClient(null).getStatusWithResponse(null, null, null); + + assertEquals(200, response.getStatusCode()); + assertTrue(response.getValue().isServerEncrypted()); + assertEquals(key.getKeySha256(), response.getValue().getEncryptionKeySha256()); + assertEquals("encryption-context", response.getValue().getEncryptionContext()); + } + @Test public void fileRead() { cpkFile.create(); diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DirectoryApiTests.java b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DirectoryApiTests.java index 634df02831cd..83d62dbfd8a9 100644 --- a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DirectoryApiTests.java +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DirectoryApiTests.java @@ -2191,6 +2191,42 @@ public void getAccessControlACFail(OffsetDateTime modified, OffsetDateTime unmod assertThrows(DataLakeStorageException.class, () -> dc.getAccessControlWithResponse(false, drc, null, null)); } + @Test + public void getStatusWithResponse() { + assertEquals(200, dc.getStatusWithResponse(null, null, null).getStatusCode()); + } + + @ParameterizedTest + @MethodSource("modifiedMatchAndLeaseIdSupplier") + public void getStatusAC(OffsetDateTime modified, OffsetDateTime unmodified, String match, String noneMatch, + String leaseID) { + DataLakeRequestConditions drc = new DataLakeRequestConditions().setLeaseId(setupPathLeaseCondition(dc, leaseID)) + .setIfMatch(setupPathMatchCondition(dc, match)) + .setIfNoneMatch(noneMatch) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + + assertEquals(200, dc.getStatusWithResponse(drc, null, null).getStatusCode()); + } + + @ParameterizedTest + @MethodSource("invalidModifiedMatchAndLeaseIdSupplier") + public void getStatusACFail(OffsetDateTime modified, OffsetDateTime unmodified, String match, String noneMatch, + String leaseID) { + if (GARBAGE_LEASE_ID.equals(leaseID)) { + return; // known bug in DFS endpoint + } + + setupPathLeaseCondition(dc, leaseID); + DataLakeRequestConditions drc = new DataLakeRequestConditions().setLeaseId(leaseID) + .setIfMatch(match) + .setIfNoneMatch(setupPathMatchCondition(dc, noneMatch)) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + + assertThrows(DataLakeStorageException.class, () -> dc.getStatusWithResponse(drc, null, null)); + } + @Test public void renameMin() { assertEquals(201, dc.renameWithResponse(null, generatePathName(), null, null, null, null).getStatusCode()); diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileApiTest.java b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileApiTest.java index 605edd614525..283eb3bd75a8 100644 --- a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileApiTest.java +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileApiTest.java @@ -54,6 +54,7 @@ import com.azure.storage.file.datalake.models.PathItem; import com.azure.storage.file.datalake.models.PathPermissions; import com.azure.storage.file.datalake.models.PathProperties; +import com.azure.storage.file.datalake.models.PathStatus; import com.azure.storage.file.datalake.models.PathRemoveAccessControlEntry; import com.azure.storage.file.datalake.models.RolePermissions; import com.azure.storage.file.datalake.options.DataLakeFileAppendOptions; @@ -1003,6 +1004,32 @@ public void getAccessControlACFail(OffsetDateTime modified, OffsetDateTime unmod assertThrows(DataLakeStorageException.class, () -> fc.getAccessControlWithResponse(false, drc, null, null)); } + @Test + public void getStatusMin() { + PathStatus ps = fc.getStatus(); + + assertNotNull(ps.getCreationTime()); + assertNotNull(ps.getLastModified()); + assertNotNull(ps.getETag()); + assertTrue(ps.getFileSize() >= 0); + assertEquals(LeaseStatusType.UNLOCKED, ps.getLeaseStatus()); + assertNotNull(ps.getLeaseState()); + assertNull(ps.getLeaseDuration()); // tested in "acquire lease" + assertNotNull(ps.getEncryptionContext()); + assertFalse(ps.isServerEncrypted()); + assertNotNull(ps.getEncryptionKeySha256()); + assertNotNull(ps.getEncryptionScope()); + assertNotNull(ps.getAccessControlList()); + assertNotNull(ps.getPermissions()); + assertNotNull(ps.getOwner()); + assertNotNull(ps.getGroup()); + } + + @Test + public void getStatusWithResponse() { + assertEquals(200, fc.getStatusWithResponse(null, null, null).getStatusCode()); + } + @Test public void getPropertiesDefault() { Response response = fc.getPropertiesWithResponse(null, null, null);