|
5 | 5 | import com.azure.core.annotation.ReturnType;
|
6 | 6 | import com.azure.core.annotation.ServiceClient;
|
7 | 7 | import com.azure.core.annotation.ServiceMethod;
|
| 8 | +import com.azure.core.credential.TokenCredential; |
8 | 9 | import com.azure.core.http.HttpPipeline;
|
9 | 10 | import com.azure.core.http.rest.PagedIterable;
|
10 | 11 | import com.azure.core.http.rest.PagedResponse;
|
|
15 | 16 | import com.azure.core.util.logging.ClientLogger;
|
16 | 17 | import com.azure.storage.common.StorageSharedKeyCredential;
|
17 | 18 | import com.azure.storage.common.implementation.AccountSasImplUtil;
|
| 19 | +import com.azure.storage.common.implementation.Constants; |
18 | 20 | import com.azure.storage.common.implementation.SasImplUtils;
|
| 21 | +import com.azure.storage.common.implementation.StorageImplUtils; |
19 | 22 | import com.azure.storage.common.sas.AccountSasSignatureValues;
|
20 | 23 | import com.azure.storage.queue.implementation.AzureQueueStorageImpl;
|
| 24 | +import com.azure.storage.queue.models.KeyInfo; |
21 | 25 | import com.azure.storage.queue.implementation.models.ServicesGetStatisticsHeaders;
|
| 26 | +import com.azure.storage.queue.implementation.models.ServicesGetUserDelegationKeyHeaders; |
22 | 27 | import com.azure.storage.queue.models.QueueCorsRule;
|
23 | 28 | import com.azure.storage.queue.models.QueueItem;
|
24 | 29 | import com.azure.storage.queue.models.QueueMessageDecodingError;
|
25 | 30 | import com.azure.storage.queue.models.QueueServiceProperties;
|
26 | 31 | import com.azure.storage.queue.models.QueueServiceStatistics;
|
27 | 32 | import com.azure.storage.queue.models.QueueStorageException;
|
28 | 33 | import com.azure.storage.queue.models.QueuesSegmentOptions;
|
| 34 | +import com.azure.storage.queue.models.UserDelegationKey; |
29 | 35 | import reactor.core.publisher.Mono;
|
30 | 36 |
|
31 | 37 | import java.time.Duration;
|
| 38 | +import java.time.OffsetDateTime; |
32 | 39 | import java.util.ArrayList;
|
33 | 40 | import java.util.List;
|
34 | 41 | import java.util.Map;
|
35 | 42 | import java.util.Objects;
|
| 43 | +import java.util.concurrent.Callable; |
36 | 44 | import java.util.function.BiFunction;
|
37 | 45 | import java.util.function.Consumer;
|
38 | 46 | import java.util.function.Function;
|
39 | 47 | import java.util.function.Supplier;
|
40 | 48 |
|
| 49 | +import static com.azure.storage.common.implementation.StorageImplUtils.sendRequest; |
41 | 50 | import static com.azure.storage.common.implementation.StorageImplUtils.submitThreadPool;
|
42 | 51 |
|
43 | 52 | /**
|
@@ -693,4 +702,48 @@ public String generateAccountSas(AccountSasSignatureValues accountSasSignatureVa
|
693 | 702 | return new AccountSasImplUtil(accountSasSignatureValues, null)
|
694 | 703 | .generateSas(SasImplUtils.extractSharedKeyCredential(getHttpPipeline()), stringToSignHandler, context);
|
695 | 704 | }
|
| 705 | + |
| 706 | + /** |
| 707 | + * Gets a user delegation key for use with this account's queue storage. Note: This method call is only valid when |
| 708 | + * using {@link TokenCredential} in this object's {@link HttpPipeline}. |
| 709 | + * |
| 710 | + * @param start Start time for the key's validity. Null indicates immediate start. |
| 711 | + * @param expiry Expiration of the key's validity. |
| 712 | + * @return The user delegation key. |
| 713 | + */ |
| 714 | + @ServiceMethod(returns = ReturnType.SINGLE) |
| 715 | + public UserDelegationKey getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry) { |
| 716 | + return getUserDelegationKeyWithResponse(start, expiry, null, Context.NONE).getValue(); |
| 717 | + } |
| 718 | + |
| 719 | + /** |
| 720 | + * Gets a user delegation key for use with this account's queue storage. Note: This method call is only valid when |
| 721 | + * using {@link TokenCredential} in this object's {@link HttpPipeline}. |
| 722 | + * |
| 723 | + * @param start Start time for the key's validity. Null indicates immediate start. |
| 724 | + * @param expiry Expiration of the key's validity. |
| 725 | + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. |
| 726 | + * @param context Additional context that is passed through the Http pipeline during the service call. |
| 727 | + * @return A {@link Response} whose {@link Response#getValue() value} contains the user delegation key. |
| 728 | + */ |
| 729 | + @ServiceMethod(returns = ReturnType.SINGLE) |
| 730 | + public Response<UserDelegationKey> getUserDelegationKeyWithResponse(OffsetDateTime start, OffsetDateTime expiry, |
| 731 | + Duration timeout, Context context) { |
| 732 | + StorageImplUtils.assertNotNull("expiry", expiry); |
| 733 | + if (start != null && !start.isBefore(expiry)) { |
| 734 | + throw LOGGER.logExceptionAsError( |
| 735 | + new IllegalArgumentException("`start` must be null or a datetime before `expiry`.")); |
| 736 | + } |
| 737 | + Context finalContext = context == null ? Context.NONE : context; |
| 738 | + Callable<ResponseBase<ServicesGetUserDelegationKeyHeaders, UserDelegationKey>> operation |
| 739 | + = () -> this.azureQueueStorage.getServices() |
| 740 | + .getUserDelegationKeyWithResponse( |
| 741 | + new KeyInfo().setStart(start == null ? "" : Constants.ISO_8601_UTC_DATE_FORMATTER.format(start)) |
| 742 | + .setExpiry(Constants.ISO_8601_UTC_DATE_FORMATTER.format(expiry)), |
| 743 | + null, null, finalContext); |
| 744 | + ResponseBase<ServicesGetUserDelegationKeyHeaders, UserDelegationKey> response |
| 745 | + = sendRequest(operation, timeout, QueueStorageException.class); |
| 746 | + return new SimpleResponse<>(response, response.getValue()); |
| 747 | + } |
| 748 | + |
696 | 749 | }
|
0 commit comments