Skip to content
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

ID-1263 Correct Error Deleting Action Managed Identities #1420

Merged
merged 3 commits into from
May 2, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ class PostgresDirectoryDAO(protected val writeDbRef: DbReference, protected val
val actionManagedIdentityColumn = ActionManagedIdentityTable.column
val resourceTable = ResourceTable.syntax
val resourceTypeTable = ResourceTypeTable.syntax
val resourceActionTable = ResourceActionTable.syntax
val managedResourceGroupTable = AzureManagedResourceGroupTable.syntax

val updateAmiQuery =
Expand All @@ -1125,7 +1126,11 @@ class PostgresDirectoryDAO(protected val writeDbRef: DbReference, protected val
${actionManagedIdentityColumn.displayName} = ${actionManagedIdentity.displayName}
where
${actionManagedIdentityColumn.resourceId} = (select ${resourceTable.result.id} from ${ResourceTable as resourceTable} left join ${ResourceTypeTable as resourceTypeTable} on ${resourceTable.resourceTypeId} = ${resourceTypeTable.id} where ${resourceTable.name} = ${actionManagedIdentity.id.resourceId.resourceId} and ${resourceTypeTable.name} = ${actionManagedIdentity.id.resourceId.resourceTypeName})
and ${actionManagedIdentityColumn.resourceActionId} = (select ${ResourceActionTable.column.id} from ${ResourceActionTable.table} where ${ResourceActionTable.column.action} = ${actionManagedIdentity.id.action})
and ${actionManagedIdentityColumn.resourceActionId} = (select ${resourceActionTable.result.id}
from ${ResourceActionTable as resourceActionTable}
left join ${ResourceTypeTable as resourceTypeTable} on ${resourceActionTable.resourceTypeId} = ${resourceTypeTable.id}
where ${resourceActionTable.action} = ${actionManagedIdentity.id.action}
and ${resourceTypeTable.name} = ${actionManagedIdentity.id.resourceId.resourceTypeName})
and ${actionManagedIdentityColumn.managedResourceGroupId} = (select ${managedResourceGroupTable.result.id}
from ${AzureManagedResourceGroupTable as managedResourceGroupTable}
where ${managedResourceGroupTable.billingProfileId} = ${actionManagedIdentity.id.billingProfileId})
Expand All @@ -1143,15 +1148,25 @@ class PostgresDirectoryDAO(protected val writeDbRef: DbReference, protected val
val actionManagedIdentityTable = ActionManagedIdentityTable.syntax
val resourceTable = ResourceTable.syntax
val resourceTypeTable = ResourceTypeTable.syntax
val resourceActionTable = ResourceActionTable.syntax
val managedResourceGroupTable = AzureManagedResourceGroupTable.syntax

val deleteActionManagedIdentityQuery =
samsql"""delete from ${ActionManagedIdentityTable.table}
where ${actionManagedIdentityTable.resourceId} = (select ${resourceTable.result.id} from ${ResourceTable as resourceTable} left join ${ResourceTypeTable as resourceTypeTable} on ${resourceTable.resourceTypeId} = ${resourceTypeTable.id} where ${resourceTable.name} = ${actionManagedIdentityId.resourceId.resourceId} and ${resourceTypeTable.name} = ${actionManagedIdentityId.resourceId.resourceTypeName})
where ${actionManagedIdentityTable.resourceId} = (select ${resourceTable.result.id}
from ${ResourceTable as resourceTable}
left join ${ResourceTypeTable as resourceTypeTable} on ${resourceTable.resourceTypeId} = ${resourceTypeTable.id}
where ${resourceTable.name} = ${actionManagedIdentityId.resourceId.resourceId}
and ${resourceTypeTable.name} = ${actionManagedIdentityId.resourceId.resourceTypeName})
and ${actionManagedIdentityTable.managedResourceGroupId} = (select ${managedResourceGroupTable.result.id}
from ${AzureManagedResourceGroupTable as managedResourceGroupTable}
where ${managedResourceGroupTable.billingProfileId} = ${actionManagedIdentityId.billingProfileId})
and ${actionManagedIdentityTable.resourceActionId} = (select ${ResourceActionTable.column.id} from ${ResourceActionTable.table} where ${ResourceActionTable.column.action} = ${actionManagedIdentityId.action})"""
and ${actionManagedIdentityTable.resourceActionId} = (select ${resourceActionTable.result.id}
from ${ResourceActionTable as resourceActionTable}
left join ${ResourceTypeTable as resourceTypeTable} on ${resourceActionTable.resourceTypeId} = ${resourceTypeTable.id}
where ${resourceActionTable.action} = ${actionManagedIdentityId.action}
and ${resourceTypeTable.name} = ${actionManagedIdentityId.resourceId.resourceTypeName})
"""
if (deleteActionManagedIdentityQuery.update().apply() != 1) {
throw new WorkbenchException(s"${actionManagedIdentityId} cannot be deleted because it already does not exist")
}
Expand Down
Loading