Skip to content

Fixing identity update bug #17248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 42 additions & 14 deletions src/EventHub/EventHub/Utilities/EventHubsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public PSNamespaceAttributes BeginCreateNamespace(string resourceGroupName, stri
if (identityType != null)
{
parameter.Identity = new Identity();
parameter.Identity = FindIdentity(identityType);
parameter.Identity.Type = FindIdentity(identityType);
}

if (identityId != null)
Expand All @@ -142,6 +142,10 @@ 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)
Expand Down Expand Up @@ -233,8 +237,23 @@ public PSNamespaceAttributes BeginUpdateNamespace(string resourceGroupName,
if (isKafkaEnabled)
parameter.KafkaEnabled = isKafkaEnabled;

if (isIdentity)
parameter.Identity = new Identity() { Type = ManagedServiceIdentityType.SystemAssigned };
if (isIdentity) {
if(parameter.Identity == null)
{
parameter.Identity = new Identity() { Type = ManagedServiceIdentityType.SystemAssigned };
}
else
{
if(parameter.Identity.Type == ManagedServiceIdentityType.None)
{
parameter.Identity = new Identity() { Type = ManagedServiceIdentityType.SystemAssigned };
}
if (parameter.Identity.Type == ManagedServiceIdentityType.UserAssigned)
{
parameter.Identity = new Identity() { Type = ManagedServiceIdentityType.SystemAssignedUserAssigned };
}
}
}

if (isDisableLocalAuth)
parameter.DisableLocalAuth = isDisableLocalAuth;
Expand Down Expand Up @@ -318,9 +337,14 @@ public PSNamespaceAttributes BeginUpdateNamespace(string resourceGroupName,
}
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;
}
Expand All @@ -340,6 +364,10 @@ public PSNamespaceAttributes BeginUpdateNamespace(string resourceGroupName,
{
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)
Expand Down Expand Up @@ -377,25 +405,25 @@ public PSNamespaceAttributes BeginUpdateNamespace(string resourceGroupName,
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 void BeginDeleteNamespace(string resourceGroupName, string namespaceName)
{
Client.Namespaces.DeleteAsync(resourceGroupName, namespaceName);
Expand Down