Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Azure Service Bus queue Shared Access Policy programmatically

I have implemented an Azure Service Bus REST API client. At the moment I am building xUnit tests for my REST project and need to create a Queue with a name provided by the test, send messages with the REST client and then delete the Queue with that specific name.

One of my requirements are to specify a Shared Access Policy for the newly created Queue with only Send permissions programmatically but I can't find anything online that suggests that this is possible.

So far I have this

TokenProvider credentials = TokenProvider.CreateSharedAccessSignatureTokenProvider("MyBusAccessPolicy", "XXXXXXXXXXXXXXXX");
NamespaceManager namespaceManager = new NamespaceManager(ServiceBusEnvironment.CreateServiceUri("sb", _serviceNamespace, string.Empty), credentials);
QueueDescription queueDescription =  await namespaceManager.CreateQueueAsync(queueName);

How would I proceed to create the Shared Access Policy specifically for that queue if even possible?

like image 501
the-ginger-geek Avatar asked Jun 10 '15 07:06

the-ginger-geek


1 Answers

Neil,

Something like this should work:

string queuePolicyName = "SendPolicy";
string queuePrimaryKey = SharedAccessAuthorizationRule.GenerateRandomKey();

QueueDescription queueDescription = new QueueDescription(queueName);
SharedAccessAuthorizationRule queueSharedAccessPolicy = new SharedAccessAuthorizationRule(queuePolicyName, queuePrimaryKey, new[] { AccessRights.Send });
queueDescription.Authorization.Add(queueSharedAccessPolicy);

await _namespaceManager.CreateQueueAsync(queueDescription);
like image 54
Seth Manheim - MSFT Avatar answered Oct 17 '22 15:10

Seth Manheim - MSFT