Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-queue/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/storage/azure-storage-queue",
"Tag": "java/storage/azure-storage-queue_06da25b415"
"Tag": "java/storage/azure-storage-queue_2e02d46abe"
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.azure.storage.queue.models.QueueStorageException;
import com.azure.storage.queue.models.SendMessageResult;
import com.azure.storage.queue.models.UpdateMessageResult;
import com.azure.storage.queue.models.UserDelegationKey;
import com.azure.storage.queue.sas.QueueServiceSasSignatureValues;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -1516,4 +1517,36 @@ public String generateSas(QueueServiceSasSignatureValues queueServiceSasSignatur
return new QueueSasImplUtil(queueServiceSasSignatureValues, getQueueName())
.generateSas(SasImplUtils.extractSharedKeyCredential(getHttpPipeline()), stringToSignHandler, context);
}

/**
* Generates a user delegation SAS for the queue using the specified {@link QueueServiceSasSignatureValues}.
* <p>See {@link QueueServiceSasSignatureValues} for more information on how to construct a user delegation SAS.</p>
*
* @param queueServiceSasSignatureValues {@link QueueServiceSasSignatureValues}
* @param userDelegationKey A {@link UserDelegationKey} object used to sign the SAS values.
*
* @return A {@code String} representing the SAS query parameters.
*/
public String generateUserDelegationSas(QueueServiceSasSignatureValues queueServiceSasSignatureValues,
UserDelegationKey userDelegationKey) {
return generateUserDelegationSas(queueServiceSasSignatureValues, userDelegationKey, null, Context.NONE);
}

/**
* Generates a user delegation SAS for the queue using the specified {@link QueueServiceSasSignatureValues}.
* <p>See {@link QueueServiceSasSignatureValues} for more information on how to construct a user delegation SAS.</p>
*
* @param queueServiceSasSignatureValues {@link QueueServiceSasSignatureValues}
* @param userDelegationKey A {@link UserDelegationKey} object used to sign the SAS values.
* @param stringToSignHandler For debugging purposes only. Returns the string to sign that was used to generate the
* signature.
* @param context Additional context that is passed through the code when generating a SAS.
*
* @return A {@code String} representing the SAS query parameters.
*/
public String generateUserDelegationSas(QueueServiceSasSignatureValues queueServiceSasSignatureValues,
UserDelegationKey userDelegationKey, Consumer<String> stringToSignHandler, Context context) {
return new QueueSasImplUtil(queueServiceSasSignatureValues, getQueueName())
.generateUserDelegationSas(userDelegationKey, accountName, stringToSignHandler, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.azure.storage.queue.implementation.models.QueuesGetAccessPolicyHeaders;
import com.azure.storage.queue.implementation.models.QueuesGetPropertiesHeaders;
import com.azure.storage.queue.implementation.models.SendMessageResultWrapper;
import com.azure.storage.queue.models.UserDelegationKey;
import com.azure.storage.queue.implementation.util.ModelHelper;
import com.azure.storage.queue.implementation.util.QueueSasImplUtil;
import com.azure.storage.queue.models.PeekedMessageItem;
Expand Down Expand Up @@ -1459,4 +1460,36 @@ public String generateSas(QueueServiceSasSignatureValues queueServiceSasSignatur
return new QueueSasImplUtil(queueServiceSasSignatureValues, getQueueName())
.generateSas(SasImplUtils.extractSharedKeyCredential(getHttpPipeline()), stringToSignHandler, context);
}

/**
* Generates a user delegation SAS for the queue using the specified {@link QueueServiceSasSignatureValues}.
* <p>See {@link QueueServiceSasSignatureValues} for more information on how to construct a user delegation SAS.</p>
*
* @param queueServiceSasSignatureValues {@link QueueServiceSasSignatureValues}
* @param userDelegationKey A {@link UserDelegationKey} object used to sign the SAS values.
*
* @return A {@code String} representing the SAS query parameters.
*/
public String generateUserDelegationSas(QueueServiceSasSignatureValues queueServiceSasSignatureValues,
UserDelegationKey userDelegationKey) {
return generateUserDelegationSas(queueServiceSasSignatureValues, userDelegationKey, null, Context.NONE);
}

/**
* Generates a user delegation SAS for the queue using the specified {@link QueueServiceSasSignatureValues}.
* <p>See {@link QueueServiceSasSignatureValues} for more information on how to construct a user delegation SAS.</p>
*
* @param queueServiceSasSignatureValues {@link QueueServiceSasSignatureValues}
* @param userDelegationKey A {@link UserDelegationKey} object used to sign the SAS values.
* @param stringToSignHandler For debugging purposes only. Returns the string to sign that was used to generate the
* signature.
* @param context Additional context that is passed through the code when generating a SAS.
*
* @return A {@code String} representing the SAS query parameters.
*/
public String generateUserDelegationSas(QueueServiceSasSignatureValues queueServiceSasSignatureValues,
UserDelegationKey userDelegationKey, Consumer<String> stringToSignHandler, Context context) {
return new QueueSasImplUtil(queueServiceSasSignatureValues, getQueueName())
.generateUserDelegationSas(userDelegationKey, accountName, stringToSignHandler, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedResponse;
Expand All @@ -15,20 +16,24 @@
import com.azure.core.util.logging.ClientLogger;
import com.azure.storage.common.StorageSharedKeyCredential;
import com.azure.storage.common.implementation.AccountSasImplUtil;
import com.azure.storage.common.implementation.Constants;
import com.azure.storage.common.implementation.SasImplUtils;
import com.azure.storage.common.implementation.StorageImplUtils;
import com.azure.storage.common.sas.AccountSasSignatureValues;
import com.azure.storage.queue.implementation.AzureQueueStorageImpl;
import com.azure.storage.queue.models.KeyInfo;
import com.azure.storage.queue.models.QueueCorsRule;
import com.azure.storage.queue.models.QueueItem;
import com.azure.storage.queue.models.QueueMessageDecodingError;
import com.azure.storage.queue.models.QueueServiceProperties;
import com.azure.storage.queue.models.QueueServiceStatistics;
import com.azure.storage.queue.models.QueueStorageException;
import com.azure.storage.queue.models.QueuesSegmentOptions;
import com.azure.storage.queue.models.UserDelegationKey;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -709,4 +714,57 @@ public String generateAccountSas(AccountSasSignatureValues accountSasSignatureVa
return new AccountSasImplUtil(accountSasSignatureValues, null)
.generateSas(SasImplUtils.extractSharedKeyCredential(getHttpPipeline()), stringToSignHandler, context);
}

/**
* Gets a user delegation key for use with this account's queue storage. Note: This method call is only valid when
* using {@link TokenCredential} in this object's {@link HttpPipeline}.
*
* @param start Start time for the key's validity. Null indicates immediate start.
* @param expiry Expiration of the key's validity.
* @return A {@link Mono} containing the user delegation key.
* @throws IllegalArgumentException If {@code start} isn't null and is after {@code expiry}.
* @throws NullPointerException If {@code expiry} is null.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<UserDelegationKey> getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry) {
return getUserDelegationKeyWithResponse(start, expiry).flatMap(FluxUtil::toMono);
}

/**
* Gets a user delegation key for use with this account's queue storage. Note: This method call is only valid when
* using {@link TokenCredential} in this object's {@link HttpPipeline}.
*
* @param start Start time for the key's validity. Null indicates immediate start.
* @param expiry Expiration of the key's validity.
* @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} containing the user
* delegation key.
* @throws IllegalArgumentException If {@code start} isn't null and is after {@code expiry}.
* @throws NullPointerException If {@code expiry} is null.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<UserDelegationKey>> getUserDelegationKeyWithResponse(OffsetDateTime start,
OffsetDateTime expiry) {
try {
return withContext(context -> getUserDelegationKeyWithResponse(start, expiry, context));
} catch (RuntimeException ex) {
return monoError(LOGGER, ex);
}
}

Mono<Response<UserDelegationKey>> getUserDelegationKeyWithResponse(OffsetDateTime start, OffsetDateTime expiry,
Context context) {
StorageImplUtils.assertNotNull("expiry", expiry);
if (start != null && !start.isBefore(expiry)) {
throw LOGGER.logExceptionAsError(
new IllegalArgumentException("`start` must be null or a datetime before `expiry`."));
}
context = context == null ? Context.NONE : context;

return client.getServices()
.getUserDelegationKeyWithResponseAsync(
new KeyInfo().setStart(start == null ? "" : Constants.ISO_8601_UTC_DATE_FORMATTER.format(start))
.setExpiry(Constants.ISO_8601_UTC_DATE_FORMATTER.format(expiry)),
null, null, context)
.map(rb -> new SimpleResponse<>(rb, rb.getValue()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
Expand All @@ -15,29 +16,37 @@
import com.azure.core.util.logging.ClientLogger;
import com.azure.storage.common.StorageSharedKeyCredential;
import com.azure.storage.common.implementation.AccountSasImplUtil;
import com.azure.storage.common.implementation.Constants;
import com.azure.storage.common.implementation.SasImplUtils;
import com.azure.storage.common.implementation.StorageImplUtils;
import com.azure.storage.common.sas.AccountSasSignatureValues;
import com.azure.storage.queue.implementation.AzureQueueStorageImpl;
import com.azure.storage.queue.models.KeyInfo;
import com.azure.storage.queue.implementation.models.ServicesGetStatisticsHeaders;
import com.azure.storage.queue.implementation.models.ServicesGetUserDelegationKeyHeaders;
import com.azure.storage.queue.models.QueueCorsRule;
import com.azure.storage.queue.models.QueueItem;
import com.azure.storage.queue.models.QueueMessageDecodingError;
import com.azure.storage.queue.models.QueueServiceProperties;
import com.azure.storage.queue.models.QueueServiceStatistics;
import com.azure.storage.queue.models.QueueStorageException;
import com.azure.storage.queue.models.QueuesSegmentOptions;
import com.azure.storage.queue.models.UserDelegationKey;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

import static com.azure.storage.common.implementation.StorageImplUtils.sendRequest;
import static com.azure.storage.common.implementation.StorageImplUtils.submitThreadPool;

/**
Expand Down Expand Up @@ -693,4 +702,48 @@ public String generateAccountSas(AccountSasSignatureValues accountSasSignatureVa
return new AccountSasImplUtil(accountSasSignatureValues, null)
.generateSas(SasImplUtils.extractSharedKeyCredential(getHttpPipeline()), stringToSignHandler, context);
}

/**
* Gets a user delegation key for use with this account's queue storage. Note: This method call is only valid when
* using {@link TokenCredential} in this object's {@link HttpPipeline}.
*
* @param start Start time for the key's validity. Null indicates immediate start.
* @param expiry Expiration of the key's validity.
* @return The user delegation key.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public UserDelegationKey getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry) {
return getUserDelegationKeyWithResponse(start, expiry, null, Context.NONE).getValue();
}

/**
* Gets a user delegation key for use with this account's queue storage. Note: This method call is only valid when
* using {@link TokenCredential} in this object's {@link HttpPipeline}.
*
* @param start Start time for the key's validity. Null indicates immediate start.
* @param expiry Expiration of the key's validity.
* @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 {@link Response} whose {@link Response#getValue() value} contains the user delegation key.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<UserDelegationKey> getUserDelegationKeyWithResponse(OffsetDateTime start, OffsetDateTime expiry,
Duration timeout, Context context) {
StorageImplUtils.assertNotNull("expiry", expiry);
if (start != null && !start.isBefore(expiry)) {
throw LOGGER.logExceptionAsError(
new IllegalArgumentException("`start` must be null or a datetime before `expiry`."));
}
Context finalContext = context == null ? Context.NONE : context;
Callable<ResponseBase<ServicesGetUserDelegationKeyHeaders, UserDelegationKey>> operation
= () -> this.azureQueueStorage.getServices()
.getUserDelegationKeyWithResponse(
new KeyInfo().setStart(start == null ? "" : Constants.ISO_8601_UTC_DATE_FORMATTER.format(start))
.setExpiry(Constants.ISO_8601_UTC_DATE_FORMATTER.format(expiry)),
null, null, finalContext);
ResponseBase<ServicesGetUserDelegationKeyHeaders, UserDelegationKey> response
= sendRequest(operation, timeout, QueueStorageException.class);
return new SimpleResponse<>(response, response.getValue());
}

}
Loading
Loading