/// <summary> /// Updates shared access signature authorization for the service bus namespace. 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="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 ruleName, string primaryKey, string secondaryKey, params AccessRights[] permissions) { ExtendedAuthorizationRule oldRule = GetAuthorizationRule(namespaceName, ruleName); if (null == oldRule) { throw new ArgumentException(Resources.ServiceBusAuthorizationRuleNotFound); } SharedAccessAuthorizationRule rule = (SharedAccessAuthorizationRule)oldRule.Rule; // Update the rule rule.Rights = permissions ?? rule.Rights; rule.PrimaryKey = string.IsNullOrEmpty(primaryKey) ? rule.PrimaryKey : primaryKey; rule.SecondaryKey = string.IsNullOrEmpty(secondaryKey) ? rule.SecondaryKey : secondaryKey; // In case that there's nothing to update then assume user asks for primary key renewal if (permissions == null && string.IsNullOrEmpty(secondaryKey) && string.IsNullOrEmpty(primaryKey)) { rule.PrimaryKey = SharedAccessAuthorizationRule.GenerateRandomKey(); } rule = ServiceBusClient.Namespaces.UpdateAuthorizationRule( namespaceName, rule.ToServiceBusSharedAccessAuthorizationRule()) .AuthorizationRule.ToSharedAccessAuthorizationRule(); return(CreateExtendedAuthorizationRule(rule, namespaceName)); }
public static PSObject GetNamespacePSObject(ExtendedAuthorizationRule rule) { return (null == rule? null : PowerShellUtilities.ConstructPSObject( typeof(ExtendedAuthorizationRule).FullName, "Namespace", rule.Namespace, "Name", rule.Name, "ConnectionString", rule.ConnectionString, "Permission", rule.Permission, "Rule", rule.Rule)); }
public static PSObject GetNamespacePSObject(ExtendedAuthorizationRule rule) { return(null == rule? null : PowerShellUtility.ConstructPSObject( typeof(ExtendedAuthorizationRule).FullName, "Namespace", rule.Namespace, "Name", rule.Name, "ConnectionString", rule.ConnectionString, "Permission", rule.Permission, "Rule", rule.Rule)); }
public static PSObject GetEntityPSObject(ExtendedAuthorizationRule rule) { return (null == rule? null : new PSObject(rule)); }
/// <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)); }
public static PSObject GetEntityPSObject(ExtendedAuthorizationRule rule) { return(null == rule? null : new PSObject(rule)); }