Skip to content

Commit 265dd93

Browse files
Sbmsi bug fix (#17249)
* Fixing identity update bug and making disable of user assigned identity possible * Making fixes
1 parent e4fd7ab commit 265dd93

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

src/ServiceBus/ServiceBus/Utilities/ServiceBusClient.cs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public PSNamespaceAttributes BeginCreateNamespace(string resourceGroupName, stri
114114
if (identityType != null)
115115
{
116116
parameter.Identity = new Identity();
117-
parameter.Identity = FindIdentity(identityType);
117+
parameter.Identity.Type = FindIdentity(identityType);
118118
}
119119

120120
if (identityIds != null)
@@ -132,6 +132,11 @@ public PSNamespaceAttributes BeginCreateNamespace(string resourceGroupName, stri
132132
{
133133
parameter.Identity.UserAssignedIdentities = UserAssignedIdentities;
134134
}
135+
136+
if (parameter.Identity.Type == ManagedServiceIdentityType.None || parameter.Identity.Type == ManagedServiceIdentityType.SystemAssigned)
137+
{
138+
throw new Exception("Please change -IdentityType to 'UserAssigned' or 'SystemAssigned, UserAssigned' if you want to add User Assigned Identities");
139+
}
135140
}
136141

137142
if (encryptionconfigs != null)
@@ -204,9 +209,14 @@ public PSNamespaceAttributes UpdateNamespace(string resourceGroupName, string na
204209

205210
if (identityType != null)
206211
{
207-
parameter.Identity = new Identity();
208-
parameter.Identity = FindIdentity(identityType);
209-
if (parameter.Identity.Type == ManagedServiceIdentityType.None)
212+
if (parameter.Identity == null)
213+
{
214+
parameter.Identity = new Identity();
215+
}
216+
217+
parameter.Identity.Type = FindIdentity(identityType);
218+
219+
if (parameter.Identity.Type == ManagedServiceIdentityType.None || parameter.Identity.Type == ManagedServiceIdentityType.SystemAssigned)
210220
{
211221
parameter.Identity.UserAssignedIdentities = null;
212222
}
@@ -226,6 +236,10 @@ public PSNamespaceAttributes UpdateNamespace(string resourceGroupName, string na
226236
{
227237
parameter.Identity.UserAssignedIdentities = UserAssignedIdentities;
228238
}
239+
if (parameter.Identity.Type == ManagedServiceIdentityType.None || parameter.Identity.Type == ManagedServiceIdentityType.SystemAssigned)
240+
{
241+
throw new Exception("Please change -IdentityType to 'UserAssigned' or 'SystemAssigned, UserAssigned' if you want to add User Assigned Identities");
242+
}
229243
}
230244

231245
if (encryptionconfigs != null)
@@ -264,26 +278,26 @@ public PSNamespaceAttributes UpdateNamespace(string resourceGroupName, string na
264278
return new PSNamespaceAttributes(response);
265279
}
266280

267-
public Identity FindIdentity(string identityType)
281+
public ManagedServiceIdentityType FindIdentity(string identityType)
268282
{
269-
Identity identity = new Identity();
270-
283+
ManagedServiceIdentityType Type = ManagedServiceIdentityType.None;
271284
if (identityType == SystemAssigned)
272-
identity.Type = ManagedServiceIdentityType.SystemAssigned;
285+
Type = ManagedServiceIdentityType.SystemAssigned;
273286

274287
else if (identityType == UserAssigned)
275-
identity.Type = ManagedServiceIdentityType.UserAssigned;
288+
Type = ManagedServiceIdentityType.UserAssigned;
276289

277290
else if (identityType == SystemAssignedUserAssigned)
278-
identity.Type = ManagedServiceIdentityType.SystemAssignedUserAssigned;
291+
Type = ManagedServiceIdentityType.SystemAssignedUserAssigned;
279292

280293
else if (identityType == None)
281-
identity.Type = ManagedServiceIdentityType.None;
294+
Type = ManagedServiceIdentityType.None;
282295

283-
return identity;
296+
return Type;
284297
}
285298

286299

300+
287301
public bool BeginDeleteNamespace(string resourceGroupName, string namespaceName)
288302
{
289303
Client.Namespaces.DeleteWithHttpMessagesAsync(resourceGroupName, namespaceName, null, new CancellationToken()).ConfigureAwait(false);

0 commit comments

Comments
 (0)