diff --git a/src/ServiceBus/ServiceBus/Utilities/ServiceBusClient.cs b/src/ServiceBus/ServiceBus/Utilities/ServiceBusClient.cs index d2270c42867c..81c26fed67f5 100644 --- a/src/ServiceBus/ServiceBus/Utilities/ServiceBusClient.cs +++ b/src/ServiceBus/ServiceBus/Utilities/ServiceBusClient.cs @@ -114,7 +114,7 @@ public PSNamespaceAttributes BeginCreateNamespace(string resourceGroupName, stri if (identityType != null) { parameter.Identity = new Identity(); - parameter.Identity = FindIdentity(identityType); + parameter.Identity.Type = FindIdentity(identityType); } if (identityIds != null) @@ -132,6 +132,11 @@ public PSNamespaceAttributes BeginCreateNamespace(string resourceGroupName, stri { parameter.Identity.UserAssignedIdentities = UserAssignedIdentities; } + + if (parameter.Identity.Type == ManagedServiceIdentityType.None || parameter.Identity.Type == ManagedServiceIdentityType.SystemAssigned) + { + throw new Exception("Please change -IdentityType to 'UserAssigned' or 'SystemAssigned, UserAssigned' if you want to add User Assigned Identities"); + } } if (encryptionconfigs != null) @@ -204,9 +209,14 @@ public PSNamespaceAttributes UpdateNamespace(string resourceGroupName, string na if (identityType != null) { - parameter.Identity = new Identity(); - parameter.Identity = FindIdentity(identityType); - if (parameter.Identity.Type == ManagedServiceIdentityType.None) + if (parameter.Identity == null) + { + parameter.Identity = new Identity(); + } + + parameter.Identity.Type = FindIdentity(identityType); + + if (parameter.Identity.Type == ManagedServiceIdentityType.None || parameter.Identity.Type == ManagedServiceIdentityType.SystemAssigned) { parameter.Identity.UserAssignedIdentities = null; } @@ -226,6 +236,10 @@ public PSNamespaceAttributes UpdateNamespace(string resourceGroupName, string na { parameter.Identity.UserAssignedIdentities = UserAssignedIdentities; } + if (parameter.Identity.Type == ManagedServiceIdentityType.None || parameter.Identity.Type == ManagedServiceIdentityType.SystemAssigned) + { + throw new Exception("Please change -IdentityType to 'UserAssigned' or 'SystemAssigned, UserAssigned' if you want to add User Assigned Identities"); + } } if (encryptionconfigs != null) @@ -264,26 +278,26 @@ public PSNamespaceAttributes UpdateNamespace(string resourceGroupName, string na return new PSNamespaceAttributes(response); } - public Identity FindIdentity(string identityType) + public ManagedServiceIdentityType FindIdentity(string identityType) { - Identity identity = new Identity(); - + ManagedServiceIdentityType Type = ManagedServiceIdentityType.None; if (identityType == SystemAssigned) - identity.Type = ManagedServiceIdentityType.SystemAssigned; + Type = ManagedServiceIdentityType.SystemAssigned; else if (identityType == UserAssigned) - identity.Type = ManagedServiceIdentityType.UserAssigned; + Type = ManagedServiceIdentityType.UserAssigned; else if (identityType == SystemAssignedUserAssigned) - identity.Type = ManagedServiceIdentityType.SystemAssignedUserAssigned; + Type = ManagedServiceIdentityType.SystemAssignedUserAssigned; else if (identityType == None) - identity.Type = ManagedServiceIdentityType.None; + Type = ManagedServiceIdentityType.None; - return identity; + return Type; } + public bool BeginDeleteNamespace(string resourceGroupName, string namespaceName) { Client.Namespaces.DeleteWithHttpMessagesAsync(resourceGroupName, namespaceName, null, new CancellationToken()).ConfigureAwait(false);