8000 Add Azure Key Vault support for Atmos Stores by jamengual · Pull Request #963 · cloudposse/atmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add Azure Key Vault support for Atmos Stores #963

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 41 commits into from
Jun 25, 2025
Merged

Add Azure Key Vault support for Atmos Stores #963

merged 41 commits into from
Jun 25, 2025

Conversation

jamengual
Copy link
Contributor
@jamengual jamengual commented Jan 21, 2025

This pull request introduces support for Azure Key Vault as a new store type in the project, along with the necessary documentation and tests. The most important changes include updating dependencies, adding the Azure Key Vault store implementation, and updating the documentation to reflect the new store type.

Azure Key Vault Store Implementation:

Dependency Updates:

  • go.mod: Added several Azure SDK dependencies to support the new Azure Key Vault functionality. [1] [2] [3] [4]

Documentation Updates:

Summary by CodeRabbit

  • New Features
    • Added support for Azure Key Vault as a secret store, enabling secure storage and retrieval of secrets using Azure Key Vault.
  • Bug Fixes
    • Improved error handling for secret operations including access denied and not found cases.
  • Tests
    • Introduced comprehensive unit tests for Azure Key Vault integration, covering secret management operations and input validation.
  • Documentation
    • Updated Atmos stores documentation to include Azure Key Vault configuration, authentication methods, and usage examples.

@jamengual jamengual requested a review from a team as a code owner January 21, 2025 21:12
@mergify mergify bot added the triage Needs triage label Jan 21, 2025

This comment was marked as outdated.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (4)
pkg/store/azure_keyvault_store.go (3)

83-89: Refine secret name normalization for consistency.

Replacing "--" with "-" may not handle cases with more than two consecutive dashes. Using a regular expression to replace multiple dashes ensures consistent normalization of the secretName.

Apply this diff to enhance the handling:

-	secretName = strings.ReplaceAll(secretName, "--", "-")
+	secretName = regexp.MustCompile("-+").ReplaceAllString(secretName, "-")

162-179: Improve the exponential backoff strategy in retries.

The current backoff increases linearly, which might not be optimal for handling transient errors. Implementing an exponential backoff can provide better performance and resource utilization during retries.

Modify the sleep duration to implement exponential backoff:

 		// Add exponential backoff for retries
-		time.Sleep(time.Duration(i+1) * time.Second)
+		sleepDuration := time.Duration(math.Pow(2, float64(i))) * time.Second
+		time.Sleep(sleepDuration)

Don't forget to import the math package:

+	"math"

125-138: Consider adding context with timeout to the Set method.

Including a context with a timeout, similar to the Get method, can prevent potential hangs and improve responsiveness during secret storage operations.

Apply this diff to incorporate context with timeout:

 func (s *KeyVaultStore) Set(stack string, component string, key string, value interface{}) error {
     // Existing code...
 
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	defer cancel()
+
     _, err = s.client.SetSecret(ctx, secretName, params, nil)
     if err != nil {
         var respErr *azcore.ResponseError
         // Error handling...
website/docs/core-concepts/projects/configuration/stores.mdx (1)

203-206: Consider these typographical improvements:

  1. Use typographic quotes (") instead of straight quotes (") for the parameters.
  2. Use an en dash (–) instead of a hyphen (-) in the range "1-127".

Also applies to: 216-216

🧰 Tools
🪛 LanguageTool

[typographical] ~203-~203: Consider using a typographic opening quote here.
Context: ...ample, with these parameters: - prefix: "myapp" - stack: "prod-us-west" - compone...

(EN_QUOTES)


[typographical] ~203-~203: Consider using a typographic close quote here.
Context: ... with these parameters: - prefix: "myapp" - stack: "prod-us-west" - component: "d...

(EN_QUOTES)


[typographical] ~204-~204: Consider using a typographic opening quote here.
Context: ... parameters: - prefix: "myapp" - stack: "prod-us-west" - component: "database/pos...

(EN_QUOTES)


[typographical] ~204-~204: Consider using a typographic close quote here.
Context: ...- prefix: "myapp" - stack: "prod-us-west" - component: "database/postgres" - key:...

(EN_QUOTES)


[typographical] ~205-~205: Consider using a typographic opening quote here.
Context: ...p" - stack: "prod-us-west" - component: "database/postgres" - key: "password" Th...

(EN_QUOTES)


[typographical] ~205-~205: Consider using a typographic close quote here.
Context: ...us-west" - component: "database/postgres" - key: "password" The resulting Key Va...

(EN_QUOTES)


[typographical] ~206-~206: Consider using typographic quotation marks here.
Context: ...- component: "database/postgres" - key: "password" The resulting Key Vault secret name wo...

(EN_QUOTES)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 78ee9c6 and f834f8b.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • go.mod (5 hunks)
  • pkg/store/azure_keyvault_store.go (1 hunks)
  • pkg/store/azure_keyvault_store_test.go (1 hunks)
  • pkg/store/registry.go (1 hunks)
  • website/docs/core-concepts/projects/configuration/stores.mdx (2 hunks)
🧰 Additional context used
🪛 LanguageTool
website/docs/core-concepts/projects/configuration/stores.mdx

[typographical] ~203-~203: Consider using a typographic opening quote here.
Context: ...ample, with these parameters: - prefix: "myapp" - stack: "prod-us-west" - compone...

(EN_QUOTES)


[typographical] ~203-~203: Consider using a typographic close quote here.
Context: ... with these parameters: - prefix: "myapp" - stack: "prod-us-west" - component: "d...

(EN_QUOTES)


[typographical] ~204-~204: Consider using a typographic opening quote here.
Context: ... parameters: - prefix: "myapp" - stack: "prod-us-west" - component: "database/pos...

(EN_QUOTES)


[typographical] ~204-~204: Consider using a typographic close quote here.
Context: ...- prefix: "myapp" - stack: "prod-us-west" - component: "database/postgres" - key:...

(EN_QUOTES)


[typographical] ~205-~205: Consider using a typographic opening quote here.
Context: ...p" - stack: "prod-us-west" - component: "database/postgres" - key: "password" Th...

(EN_QUOTES)


[typographical] ~205-~205: Consider using a typographic close quote here.
Context: ...us-west" - component: "database/postgres" - key: "password" The resulting Key Va...

(EN_QUOTES)


[typographical] ~206-~206: Consider using typographic quotation marks here.
Context: ...- component: "database/postgres" - key: "password" The resulting Key Vault secret name wo...

(EN_QUOTES)


[typographical] ~216-~216: If specifying a range, consider using an en dash instead of a hyphen.
Context: ...dashes - Are case-insensitive - Must be 1-127 characters long The store automaticall...

(HYPHEN_TO_EN)

🪛 GitHub Actions: Dependency Review
go.mod

[error] Incompatible license detected: Package 'github.com/pkg/browser@0.0.0-20240102092130-5ac0b6a4141c' uses BSD-2-Clause license which is not compatible with project requirements

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (5)
pkg/store/registry.go (1)

42-53: Integration looks solid.

The addition of the Azure Key Vault case in the registry is clear and follows the existing pattern.

website/docs/core-concepts/projects/configuration/stores.mdx (4)

20-21: LGTM! Clear and concise introduction of Azure Key Vault support.

The configuration example is well-structured and includes all necessary fields with proper formatting.

Also applies to: 119-131


155-170: Well-documented authentication methods!

The authentication documentation clearly outlines all supported methods and provides appropriate recommendations for different environments.


171-193: Excellent examples that demonstrate practical usage!

The examples effectively cover both basic secret retrieval and component output storage scenarios.


195-235: Comprehensive documentation of key naming and error handling!

The documentation clearly explains the key name construction rules and provides helpful error messages.

🧰 Tools
🪛 LanguageTool

[typographical] ~203-~203: Consider using a typographic opening quote here.
Context: ...ample, with these parameters: - prefix: "myapp" - stack: "prod-us-west" - compone...

(EN_QUOTES)


[typographical] ~203-~203: Consider using a typographic close quote here.
Context: ... with these parameters: - prefix: "myapp" - stack: "prod-us-west" - component: "d...

(EN_QUOTES)


[typographical] ~204-~204: Consider using a typographic opening quote here.
Context: ... parameters: - prefix: "myapp" - stack: "prod-us-west" - component: "database/pos...

(EN_QUOTES)


[typographical] ~204-~204: Consider using a typographic close quote here.
Context: ...- prefix: "myapp" - stack: "prod-us-west" - component: "database/postgres" - key:...

(EN_QUOTES)


[typographical] ~205-~205: Consider using a typographic opening quote here.
Context: ...p" - stack: "prod-us-west" - component: "database/postgres" - key: "password" Th...

(EN_QUOTES)


[typographical] ~205-~205: Consider using a typographic close quote here.
Context: ...us-west" - component: "database/postgres" - key: "password" The resulting Key Va...

(EN_QUOTES)


[typographical] ~206-~206: Consider using typographic quotation marks here.
Context: ...- component: "database/postgres" - key: "password" The resulting Key Vault secret name wo...

(EN_QUOTES)


[typographical] ~216-~216: If specifying a range, consider using an en dash instead of a hyphen.
Context: ...dashes - Are case-insensitive - Must be 1-127 characters long The store automaticall...

(HYPHEN_TO_EN)

Copy link
Member
@mcalhoun mcalhoun left a comment

Choose a reason for hiding this comment

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

@jamengual thanks for taking a stab at this!

The pluggable store MUST implement the store interface in order to be used as a store. It looks like you changed the interface that it's implementing here. Could you take a shot at implementing that?

Also, please take a look at one of the other store implementations to see how we mock the calls to the underlying cloud provider in tests so we don't need to have each setup.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
pkg/store/azure_keyvault_store_test.go (1)

112-114: ⚠️ Potential issue

Handle errors returned by getKey function

The getKey function returns a (string, error), but the error isn't checked in the test. Capturing and asserting the error enhances test robustness.

Consider applying this change:

-			result := store.getKey(tt.stack, tt.component, tt.key)
-			assert.Equal(t, tt.expected, result)
+			result, err := store.getKey(tt.stack, tt.component, tt.key)
+			assert.NoError(t, err)
+			assert.Equal(t, tt.expected, result)
🧹 Nitpick comments (3)
pkg/store/azure_keyvault_store.go (3)

77-101: Simplify the replacement of multiple dashes in secret names

In the getKey function, replacing multiple consecutive dashes using strings.ReplaceAll might not handle more than two dashes effectively. Consider using a regular expression to replace any sequence of dashes with a single dash.

Here's a possible improvement:

-	secretName = strings.ReplaceAll(secretName, "--", "-")
+	re := regexp.MustCompile("-+")
+	secretName = re.ReplaceAllString(secretName, "-")

149-193: Use defer to ensure the context is canceled properly

In the Get method, calling cancel() immediately after GetSecret might not cover all execution paths, especially if future modifications are made. Using defer cancel() ensures the context is canceled when the function returns.

Here's how you might adjust the code:

-		ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+		ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+		defer cancel()

114-118: Enhance value type handling in Set method

Currently, the Set method only accepts string values. If there's a need to store other types, consider converting them to strings or handling different types appropriately.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f834f8b and 5223d81.

📒 Files selected for processing (2)
  • pkg/store/azure_keyvault_store.go (1 hunks)
  • pkg/store/azure_keyvault_store_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Acceptance Tests (macos-latest, macos)
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Acceptance Tests (ubuntu-latest, linux)
  • GitHub Check: [localstack] demo-localstack
  • GitHub Check: Summary
🔇 Additional comments (1)
pkg/store/azure_keyvault_store_test.go (1)

122-125: Great job initializing the mock client

In TestKeyVaultStore_InputValidation, initializing the client with a mock ensures the tests run without nil pointer dereferences.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (4)
pkg/store/azure_keyvault_store.go (2)

23-29: Consider adding validation for stackDelimiter.

The KeyVaultStore struct looks good, but consider adding validation in the constructor to ensure stackDelimiter is not empty when initialized.


125-146: Add retry mechanism for transient failures.

The Get operation should implement a retry mechanism for handling transient failures in Azure Key Vault operations.

+func (s *KeyVaultStore) Get(stack string, component string, key string) (interface{}, error) {
+    const maxRetries = 3
+    var lastErr error
+    
+    for i := 0; i < maxRetries; i++ {
+        value, err := s.tryGet(stack, component, key)
+        if err == nil {
+            return value, nil
+        }
+        
+        var respErr *azcore.ResponseError
+        if errors.As(err, &respErr) && respErr.StatusCode >= 500 {
+            lastErr = err
+            time.Sleep(time.Duration(i+1) * time.Second)
+            continue
+        }
+        return nil, err
+    }
+    return nil, fmt.Errorf("failed after %d retries: %w", maxRetries, lastErr)
+}
pkg/store/azure_keyvault_store_test.go (2)

18-21: Return mock response data in SetSecret.

The mock SetSecret method should return meaningful response data for better test coverage.

 func (m *MockKeyVaultClient) SetSecret(ctx context.Context, name string, parameters azsecrets.SetSecretParameters, options *azsecrets.SetSecretOptions) (azsecrets.SetSecretResponse, error) {
     args := m.Called(ctx, name, parameters)
-    return azsecrets.SetSecretResponse{}, args.Error(1)
+    if args.Get(0) == nil {
+        return azsecrets.SetSecretResponse{}, args.Error(1)
+    }
+    return args.Get(0).(azsecrets.SetSecretResponse), args.Error(1)
 }

66-110: Add test cases for complex stack paths.

The TestKeyVaultStore_getKey should include additional test cases for:

  • Stack paths with multiple segments
  • Component paths with nested structures
  • Keys containing special characters
+        {
+            name:      "complex path",
+            stack:     "prod-east",
+            component: "service/api/v1",
+            key:       "database.credentials",
+            expected:  "prefix-prod-east-service-api-v1-database-credentials",
+            wantErr:   false,
+        },
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5223d81 and 44fbfd4.

📒 Files selected for processing (2)
  • pkg/store/azure_keyvault_store.go (1 hunks)
  • pkg/store/azure_keyvault_store_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (1)
pkg/store/azure_keyvault_store.go (1)

17-21: LGTM! Well-defined interface for mocking.

The KeyVaultClient interface is well-designed for testing purposes, making it easy to mock Azure Key Vault operations.

@osterman osterman added minor New features that do not break anything and removed triage Needs triage labels Jan 22, 2025
Copy link
mergify bot commented Feb 20, 2025

💥 This pull request now has conflicts. Could you fix it @jamengual? 🙏

@mergify mergify bot added the conflict This PR has conflicts label Feb 20, 2025
@mergify mergify bot closed this Feb 20, 2025
Copy link
mergify bot commented Feb 20, 2025

This PR was closed due to inactivity and merge conflicts. 😭
Please resolve the conflicts and reopen if necessary.

@mergify mergify bot removed the conflict This PR has conflicts label Feb 20, 2025
@mergify mergify bot removed the conflict This PR has conflicts label May 21, 2025
@jamengual jamengual reopened this May 23, 2025
Copy link
mergify bot commented May 23, 2025

💥 This pull request now has conflicts. Could you fix it @jamengual? 🙏

@mergify mergify bot added the conflict This PR has conflicts label May 23, 2025
@mergify mergify bot closed this May 30, 2025
Copy link
mergify bot commented May 30, 2025

This PR was closed due to inactivity and merge conflicts. 😭
Please resolve the conflicts and reopen if necessary.

@mergify mergify bot removed the conflict This PR has conflicts label May 30, 2025
@jamengual jamengual reopened this Jun 24, 2025
Copy link
mergify bot commented Jun 24, 2025

💥 This pull request now has conflicts. Could you fix it @jamengual? 🙏

@mergify mergify bot added the conflict This PR has conflicts label Jun 24, 2025
@github-actions github-actions bot added the size/l Large size PR label Jun 24, 2025
@mergify mergify bot removed the conflict This PR has conflicts label Jun 24, 2025
Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (2)
pkg/store/azure_keyvault_store.go (2)

140-140: Add context timeout for Azure operations.

Past reviews identified this issue and it was confirmed as a good suggestion by maintainers. The Set operation uses context.Background() without a timeout, which could cause hanging operations.

-	_, err = s.client.SetSecret(context.Background(), secretName, params, nil)
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	defer cancel()
+	_, err = s.client.SetSecret(ctx, secretName, params, nil)

You'll also need to import the time package.


168-168: Add context timeout for Get operation.

Same issue as the Set method - this was identified in past reviews and confirmed as important by maintainers.

-	resp, err := s.client.GetSecret(context.Background(), secretName, "", nil)
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	defer cancel()
+	resp, err := s.client.GetSecret(ctx, secretName, "", nil)
🧹 Nitpick comments (4)
pkg/store/azure_keyvault_store.go (4)

21-23: Remove unused regex or integrate it for validation.

Static analysis correctly identifies that azureKeyVaultNameRegex is unused. Either remove this variable or integrate it into the validation logic within normalizeSecretName method.

-// Azure Key Vault secret names must match the pattern: ^[0-9a-zA-Z-]+$
-// They can only contain alphanumeric characters and hyphens
-var azureKeyVaultNameRegex = regexp.MustCompile(`^[0-9a-zA-Z-]+$`)

85-97: Consider creating a constant for the hyphen delimiter.

The method works well, but static analysis suggests creating a named constant for the "-" string literal that appears multiple times throughout the file.

+const (
+	hyphenDelimiter = "-"
+	// ... other constants
+)

 func (s *AzureKeyVaultStore) normalizeSecretName(key string) string {
 	// Replace any non-alphanumeric characters with hyphens
-	normalized := regexp.MustCompile(`[^0-9a-zA-Z-]`).ReplaceAllString(key, "-")
+	normalized := regexp.MustCompile(`[^0-9a-zA-Z-]`).ReplaceAllString(key, hyphenDelimiter)
 	// Replace multiple consecutive hyphens with a single hyphen
-	normalized = regexp.MustCompile(`-+`).ReplaceAllString(normalized, "-")
+	normalized = regexp.MustCompile(`-+`).ReplaceAllString(normalized, hyphenDelimiter)
 	// Remove leading and trailing hyphens
-	normalized = strings.Trim(normalized, "-")
+	normalized = strings.Trim(normalized, hyphenDelimiter)

186-192: Clarify error handling in JSON unmarshaling.

Static analysis correctly identifies that line 188 produces an error but line 190 returns nil for the error. This loses context about the unmarshaling failure.

If the intention is to silently fall back to string when JSON parsing fails, consider adding a comment to clarify this behavior:

 	// Try to unmarshal as JSON first, fallback to string if it fails
 	var result interface{}
 	if err := json.Unmarshal([]byte(*resp.Value), &result); err != nil {
-		// If JSON unmarshaling fails, return as string
+		// If JSON unmarshaling fails, return raw value as string (this is expected behavior)
 		return *resp.Value, nil
 	}

152-193: Consider refactoring to reduce cyclomatic complexity.

The method has a cyclomatic complexity of 11, which exceeds the threshold. While functional, consider extracting error handling or JSON F438 processing into helper methods to improve maintainability.

Example approach:

func (s *AzureKeyVaultStore) Get(stack string, component string, key string) (interface{}, error) {
    if err := s.validateGetInputs(stack, component, key); err != nil {
        return nil, err
    }
    
    secretName, err := s.getKey(stack, component, key)
    if err != nil {
        return nil, fmt.Errorf(errWrapFormat, ErrGetKey, err)
    }
    
    resp, err := s.getSecretFromAzure(secretName)
    if err != nil {
        return nil, err
    }
    
    return s.parseSecretValue(resp.Value), nil
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 367b53d and 6f79b5e.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • go.mod (5 hunks)
  • pkg/store/azure_keyvault_store.go (1 hunks)
  • pkg/store/azure_keyvault_store_test.go (1 hunks)
  • pkg/store/errors.go (2 hunks)
  • pkg/store/google_secret_manager_store_test.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • pkg/store/google_secret_manager_store_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • pkg/store/errors.go
  • go.mod
  • pkg/store/azure_keyvault_store_test.go
🧰 Additional context used
📓 Path-based instructions (1)
`pkg/*/*.go`: Organize feature implementations in subdirectories under pkg/ with separate files for each feature.

pkg/*/*.go: Organize feature implementations in subdirectories under pkg/ with separate files for each feature.

  • pkg/store/azure_keyvault_store.go
🪛 golangci-lint (1.64.8)
pkg/store/azure_keyvault_store.go

[error] 23-23: var azureKeyVaultNameRegex is unused

(unused)


[error] 91-91: add-constant: string literal "-" appears, at least, 4 times, create a named constant for it

(revive)


[error] 152-152: cyclomatic: function (*AzureKeyVaultStore).Get has cyclomatic complexity 11 (> max enabled 10)

(revive)


[error] 190-190: error is not nil (line 188) but it returns nil

(nilerr)

⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Lint (golangci)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
  • GitHub Check: Build (ubuntu-latest, linux)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Build (macos-latest, macos)
  • GitHub Check: website-deploy-preview
  • GitHub Check: Lint (golangci)
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
pkg/store/azure_keyvault_store.go (2)

25-29: Clean interface design.

Good focused interface that includes only the methods actually used by the implementation. This makes testing easier and avoids unnecessary complexity.


48-81: Well-structured constructor with proper validation.

Good implementation that validates required inputs, handles errors appropriately, and sets sensible defaults. The use of static errors (like ErrVaultURLRequired) addresses previous feedback about avoiding dynamic error creation.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (2)
pkg/store/azure_keyvault_store.go (2)

141-141: Add context timeout for Azure operations.

The Set operation still uses context.Background() without a timeout, which could cause hanging operations with Azure services.

Apply this pattern for better resilience:

+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	defer cancel()
-	_, err = s.client.SetSecret(context.Background(), secretName, params, nil)
+	_, err = s.client.SetSecret(ctx, secretName, params, nil)

169-169: Add context timeout for Get operation.

Similar to the Set method, this should use a context with timeout to prevent hanging operations.

+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	defer cancel()
-	resp, err := s.client.GetSecret(context.Background(), secretName, "", nil)
+	resp, err := s.client.GetSecret(ctx, secretName, "", nil)
🧹 Nitpick comments (1)
pkg/store/azure_keyvault_store.go (1)

170-194: Consider refactoring to reduce cyclomatic complexity.

The method exceeds complexity limits due to nested error handling. Consider extracting error processing into a helper method.

+func (s *AzureKeyVaultStore) handleGetSecretError(err error, secretName string) error {
+	var respErr *azcore.ResponseError
+	if errors.As(err, &respErr) {
+		switch respErr.StatusCode {
+		case statusCodeNotFound:
+			return fmt.Errorf(errWrapFormatWithID, ErrResourceNotFound, secretName, err)
+		case statusCodeForbidden:
+			return fmt.Errorf(errWrapFormatWithID, ErrPermissionDenied, fmt.Sprintf("secret %s", secretName), err)
+		}
+	}
+	return fmt.Errorf(errWrapFormat, ErrAccessSecret, err)
+}

Note: The static analysis warning about line 191 is a false positive - returning the raw string when JSON unmarshaling fails is the intended fallback behavior.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f79b5e and 76d9115.

📒 Files selected for processing (3)
  • pkg/store/azure_keyvault_store.go (1 hunks)
  • pkg/store/registry.go (1 hunks)
  • website/docs/core-concepts/projects/configuration/stores.mdx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/store/registry.go
  • website/docs/core-concepts/projects/configuration/stores.mdx
🧰 Additional context used
📓 Path-based instructions (1)
`pkg/*/*.go`: Organize feature implementations in subdirectories under pkg/ with separate files for each feature.

pkg/*/*.go: Organize feature implementations in subdirectories under pkg/ with separate files for each feature.

  • pkg/store/azure_keyvault_store.go
🪛 golangci-lint (1.64.8)
pkg/store/azure_keyvault_store.go

[error] 153-153: cyclomatic: function (*AzureKeyVaultStore).Get has cyclomatic complexity 11 (> max enabled 10)

(revive)


[error] 191-191: error is not nil (line 189) but it returns nil

(nilerr)

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Analyze (go)
  • GitHub Check: Lint (golangci)
  • GitHub Check: website-deploy-preview
  • GitHub Check: Build (ubuntu-latest, linux)
  • GitHub Check: Build (windows-latest, windows)
🔇 Additional comments (5)
pkg/store/azure_keyvault_store.go (5)

1-14: Package and imports look solid.

Clean import organization with all necessary Azure SDK dependencies properly included.


16-30: Constants and interface definition are well-structured.

Good addition of status code constants to eliminate magic numbers, and the client interface design enables proper mocking for tests.


32-47: Struct definitions follow good design patterns.

The Azure prefix naming and interface compliance check demonstrate solid Go practices. Options struct is properly configured for configuration parsing.


49-82: Constructor implementation is robust.

Good use of static errors, proper Azure credential handling, and sensible default value management. The validation and error wrapping follow established patterns.


84-112: Helper methods demonstrate thoughtful design.

The secret name normalization handles Azure Key Vault constraints elegantly, and the getKey integration maintains consistency with other store implementations.

@jamengual
Copy link
Contributor Author

@mcalhoun @aknysh I addressed the feedback, tested, and it is ready for review

@aknysh aknysh added no-release Do not create a new release (wait for additional code changes) and removed minor New features that do not break anything labels Jun 25, 2025
@aknysh aknysh requested review from mcalhoun and aknysh June 25, 2025 02:58
Copy link
Member
@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

thanks @jamengual

@aknysh aknysh merged commit 5521295 into main Jun 25, 2025
62 checks passed
@aknysh aknysh deleted the add_keyvaul_store branch June 25, 2025 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-release Do not create a new release (wait for additional code changes) size/l Large size PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0