Azure DevOps Integration
Relevant source files
The following files were used as context for generating this wiki page:The Azure DevOps integration provides the iac-recert-engine with the capability to connect to and interact with Git repositories hosted on Azure DevOps. It is one of several supported Git providers, alongside GitHub and GitLab. The primary purpose of this provider is to enable the core recertification workflow by fetching file modification history and creating pull requests for recertification tasks directly within the Azure DevOps environment.
This provider implements the GitProvider interface, allowing the main engine to use it interchangeably with other providers. However, its current implementation is partial, with a focus on essential read operations and pull request creation, while many branch and pull request management features are not yet implemented.
Sources: internal/provider/azure.go, internal/config/types.go:21, internal/engine/engine.go:35-38
Configuration
To use the Azure DevOps provider, you must set the provider field to "azure" in both the repository and auth sections of the config.yaml file. The engine requires a Personal Access Token (PAT) for authentication, which must be provided via an environment variable specified in auth.token_env.
Sources: example.config.yaml:8, example.config.yaml:13, internal/config/types.go:21, internal/config/types.go:26
The following table details the necessary configuration options:
| Section | Key | Value | Description - |
|---|---|---|---|
repository | url | https://dev.azure.com/{org}/{project}/_git/{repo} or https://{org}.visualstudio.com/{project}/_git/{repo} | The full URL of the Azure DevOps repository. - |
repository | provider | azure | Specifies that the Azure DevOps provider should be used. - |
auth | provider | azure | Must match the repository provider. - |
auth | token_env | AZURE_DEVOPS_TOKEN (example) | The name of the environment variable containing the Azure DevOps PAT. - |
Sources: internal/config/types.go:19-28, example.config.yaml:5-14
Architecture
The integration is encapsulated within the AzureDevOpsProvider struct. This struct holds the client connection, repository details parsed from the configuration, and a logger instance.
AzureDevOpsProvider Structure
This diagram shows the internal components of the AzureDevOpsProvider.
Sources: internal/provider/azure.go:21-28
Initialization Flow
The NewAzureDevOpsProvider function is responsible for creating and configuring an instance of the provider.
- It retrieves the authentication token from the environment variable defined in the configuration.
- It parses the repository URL to extract the organization, project, and repository name. It supports both
dev.azure.comandvisualstudio.comURL formats. - It constructs the
baseURLfor all subsequent API calls. - It returns an initialized
AzureDevOpsProviderstruct.
This diagram illustrates the initialization process.
Sources: internal/provider/azure.go:30-73
API Interaction
All communication with the Azure DevOps REST API is handled by the doRequest method. This centralized function is responsible for:
- Marshalling the request body into JSON if provided.
- Constructing the full request URL.
- Creating an
http.Requestwith the appropriate method and context. - Setting the
Authorizationheader using Basic Authentication with the PAT. - Setting the
Content-Typeheader toapplication/json. - Executing the request and checking for non-successful status codes (>= 400).
- Decoding the JSON response into a provided result interface.
Sources: internal/provider/azure.go:75-110
Implemented Functionality
The provider currently implements a subset of the GitProvider interface, focusing on the features essential for the recertification workflow.
Get Last Modification Date
The GetLastModificationDate method retrieves the details of the last commit for a specific file. It makes a GET request to the Azure DevOps Commits API endpoint: /git/repositories/{repositoryId}/commits. The query is filtered by searchCriteria.itemPath and limited to the top 1 result to get the most recent commit.
The following sequence diagram shows the interaction:
Create Pull Request
The CreatePullRequest method creates a new pull request in the Azure DevOps repository. It sends a POST request to the /git/repositories/{repositoryId}/pullrequests endpoint. The request body includes the source branch, target branch, title, and description.
The following sequence diagram shows the interaction:
Unimplemented Functionality
A significant number of methods in the GitProvider interface are not yet implemented for Azure DevOps. These methods currently return a "not implemented" error, limiting the engine's ability to manage branches and pull requests beyond creation.
The following table lists the unimplemented functions:
| Function | Description |
|---|---|
BranchExists | Checks if a branch exists. |
CreateBranch | Creates a new branch. |
CreateCommit | Creates a new commit with file changes. |
PullRequestExists | Checks if a pull request already exists. |
UpdatePullRequest | Updates an existing pull request. |
ClosePullRequest | Closes a pull request. |
AssignPullRequest | Assigns users to a pull request. |
RequestReviewers | Requests reviews from users on a pull request. |
AddLabels | Adds labels to a pull request. |
AddComment | Adds a comment to a pull request. |
Sources: internal/provider/azure.go:153, internal/provider/azure.go:158, internal/provider/azure.go:163, internal/provider/azure.go:167, internal/provider/azure.go:197, internal/provider/azure.go:201, internal/provider/azure.go:205, internal/provider/azure.go:209, internal/provider/azure.go:213, internal/provider/azure.go:217
Summary
The Azure DevOps integration for the iac-recert-engine provides foundational support for running recertification checks against Azure-hosted repositories. It can successfully determine the last modification date of files and create pull requests to initiate the review process. However, its capabilities are currently limited, as many branch and pull request management functions found in other providers like GitHub are not implemented. Developers using this integration should be aware of these limitations.
Sources: internal/provider/azure.go