Skip to content

Commit 27c1905

Browse files
Fixing identity update bug (#17248)
* Fixing identity bug * Fixing bugs Co-authored-by: Yabo Hu <[email protected]>
1 parent 94a3892 commit 27c1905

File tree

1 file changed

+42
-14
lines changed

1 file changed

+42
-14
lines changed

src/EventHub/EventHub/Utilities/EventHubsClient.cs

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public PSNamespaceAttributes BeginCreateNamespace(string resourceGroupName, stri
124124
if (identityType != null)
125125
{
126126
parameter.Identity = new Identity();
127-
parameter.Identity = FindIdentity(identityType);
127+
parameter.Identity.Type = FindIdentity(identityType);
128128
}
129129

130130
if (identityId != null)
@@ -142,6 +142,10 @@ public PSNamespaceAttributes BeginCreateNamespace(string resourceGroupName, stri
142142
{
143143
parameter.Identity.UserAssignedIdentities = UserAssignedIdentities;
144144
}
145+
if (parameter.Identity.Type == ManagedServiceIdentityType.None || parameter.Identity.Type == ManagedServiceIdentityType.SystemAssigned)
146+
{
147+
throw new Exception("Please change -IdentityType to 'UserAssigned' or 'SystemAssigned, UserAssigned' if you want to add User Assigned Identities");
148+
}
145149
}
146150

147151
if (encryptionConfigs != null)
@@ -233,8 +237,23 @@ public PSNamespaceAttributes BeginUpdateNamespace(string resourceGroupName,
233237
if (isKafkaEnabled)
234238
parameter.KafkaEnabled = isKafkaEnabled;
235239

236-
if (isIdentity)
237-
parameter.Identity = new Identity() { Type = ManagedServiceIdentityType.SystemAssigned };
240+
if (isIdentity) {
241+
if(parameter.Identity == null)
242+
{
243+
parameter.Identity = new Identity() { Type = ManagedServiceIdentityType.SystemAssigned };
244+
}
245+
else
246+
{
247+
if(parameter.Identity.Type == ManagedServiceIdentityType.None)
248+
{
249+
parameter.Identity = new Identity() { Type = ManagedServiceIdentityType.SystemAssigned };
250+
}
251+
if (parameter.Identity.Type == ManagedServiceIdentityType.UserAssigned)
252+
{
253+
parameter.Identity = new Identity() { Type = ManagedServiceIdentityType.SystemAssignedUserAssigned };
254+
}
255+
}
256+
}
238257

239258
if (isDisableLocalAuth)
240259
parameter.DisableLocalAuth = isDisableLocalAuth;
@@ -318,9 +337,14 @@ public PSNamespaceAttributes BeginUpdateNamespace(string resourceGroupName,
318337
}
319338
if (identityType != null)
320339
{
321-
parameter.Identity = new Identity();
322-
parameter.Identity = FindIdentity(identityType);
323-
if(parameter.Identity.Type == ManagedServiceIdentityType.None)
340+
if(parameter.Identity == null)
341+
{
342+
parameter.Identity = new Identity();
343+
}
344+
345+
parameter.Identity.Type = FindIdentity(identityType);
346+
347+
if(parameter.Identity.Type == ManagedServiceIdentityType.None || parameter.Identity.Type == ManagedServiceIdentityType.SystemAssigned)
324348
{
325349
parameter.Identity.UserAssignedIdentities = null;
326350
}
@@ -340,6 +364,10 @@ public PSNamespaceAttributes BeginUpdateNamespace(string resourceGroupName,
340364
{
341365
parameter.Identity.UserAssignedIdentities = UserAssignedIdentities;
342366
}
367+
if (parameter.Identity.Type == ManagedServiceIdentityType.None || parameter.Identity.Type == ManagedServiceIdentityType.SystemAssigned)
368+
{
369+
throw new Exception("Please change -IdentityType to UserAssigned or 'SystemAssigned, UserAssigned' if you want to add User Assigned Identities");
370+
}
343371
}
344372

345373
if (encryptionConfigs != null)
@@ -377,25 +405,25 @@ public PSNamespaceAttributes BeginUpdateNamespace(string resourceGroupName,
377405
return new PSNamespaceAttributes(response);
378406
}
379407

380-
public Identity FindIdentity(string identityType)
408+
public ManagedServiceIdentityType FindIdentity(string identityType)
381409
{
382-
Identity identity = new Identity();
383-
410+
ManagedServiceIdentityType Type = ManagedServiceIdentityType.None;
384411
if (identityType == SystemAssigned)
385-
identity.Type = ManagedServiceIdentityType.SystemAssigned;
412+
Type = ManagedServiceIdentityType.SystemAssigned;
386413

387414
else if (identityType == UserAssigned)
388-
identity.Type = ManagedServiceIdentityType.UserAssigned;
415+
Type = ManagedServiceIdentityType.UserAssigned;
389416

390417
else if (identityType == SystemAssignedUserAssigned)
391-
identity.Type = ManagedServiceIdentityType.SystemAssignedUserAssigned;
418+
Type = ManagedServiceIdentityType.SystemAssignedUserAssigned;
392419

393420
else if (identityType == None)
394-
identity.Type = ManagedServiceIdentityType.None;
421+
Type = ManagedServiceIdentityType.None;
395422

396-
return identity;
423+
return Type;
397424
}
398425

426+
399427
public void BeginDeleteNamespace(string resourceGroupName, string namespaceName)
400428
{
401429
Client.Namespaces.DeleteAsync(resourceGroupName, namespaceName);

0 commit comments

Comments
 (0)