Skip to content

[Data Factory] EncryptionConfiguration JSON unmarshaling fails due to case-sensitive field names #25725

@matthewyuh246

Description

@matthewyuh246

Description

The EncryptionConfiguration struct in the armdatafactory package (v8, v9, v10) fails to unmarshal JSON responses from the Azure Data Factory REST API due to case sensitivity mismatch in field names.

Current Behavior

  • Azure Data Factory REST API returns encryption properties with PascalCase: KeyName, VaultBaseUrl
  • SDK's UnmarshalJSON expects camelCase: keyName, vaultBaseUrl
  • Result: Encryption configuration fields remain nil after unmarshaling, even when CMK is configured

Expected Behavior

The SDK should correctly unmarshal encryption configuration from API responses regardless of the field name casing.

Steps to Reproduce

  1. Create a Data Factory with customer-managed key (CMK) encryption via Azure Portal
  2. Use the SDK to retrieve the factory:
    factory, err := factoriesClient.Get(ctx, resourceGroup, factoryName, nil)
  3. Check the encryption configuration:
    if factory.Properties.Encryption != nil {
        fmt.Println(factory.Properties.Encryption.KeyName)      // nil
        fmt.Println(factory.Properties.Encryption.VaultBaseURL) // nil
    }
  4. Both fields are nil despite being configured in Azure

Environment

  • SDK Version: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/datafactory/armdatafactory/v10 v10.0.0
  • Go Version: 1.21+
  • API Version: 2018-06-01

Evidence

REST API Response (verified with az rest):

{
  "properties": {
    "encryption": {
      "KeyName": "my-cmk-key",
      "VaultBaseUrl": "https://my-keyvault.vault.azure.com",
      "KeyVersion": "abc123..."
    }
  }
}

SDK UnmarshalJSON Implementation (models_serde.go):

func (e *EncryptionConfiguration) UnmarshalJSON(data []byte) error {
    // ...
    switch key {
    case "keyName":      // expects lowercase 'k'
        err = unpopulate(val, "KeyName", &e.KeyName)
    case "vaultBaseUrl": // expects lowercase 'v'
        err = unpopulate(val, "VaultBaseURL", &e.VaultBaseURL)
    }
}

Documentation vs Reality

Microsoft's official template documentation specifies camelCase field names:

However, the actual REST API returns PascalCase.

Impact

This prevents applications from:

  • Detecting whether CMK encryption is enabled
  • Validating security compliance
  • Auditing encryption configurations

Proposed Solution

Update UnmarshalJSON to accept both PascalCase and camelCase variants:

case "keyName", "KeyName":
    err = unpopulate(val, "KeyName", &e.KeyName)
case "keyVersion", "KeyVersion":
    err = unpopulate(val, "KeyVersion", &e.KeyVersion)
case "vaultBaseUrl", "VaultBaseUrl":
    err = unpopulate(val, "VaultBaseURL", &e.VaultBaseURL)

Note: I understand that models_serde.go is an auto-generated file managed by the codegen framework. I'm proposing this as a temporary fix to address the API compatibility issue. The root cause may be:

  1. Incorrect Swagger spec (should specify PascalCase to match actual API behavior)
  2. Azure API inconsistency (should return camelCase as per documentation)

I'm willing to help fix the proper source (Swagger spec or autorest template) if maintainers can provide guidance on where the fix should be applied.

Workaround

Currently using direct REST API calls with custom struct:

type encryptionConfig struct {
    KeyName      string `json:"KeyName"`
    VaultBaseURL string `json:"VaultBaseUrl"`
    KeyVersion   string `json:"KeyVersion"`
}

// Direct REST API call instead of SDK
url := fmt.Sprintf("https://management.azure.com/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataFactory/factories/%s?api-version=2018-06-01",
    subscriptionID, resourceGroup, factoryName)
// ... make request and unmarshal with custom struct

Affected Versions

Tested and confirmed in:

  • v8.0.0
  • v10.0.0

Likely affects all versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Data FactoryMgmtThis issue is related to a management-plane library.customer-reportedIssues that are reported by GitHub users external to the Azure organization.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions