Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions kcl/lib/steps/azure/identity.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import azure_pipelines.ap.steps

CreateManagedIdentity = lambda serviceConnection: str, subscription: str, resourceGroup: str, name: str, exportVar: str = "IDENTITY" -> steps.Step {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, you always need to create managed identity, then assign role, then bind it to a service account. Does it make sense to encapsulate the 3 steps into one?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for my case. I’m not binding it to a service account, and the role assignments target different resources and roles.

script = """
az identity create \\
--resource-group "${resourceGroup}" \\
--name "${name}" \\
--subscription "${subscription}"

IDENTITY=$(az identity show \\
--resource-group "${resourceGroup}" \\
--name "${name}" \\
--subscription "${subscription}")
echo "##vso[task.setvariable variable=${exportVar}_CLIENT_ID]$(echo "$IDENTITY" | jq -r '.clientId')"
echo "##vso[task.setvariable variable=${exportVar}_ID]$(echo "$IDENTITY" | jq -r '.id')"
"""
AzCli(serviceConnection, "Create managed identity ${name}", script)
}
12 changes: 12 additions & 0 deletions kcl/lib/steps/azure/role_assignment.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import azure_pipelines.ap.steps

CreateRoleAssignment = lambda serviceConnection: str, scope: str, role: str, assignee: str, subscription: str -> steps.Step {
Copy link
Copy Markdown
Collaborator

@wonderyl wonderyl May 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't provide much value, would it be easier if the user just call AzCli with the script directly?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When create a function, ask yourself, what does this function encapsulate?

Copy link
Copy Markdown
Collaborator Author

@xinWeiWei24 xinWeiWei24 May 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intended to be invoked multiple times, since the 3 input variables ( scope, role, assignee) can differ per call. Wrapping it as a function avoids duplicating the same CLI script logic.

script = """
az role assignment create \\
--scope "${scope}" \\
--role "${role}" \\
--assignee "${assignee}" \\
--subscription "${subscription}"
"""
AzCli(serviceConnection, "Assign role ${role} to ${assignee}", script)
}