@@ -428,8 +428,19 @@ func (azappcfg *AzureAppConfiguration) loadKeyValues(ctx context.Context, settin
428428 azappcfg .tracingOptions .UseAIConfiguration = useAIConfiguration
429429 azappcfg .tracingOptions .UseAIChatCompletionConfiguration = useAIChatCompletionConfiguration
430430
431- if err := azappcfg .loadSettingsFromSnapshotRefs (ctx , settingsClient , snapshotRefs , kvSettings , keyVaultRefs ); err != nil {
432- return err
431+ if len (snapshotRefs ) > 0 {
432+ var loadSnapshot snapshotSettingsLoader
433+ if client , ok := settingsClient .(* selectorSettingsClient ); ok {
434+ loadSnapshot = func (ctx context.Context , snapshotName string ) ([]azappconfig.Setting , error ) {
435+ return loadSnapshotSettings (ctx , client .client , snapshotName )
436+ }
437+ }
438+
439+ if loadSnapshot != nil {
440+ if err := azappcfg .loadSettingsFromSnapshotRefs (ctx , loadSnapshot , snapshotRefs , kvSettings , keyVaultRefs ); err != nil {
441+ return err
442+ }
443+ }
433444 }
434445
435446 secrets , err := azappcfg .loadKeyVaultSecrets (ctx , keyVaultRefs )
@@ -445,51 +456,60 @@ func (azappcfg *AzureAppConfiguration) loadKeyValues(ctx context.Context, settin
445456 return nil
446457}
447458
448- func (azappcfg * AzureAppConfiguration ) loadSettingsFromSnapshotRefs (ctx context.Context , settingsClient settingsClient , snapshotRefs map [string ]string , kvSettings map [string ]any , keyVaultRefs map [string ]string ) error {
459+ func (azappcfg * AzureAppConfiguration ) loadSettingsFromSnapshotRefs (ctx context.Context , loadSnapshot snapshotSettingsLoader , snapshotRefs map [string ]string , kvSettings map [string ]any , keyVaultRefs map [string ]string ) error {
449460 for key , snapshotRef := range snapshotRefs {
450461 // Parse the snapshot reference
451462 snapshotName , err := parseSnapshotReference (snapshotRef )
452463 if err != nil {
453464 return fmt .Errorf ("invalid format for Snapshot reference setting %s: %w" , key , err )
454465 }
455466
456- if client , ok := settingsClient .(* selectorSettingsClient ); ok {
457- // Load the snapshot settings
458- settingsFromSnapshot , err := loadSnapshotSettings (ctx , client .client , snapshotName )
459- if err != nil {
460- return fmt .Errorf ("failed to load snapshot settings: key=%s, error=%s" , key , err .Error ())
467+ // Load the snapshot settings
468+ settingsFromSnapshot , err := loadSnapshot (ctx , snapshotName )
469+ if err != nil {
470+ return fmt .Errorf ("failed to load snapshot settings: key=%s, error=%s" , key , err .Error ())
471+ }
472+
473+ for _ , setting := range settingsFromSnapshot {
474+ if setting .Key == nil {
475+ continue
461476 }
462477
463- for _ , setting := range settingsFromSnapshot {
464- if setting .ContentType == nil || setting .Value == nil || setting .Key == nil {
465- continue
466- }
478+ trimmedKey := azappcfg .trimPrefix (* setting .Key )
479+ if len (trimmedKey ) == 0 {
480+ log .Printf ("Key of the setting '%s' is trimmed to the empty string, just ignore it" , * setting .Key )
481+ continue
482+ }
467483
468- if * setting .ContentType == featureFlagContentType {
469- continue
470- }
484+ if setting .ContentType == nil || setting .Value == nil {
485+ kvSettings [trimmedKey ] = setting .Value
486+ continue
487+ }
471488
472- if * setting .ContentType == secretReferenceContentType {
473- keyVaultRefs [* setting .Key ] = * setting .Value
474- continue
475- }
489+ if * setting .ContentType == featureFlagContentType {
490+ continue
491+ }
476492
477- // Handle JSON content types (similar to regular key-value loading)
478- if isJsonContentType (setting .ContentType ) {
479- var v any
480- if err := json .Unmarshal ([]byte (* setting .Value ), & v ); err != nil {
481- // If the value is not valid JSON, try to remove comments and parse again
482- if err := json .Unmarshal (jsonc .StripComments ([]byte (* setting .Value )), & v ); err != nil {
483- // If still invalid, log the error and treat it as a plain string
484- log .Printf ("Failed to unmarshal JSON value from snapshot: key=%s, error=%s" , * setting .Key , err .Error ())
485- kvSettings [* setting .Key ] = setting .Value
486- continue
487- }
493+ if * setting .ContentType == secretReferenceContentType {
494+ keyVaultRefs [trimmedKey ] = * setting .Value
495+ continue
496+ }
497+
498+ // Handle JSON content types (similar to regular key-value loading)
499+ if isJsonContentType (setting .ContentType ) {
500+ var v any
501+ if err := json .Unmarshal ([]byte (* setting .Value ), & v ); err != nil {
502+ // If the value is not valid JSON, try to remove comments and parse again
503+ if err := json .Unmarshal (jsonc .StripComments ([]byte (* setting .Value )), & v ); err != nil {
504+ // If still invalid, log the error and treat it as a plain string
505+ log .Printf ("Failed to unmarshal JSON value from snapshot: key=%s, error=%s" , * setting .Key , err .Error ())
506+ kvSettings [trimmedKey ] = setting .Value
507+ continue
488508 }
489- kvSettings [* setting .Key ] = v
490- } else {
491- kvSettings [* setting .Key ] = setting .Value
492509 }
510+ kvSettings [trimmedKey ] = v
511+ } else {
512+ kvSettings [trimmedKey ] = setting .Value
493513 }
494514 }
495515 }
0 commit comments