public static string ConnectionStringUri( string namespaceName, string entityName, ServiceBusEntityType entityType) { return(string.Format("{0}/{1}s/{2}/ConnectionDetails/?api-version={3}", namespaceName, entityType.ToString(), entityName, ServiceBusLatestVersion)); }
public static string ConnectionStringUri( string namespaceName, string entityName, ServiceBusEntityType entityType) { return string.Format("{0}/{1}s/{2}/ConnectionDetails/?api-version={3}", namespaceName, entityType.ToString(), entityName, ServiceBusLatestVersion); }
/// <summary> /// Removed shared access signature authorization for the service bus entity. /// </summary> /// <param name="namespaceName">The service bus namespace name</param> /// <param name="entityName">The fully qualified service bus entity name</param> /// <param name="entityType">The service bus entity type (e.g. Queue)</param> /// <param name="ruleName">The SAS authorization rule name</param> public virtual void RemoveAuthorizationRule( string namespaceName, string entityName, ServiceBusEntityType entityType, string ruleName) { bool removed = false; SharedAccessAuthorizationRule rule = (SharedAccessAuthorizationRule)GetAuthorizationRule( namespaceName, entityName, entityType, ruleName).Rule; // 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(rule); Debug.Assert(removed); namespaceManager.UpdateQueue(queue); break; case ServiceBusEntityType.Topic: TopicDescription topic = namespaceManager.GetTopic(entityName); removed = topic.Authorization.Remove(rule); Debug.Assert(removed); namespaceManager.UpdateTopic(topic); break; case ServiceBusEntityType.Relay: RelayDescription relay = namespaceManager.GetRelayAsync(entityName).Result; removed = relay.Authorization.Remove(rule); Debug.Assert(removed); namespaceManager.UpdateRelayAsync(relay).Wait(); break; case ServiceBusEntityType.NotificationHub: NotificationHubDescription notificationHub = namespaceManager.GetNotificationHub(entityName); removed = notificationHub.Authorization.Remove(rule); Debug.Assert(removed); namespaceManager.UpdateNotificationHub(notificationHub); break; default: throw new Exception(string.Format(Resources.ServiceBusEntityTypeNotFound, entityType.ToString())); } }
/// <summary> /// 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. /// </summary> /// <param name="namespaceName">The service bus namespace name</param> /// <param name="entityName">The fully qualified service bus entity name</param> /// <param name="entityType">The service bus entity type (e.g. Queue)</param> /// <param name="ruleName">The SAS authorization rule name</param> /// <param name="primaryKey">The SAS primary key. It'll be generated if empty</param> /// <param name="secondaryKey">The SAS secondary key</param> /// <param name="permissions">Set of permissions given to the rule</param> /// <returns>The created Shared Access Signature authorization rule</returns> 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); }
/// <summary> /// Gets available connection strings for the specified entity. /// </summary> /// <param name="namespaceName">The namespace name</param> /// <param name="entityName">The entity name</param> /// <param name="entityType">The entity type</param> /// <returns>List of all available connection strings</returns> public virtual List<ServiceBusConnectionDetail> GetConnectionString( string namespaceName, string entityName, ServiceBusEntityType entityType) { switch (entityType) { case ServiceBusEntityType.Queue: return ServiceBusClient.Queues.GetConnectionDetails(namespaceName, entityName).ConnectionDetails .ToList(); case ServiceBusEntityType.Topic: return ServiceBusClient.Topics.GetConnectionDetails(namespaceName, entityName).ConnectionDetails .ToList(); case ServiceBusEntityType.Relay: return ServiceBusClient.Relays.GetConnectionDetails(namespaceName, entityName).ConnectionDetails .ToList(); case ServiceBusEntityType.NotificationHub: return ServiceBusClient.NotificationHubs.GetConnectionDetails(namespaceName, entityName) .ConnectionDetails .ToList(); default: throw new Exception(string.Format(Resources.ServiceBusEntityTypeNotFound, entityType.ToString())); } }
/// <summary> /// 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. /// </summary> /// <param name="namespaceName">The service bus namespace name</param> /// <param name="entityName">The fully qualified service bus entity name</param> /// <param name="entityType">The service bus entity type (e.g. Queue)</param> /// <param name="ruleName">The SAS authorization rule name</param> /// <param name="primaryKey">The SAS primary key. It'll be generated if empty</param> /// <param name="secondaryKey">The SAS secondary key</param> /// <param name="permissions">Set of permissions given to the rule</param> /// <returns>The created Shared Access Signature authorization rule</returns> 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)); }
/// <summary> /// Gets available connection strings for the specified entity. /// </summary> /// <param name="namespaceName">The namespace name</param> /// <param name="entityName">The entity name</param> /// <param name="entityType">The entity type</param> /// <returns>List of all available connection strings</returns> public virtual List <ServiceBusConnectionDetail> GetConnectionString( string namespaceName, string entityName, ServiceBusEntityType entityType) { switch (entityType) { case ServiceBusEntityType.Queue: return(ServiceBusClient.Queues.GetConnectionDetails(namespaceName, entityName).ConnectionDetails .ToList()); case ServiceBusEntityType.Topic: return(ServiceBusClient.Topics.GetConnectionDetails(namespaceName, entityName).ConnectionDetails .ToList()); case ServiceBusEntityType.Relay: return(ServiceBusClient.Relays.GetConnectionDetails(namespaceName, entityName).ConnectionDetails .ToList()); case ServiceBusEntityType.NotificationHub: return(ServiceBusClient.NotificationHubs.GetConnectionDetails(namespaceName, entityName) .ConnectionDetails .ToList()); default: throw new Exception(string.Format(Resources.ServiceBusEntityTypeNotFound, entityType.ToString())); } }
/// <summary> /// Creates shared access signature authorization for the service bus entity. This authorization works on /// public Windows Azure environments and Windows Azure Pack on prim as well. /// </summary> /// <param name="namespaceName">The service bus namespace name</param> /// <param name="entityName">The fully qualified service bus entity name</param> /// <param name="entityType">The service bus entity type (e.g. Queue)</param> /// <param name="ruleName">The SAS authorization rule name</param> /// <param name="primaryKey">The SAS primary key. It'll be generated if empty</param> /// <param name="secondaryKey">The SAS secondary key</param> /// <param name="permissions">Set of permissions given to the rule</param> /// <returns>The created Shared Access Signature authorization rule</returns> public ExtendedAuthorizationRule CreateSharedAccessAuthorization( string namespaceName, string entityName, ServiceBusEntityType entityType, string ruleName, string primaryKey, string secondaryKey, params AccessRights[] permissions) { // Create the SAS authorization rule SharedAccessAuthorizationRule rule = new SharedAccessAuthorizationRule( ruleName, string.IsNullOrEmpty(primaryKey) ? SharedAccessAuthorizationRule.GenerateRandomKey() : primaryKey, secondaryKey, permissions); // 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); queue.Authorization.Add(rule); namespaceManager.UpdateQueue(queue); break; case ServiceBusEntityType.Topic: TopicDescription topic = namespaceManager.GetTopic(entityName); topic.Authorization.Add(rule); namespaceManager.UpdateTopic(topic); break; case ServiceBusEntityType.Relay: RelayDescription relay = namespaceManager.GetRelayAsync(entityName).Result; relay.Authorization.Add(rule); namespaceManager.UpdateRelayAsync(relay).Wait(); break; case ServiceBusEntityType.NotificationHub: NotificationHubDescription notificationHub = namespaceManager.GetNotificationHub(entityName); notificationHub.Authorization.Add(rule); namespaceManager.UpdateNotificationHub(notificationHub); break; default: throw new Exception(string.Format(Resources.ServiceBusEntityTypeNotFound, entityType.ToString())); } return(CreateExtendedAuthorizationRule(rule, namespaceName, entityName, entityType)); }