Skip to main content

Configuration

Satélite API uses ASP.NET Core’s configuration system to manage settings across different environments. Configuration is loaded from environment variables, Azure App Settings, and configuration files.

Database Connection Strings

The application connects to multiple SQL Server databases using Entity Framework Core with connection pooling for optimal performance.

Database Contexts

Satélite API uses seven distinct database contexts, each configured with pooled connections:
// Program.cs:272-273
builder.Services.AddPooledDbContextFactory<SateliteDBContext>(
    options => options.UseSqlServer(builder.Configuration.GetConnectionString("SateliteConnection")));
Connection Pooling: All database contexts use AddPooledDbContextFactory for improved performance under high load.
Retry Logic: BitacoraCumplimientoDBContext and NexusDBContext include automatic retry on failure with 5 attempts and 30-second maximum delay.

Connection String Format

SQL Server connection strings should follow this format:
Server=<server-name>.database.windows.net;Database=<database-name>;User Id=<username>;Password=<password>;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
Example Configuration in Azure:
1

Navigate to Configuration

In Azure Portal, go to your Web App > Configuration > Connection strings
2

Add Connection Strings

Add each connection string with type SQLServer:
  • SateliteConnection
  • CajachicaConnection
  • ConsolidadoConnection
  • AnticiposConnection
  • CuboComercialConnection
  • NexusConnection
  • CentinelaConnection
3

Save and Restart

Click Save and restart the Web App to apply changes

JWT Authentication Configuration

Satélite API uses JWT (JSON Web Tokens) for authentication with cookie and header support.

JWT Settings

// Program.cs:343-354
options.TokenValidationParameters =
    new TokenValidationParameters
    {
        ValidateIssuer = true,
        ValidateAudience = true,
        ValidateLifetime = true,
        ValidateIssuerSigningKey = true,
        ValidIssuer = builder.Configuration["Jwt:Issuer"],
        ValidAudience = builder.Configuration["Jwt:Audience"],
        IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"]))
    };

Required JWT Configuration

Add these settings to Azure App Settings or configuration file:
{
  "Jwt": {
    "Key": "<your-secret-key-minimum-32-characters>",
    "Issuer": "https://sateliteappapi.azurewebsites.net",
    "Audience": "https://sateliteappapi.azurewebsites.net"
  }
}
The JWT Key must be at least 32 characters long for HS256 algorithm. Store this securely in Azure Key Vault for production.

Authentication Flow

  1. Token in Header: Checks Authorization header for Bearer <token>
  2. Token in Cookie: Falls back to satelite_session cookie if header is not present
  3. Validation: Validates issuer, audience, lifetime, and signing key

CORS Configuration

Cross-Origin Resource Sharing (CORS) is configured to allow requests from any origin.
Program.cs:355-362
builder.Services.AddCors(options => options.AddPolicy("AllowAllHeaders",
            builder =>
            {
                builder.AllowAnyOrigin()
            
                       .AllowAnyHeader()
                       .AllowAnyMethod();
            }));
For production environments, consider restricting CORS to specific origins:
builder.WithOrigins(
    "https://sateliteapp.modernaalimentos.com.ec",
    "https://sateliteapp-test.azurewebsites.net"
).AllowCredentials();
The CORS policy is applied in the middleware pipeline:
Program.cs:747
app.UseCors("AllowAllHeaders");

External API Configuration

Satélite API integrates with multiple external services.

Cofase API Settings

Program.cs:306
builder.Services.Configure<ApiCofaseSettings>(builder.Configuration.GetSection("ApiCofase"));
Configuration structure:
ApiCofaseSettings.cs
public class ApiCofaseSettings
{
    public string Server { get; set; }
    public string RootContextCompany { get; set; }
    public string RootContextProduct { get; set; }
    public string RootContextAuth { get; set; }
    public string Username { get; set; }
    public string Password { get; set; }
    public string Apikey { get; set; }
    public string PolicyNumber { get; set; }
}
Add to configuration:
{
  "ApiCofase": {
    "Server": "https://api.cofase.com",
    "RootContextCompany": "/company",
    "RootContextProduct": "/product",
    "RootContextAuth": "/auth",
    "Username": "<username>",
    "Password": "<password>",
    "Apikey": "<api-key>",
    "PolicyNumber": "<policy-number>"
  }
}

Equifax API Settings

Program.cs:307
builder.Services.Configure<ApiEquifaxSettings>(builder.Configuration.GetSection("ApiEquifax"));
Configuration structure:
ApiEquifaxSettings.cs
public class ApiEquifaxSettings
{
    public string Url { get; set; }
    public string Username { get; set; }
    public string Password { get; set; }
}
Add to configuration:
{
  "ApiEquifax": {
    "Url": "https://api.equifax.com",
    "Username": "<username>",
    "Password": "<password>"
  }
}

Databricks Configuration

DatabricksConfig.cs
public class DatabricksConfig
{
    public string? BaseUrl { get; set; }
    public string ClusterId { get; set; }
    public string AccessToken { get; set; }
    public string WarehouseId { get; set; }
}
Add to configuration:
{
  "DatabricksConfig": {
    "BaseUrl": "https://<workspace>.azuredatabricks.net",
    "ClusterId": "<cluster-id>",
    "AccessToken": "<access-token>",
    "WarehouseId": "<warehouse-id>"
  }
}
Store sensitive API credentials in Azure Key Vault and reference them in configuration:
{
  "ApiCofase": {
    "Password": "@Microsoft.KeyVault(SecretUri=https://<vault>.vault.azure.net/secrets/cofase-password/)"
  }
}

GraphQL Configuration

GraphQL server is configured with extended execution timeout:
Program.cs:515-518
.SetRequestOptions(_ => new HotChocolate.Execution.Options.RequestExecutorOptions
{
    ExecutionTimeout = TimeSpan.FromMinutes(10)
});
The 10-minute timeout accommodates long-running queries and complex data operations.

Scheduled Jobs Configuration

Satélite API uses Quartz.NET for scheduled background jobs:
// Program.cs:208-212
q.AddJob<TaskAnticipo>(opts => opts.WithIdentity(anticipoKey));
q.AddTrigger(opts => opts
    .ForJob(anticipoKey)
    .WithIdentity("AnticipoJob-trigger")
    .WithCronSchedule("0 0 9 * * ?")); // Daily at 9:00 AM

Environment-Specific Configuration

Configuration values can vary by environment using appsettings.{Environment}.json files:
  • appsettings.json - Base configuration
  • appsettings.Production.json - Production overrides
  • appsettings.Quality.json - Testing environment overrides
The active environment is determined by the ASPNETCORE_ENVIRONMENT variable.

Configuration Best Practices

Use Azure Key Vault

Store all secrets and connection strings in Azure Key Vault, not in configuration files

Connection Pooling

Always use pooled database contexts for better performance under load

Enable Retry Logic

Configure retry policies for critical database contexts to handle transient failures

Separate Configurations

Use environment-specific configuration files to avoid accidental production changes

Next Steps

Azure Setup

Learn how to deploy to Azure Web Services

Environments

Understand production vs testing environments

Build docs developers (and LLMs) love