Open Closed

Default settings applied on appsettings.json is not propagating when deployed as an ECS Task #8275


User avatar
0
Bryan-EDV created

I understand that we can change certain settings in the appsetings.json. This applies the default settings to the host and tenant level.

  "Settings": {
    "Abp.Identity.User.IsUserNameUpdateEnabled": false,
    "Abp.Identity.User.IsEmailUpdateEnabled": false,
    "Abp.Account.IsSelfRegistrationEnabled": false
  },

When testing locally using dotnet run or using a docker container, these settings work fine. I can see that the values in the settings page are updated correctly

However they are not applied when we deploy this to ECS (ABP backend is running in an ECS Task)

I've even tried to update using environment variables. But it doesn't work either

Could you outline any possible reason for this? I've checked that those settings are not overwritten in the DB


2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    you can override SettingProvider and SettingManagement to log the setting value from where and check it log.

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(ISettingProvider))]
    public class MySettingProvider : SettingProvider
    {
        private readonly ILogger<MySettingManagement> _logger;
        public MySettingProvider([NotNull] ISettingDefinitionManager settingDefinitionManager, [NotNull] ISettingEncryptionService settingEncryptionService, [NotNull] ISettingValueProviderManager settingValueProviderManager, ILogger<MySettingManagement> logger) : base(settingDefinitionManager, settingEncryptionService, settingValueProviderManager)
        {
            _logger = logger;
        }
    
        protected async override Task<string> GetOrNullValueFromProvidersAsync(IEnumerable<ISettingValueProvider> providers, SettingDefinition setting)
        {
            foreach (var provider in providers)
            {
                var value = await provider.GetOrNullAsync(setting);
                _logger.LogInformation($"Get value from SettingProvider: {provider.Name}, Value: {value}");
                if (value != null)
                {
                    return value;
                }
            }
    
            return null;
        }
    }
    
    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(ISettingManager))]
    public class MySettingManagement : SettingManager
    {
        private readonly ILogger<MySettingManagement> _logger;
        public MySettingManagement(IOptions<SettingManagementOptions> options, IServiceProvider serviceProvider, ISettingDefinitionManager settingDefinitionManager, ISettingEncryptionService settingEncryptionService, ISettingManagementStore settingManagementStore, ILogger<MySettingManagement> logger) : base(options, serviceProvider, settingDefinitionManager, settingEncryptionService, settingManagementStore)
        {
            _logger = logger;
        }
    
        protected async override Task<string> GetOrNullInternalAsync(string name, string providerName, string providerKey, bool fallback = true)
        {
            var setting = await SettingDefinitionManager.GetAsync(name);
            var providers = Enumerable
                .Reverse(Providers);
    
            if (providerName != null)
            {
                providers = providers.SkipWhile(c => c.Name != providerName);
            }
    
            if (!fallback || !setting.IsInherited)
            {
                providers = providers.TakeWhile(c => c.Name == providerName);
            }
    
            string value = null;
            foreach (var provider in providers)
            {
                value = await provider.GetOrNullAsync(
                    setting,
                    provider.Name == providerName ? providerKey : null
                );
    
                _logger.LogInformation($"Get value from SettingProvider: {provider.Name}, Value: {value}");
                if (value != null)
                {
                    break;
                }
            }
    
            if (setting.IsEncrypted)
            {
                value = SettingEncryptionService.Decrypt(setting, value);
            }
    
            return value;
        }
    }
    
  • User Avatar
    0
    Bryan-EDV created

    Will post the results here soon

Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11