/
ApiSettings

ApiSettings

ApiSettings is a class that respresent the appsettings.json that is specific for the ODS/API.

#if NETSTANDARD
using System;
using System.Collections.Generic;
using System.Linq;
using EdFi.Ods.Common.Configuration;
using EdFi.Ods.Common.Extensions;

namespace EdFi.Ods.Api.Common.Configuration
{
    public class ApiSettings
    {
        private readonly Lazy<DatabaseEngine> _databaseEngine;
        private readonly Lazy<ApiMode> _apiMode;

        public ApiSettings()
        {
            _databaseEngine = new Lazy<DatabaseEngine>(
                () =>
                {
                    if (DatabaseEngine.TryParse(x => x.Value.EqualsIgnoreCase(Engine), out DatabaseEngine databaseEngine))
                    {
                        return databaseEngine;
                    }

                    throw new NotSupportedException(
                        $"Not supported database provider name \"{Engine}\". Supported database providers: {ApiConfigurationConstants.PostgresProviderName}, and {ApiConfigurationConstants.SqlServerProviderName}.");
                }
            );

            _apiMode = new Lazy<ApiMode>(
                () =>
                {
                    if (ApiMode.TryParse(x => x.Value.EqualsIgnoreCase(Mode), out ApiMode apiMode))
                    {
                        return apiMode;
                    }

                    throw new NotSupportedException(
                        $"Not supported Mode \"{Mode}\". Supported modes: {ApiConfigurationConstants.Sandbox}, {ApiConfigurationConstants.YearSpecific}, and {ApiConfigurationConstants.SharedInstance}.");
                }
            );
        }

        public string Mode { get; set; }

        public string Engine { get; set; }

        public bool EncryptSecrets { get; set; }

        public bool DisableSecurity { get; set; }

        public int[] Years { get; set; }

        public List<Feature> Features { get; set; } = new List<Feature>();

        public List<string> ExcludedExtensions { get; set; } = new List<string>();

        public int? BearerTokenTimeoutMinutes { get; set; }

        public bool? UseReverseProxyHeaders { get; set; }

        public string PluginFolder { get; set; }

        public DatabaseEngine GetDatabaseEngine() => _databaseEngine.Value;

        public ApiMode GetApiMode() => _apiMode.Value;

        public bool IsFeatureEnabled(string featureName)
            => Features.SingleOrDefault(x => x.Name.EqualsIgnoreCase(featureName) && x.IsEnabled) != null;
    }
}
#endif

Features are represented using the DTO

namespace EdFi.Ods.Api.Common.Configuration
{
    public class Feature
    {
        public string Name { get; set; }

        public bool IsEnabled { get; set; }
    }
}

Sample applicationsettings.json 

{
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "Microsoft": "Warning"
    }
  },
  "ConnectionStrings": {
    "EdFi_Ods_Empty": "Database=EdFi_Ods_Empty_Template; Data Source=(local); Trusted_Connection=True",
    "EdFi_Admin": "Server=(local); Database=EdFi_Admin; Trusted_Connection=True; Application Name=EdFi.Ods.WebApi;",
    "EdFi_Security": "Server=(local); Database=EdFi_Security; Trusted_Connection=True; Persist Security Info=True; Application Name=EdFi.Ods.WebApi;",
    "EdFi_Ods": "Server=(local); Database=EdFi_{0}; Trusted_Connection=True; Application Name=EdFi.Ods.WebApi;"
  },
  "ApiSettings": {
    "Mode": "sandbox",
    "Engine": "System.Data.SqlClient",
    "EncryptSecrets": false,
    "DisableSecurity": false,
    "UseReverseProxyHeaders": false,
    "Years": [],
    "Features": [
      {
        "Name": "Extensions",
        "IsEnabled": true
      },
      {
        "Name": "Profiles",
        "IsEnabled": false
      },
      {
        "Name": "ChangeQueries",
        "IsEnabled": false
      },
      {
        "Name": "OpenApiMetadata",
        "IsEnabled": true
      },
      {
        "Name": "Composites",
        "IsEnabled": true
      },
      {
        "Name": "IdentityManagement",
        "IsEnabled": false
      },
      {
        "Name": "OwnershipBasedAuthorization",
        "IsEnabled": false
      },
      {
        "Name": "UniqueIdValidation",
        "IsEnabled": false
      },
      {
        "Name": "AggregateDependencies",
        "IsEnabled": true
      }
    ],
    "ExcludedExtensions": [
    ],
    "PluginFolder": "./plugins"
  }
}


Related content

Platform Dev. Guide - Configuration
Platform Dev. Guide - Configuration
More like this
Platform Dev. Guide - Configuration
Platform Dev. Guide - Configuration
More like this
Features
More like this
Platform Dev. Guide - Configuration
Platform Dev. Guide - Configuration
More like this
External Configuration of ODS Connection Strings
External Configuration of ODS Connection Strings
More like this
External Configuration of ODS Connection Strings
External Configuration of ODS Connection Strings
More like this