Microsoft.WindowsAzure.Commands.Utilities.ServiceBus.ServiceBusClientExtensions.UpdateSharedAccessAuthorization C# (CSharp) Method

UpdateSharedAccessAuthorization() public method

Updates shared access signature authorization for the service bus entity. This authorization works on public Microsoft Azure environments and Windows Azure Pack on prim as well.
public UpdateSharedAccessAuthorization ( string namespaceName, string entityName, ServiceBusEntityType entityType, string ruleName, string primaryKey, string secondaryKey ) : Microsoft.WindowsAzure.Commands.Utilities.ServiceBus.ExtendedAuthorizationRule
namespaceName string The service bus namespace name
entityName string The fully qualified service bus entity name
entityType ServiceBusEntityType The service bus entity type (e.g. Queue)
ruleName string The SAS authorization rule name
primaryKey string The SAS primary key. It'll be generated if empty
secondaryKey string The SAS secondary key
return Microsoft.WindowsAzure.Commands.Utilities.ServiceBus.ExtendedAuthorizationRule
        public virtual ExtendedAuthorizationRule UpdateSharedAccessAuthorization(
            string namespaceName,
            string entityName,
            ServiceBusEntityType entityType,
            string ruleName,
            string primaryKey,
            string secondaryKey,
            params AccessRights[] permissions)
        {
            bool removed = false;
            ExtendedAuthorizationRule rule = GetAuthorizationRule( namespaceName, entityName, entityType, ruleName);
            if (null == rule)
            {
                throw new ArgumentException(Resources.ServiceBusAuthorizationRuleNotFound);
            }

            SharedAccessAuthorizationRule oldRule = (SharedAccessAuthorizationRule)rule.Rule;

            SharedAccessAuthorizationRule newRule = new SharedAccessAuthorizationRule(
                ruleName,
                string.IsNullOrEmpty(primaryKey) ? SharedAccessAuthorizationRule.GenerateRandomKey() : primaryKey,
                secondaryKey,
                permissions ?? oldRule.Rights);

            // Create namespace manager
            NamespaceManager namespaceManager = CreateNamespaceManager(namespaceName);

            // Add the SAS rule and update the entity
            switch (entityType)
            {
                case ServiceBusEntityType.Queue:
                    QueueDescription queue = namespaceManager.GetQueue(entityName);
                    removed = queue.Authorization.Remove(oldRule);
                    Debug.Assert(removed);
                    queue.Authorization.Add(newRule);
                    namespaceManager.UpdateQueue(queue);
                    break;

                case ServiceBusEntityType.Topic:
                    TopicDescription topic = namespaceManager.GetTopic(entityName);
                    removed = topic.Authorization.Remove(oldRule);
                    Debug.Assert(removed);
                    topic.Authorization.Add(newRule);
                    namespaceManager.UpdateTopic(topic);
                    break;

                case ServiceBusEntityType.Relay:
                    RelayDescription relay = namespaceManager.GetRelayAsync(entityName).Result;
                    removed = relay.Authorization.Remove(oldRule);
                    Debug.Assert(removed);
                    relay.Authorization.Add(newRule);
                    namespaceManager.UpdateRelayAsync(relay).Wait();
                    break;

                case ServiceBusEntityType.NotificationHub:
                    NotificationHubDescription notificationHub = namespaceManager.GetNotificationHub(entityName);
                    removed = notificationHub.Authorization.Remove(oldRule);
                    Debug.Assert(removed);
                    notificationHub.Authorization.Add(newRule);
                    namespaceManager.UpdateNotificationHub(notificationHub);
                    break;

                default:
                    throw new Exception(string.Format(Resources.ServiceBusEntityTypeNotFound, entityType.ToString()));
            }

            return CreateExtendedAuthorizationRule(newRule, namespaceName, entityName, entityType);
        }

Same methods

ServiceBusClientExtensions::UpdateSharedAccessAuthorization ( string namespaceName, string ruleName, string primaryKey, string secondaryKey ) : Microsoft.WindowsAzure.Commands.Utilities.ServiceBus.ExtendedAuthorizationRule