-
Notifications
You must be signed in to change notification settings - Fork 951
Description
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
nilafter 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
- Create a Data Factory with customer-managed key (CMK) encryption via Azure Portal
- Use the SDK to retrieve the factory:
factory, err := factoriesClient.Get(ctx, resourceGroup, factoryName, nil)
- Check the encryption configuration:
if factory.Properties.Encryption != nil { fmt.Println(factory.Properties.Encryption.KeyName) // nil fmt.Println(factory.Properties.Encryption.VaultBaseURL) // nil }
- Both fields are
nildespite being configured in Azure
Environment
- SDK Version:
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/datafactory/armdatafactory/v10v10.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:
- Incorrect Swagger spec (should specify PascalCase to match actual API behavior)
- 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 structAffected Versions
Tested and confirmed in:
- v8.0.0
- v10.0.0
Likely affects all versions.