Skip to content

Added entry parameter for preserving certificate Tags #64

Merged
spbsoluble merged 8 commits intorelease-3.1from
preserve_tags_75510
Oct 1, 2025
Merged

Added entry parameter for preserving certificate Tags #64
spbsoluble merged 8 commits intorelease-3.1from
preserve_tags_75510

Conversation

@joevanwanzeeleKF
Copy link
Contributor

Added optional entry parameter to indicate that existing Tags in KeyVault should be preserved if certificate is replaced.

@joevanwanzeeleKF joevanwanzeeleKF changed the title Added additional null check for certificate tags Added entry parameter for preserving certificate Tags Sep 19, 2025
@spbsoluble spbsoluble requested a review from Copilot September 25, 2025 16:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds functionality to preserve existing certificate tags in Azure Key Vault when certificates are replaced. The primary purpose is to allow users to maintain existing tags on certificates during re-enrollment or replacement operations while optionally merging them with new tags provided during the operation.

Key changes include:

  • Added PreserveExistingTags entry parameter to control tag preservation behavior
  • Updated certificate import logic to merge existing and new tags when preservation is enabled
  • Refactored tag handling to use Dictionary objects instead of JSON strings internally

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
integration-manifest.json Added new PreserveExistingTags boolean entry parameter definition
README.md Updated documentation to include the new entry parameter and reorganized content structure
CHANGELOG.md Added version 3.1.9 entry documenting the new feature and bug fix
AzureKeyVault/Jobs/Management.cs Implemented tag preservation logic in certificate addition workflow
AzureKeyVault/Jobs/Inventory.cs Minor logging improvement using Count property instead of Count() method
AzureKeyVault/Jobs/AzureKeyVaultJob.cs Code formatting and logging improvements for Azure cloud configuration
AzureKeyVault/Constants.cs Added constants for entry parameter names
AzureKeyVault/AzureClient.cs Refactored certificate import method to accept Dictionary instead of JSON string for tags
AzureKeyVault/AkvProperties.cs Updated cloud endpoint handling and made VaultURL property public

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


config.JobProperties.TryGetValue(EntryParameters.PRESERVE_TAGS, out preserveTagsObj);

preserveTags = (bool)preserveTagsObj;
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

Direct casting to bool can throw InvalidCastException if preserveTagsObj is null or not a boolean. Use safe casting with as bool? and provide a default value, or check for null first.

Suggested change
preserveTags = (bool)preserveTagsObj;
preserveTags = preserveTagsObj as bool? ?? false;

Copilot uses AI. Check for mistakes.
{
var existingTags = new Dictionary<string, string>();
logger.LogTrace($"checking for an existing cert with the alias {alias}");
var existing = AzClient.GetCertificate(alias).Result;
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

Using .Result on async operations can cause deadlocks and blocks the thread. Consider making this method async and using await, or use GetAwaiter().GetResult() if async conversion is not possible.

Copilot uses AI. Check for mistakes.
logger.LogTrace($"there is an existing cert..");
}

existingTags = existing?.Properties.Tags as Dictionary<string, string> ?? new Dictionary<string, string>();
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

The cast as Dictionary<string, string> may fail silently if Properties.Tags is not actually a Dictionary<string, string>. Consider using a safer conversion method or checking the type first.

Suggested change
existingTags = existing?.Properties.Tags as Dictionary<string, string> ?? new Dictionary<string, string>();
if (existing?.Properties.Tags is IDictionary<string, string> tagsDict)
{
existingTags = new Dictionary<string, string>(tagsDict);
}
else
{
existingTags = new Dictionary<string, string>();
}

Copilot uses AI. Check for mistakes.
}

public virtual async Task<KeyVaultCertificateWithPolicy> ImportCertificateAsync(string certName, string contents, string pfxPassword, string tags = null)
public virtual async Task<KeyVaultCertificateWithPolicy> ImportCertificateAsync(string certName, string contents, string pfxPassword, Dictionary<string,string> tags)
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

The method signature change from string tags = null to Dictionary<string,string> tags is a breaking change. Consider adding method overloads to maintain backward compatibility or make the parameter nullable with Dictionary<string,string>? tags = null.

Copilot uses AI. Check for mistakes.
@spbsoluble spbsoluble merged commit 9774959 into release-3.1 Oct 1, 2025
61 of 64 checks passed
@spbsoluble spbsoluble deleted the preserve_tags_75510 branch October 1, 2025 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants