Skip to content

Commit

Permalink
Merge pull request #27 from eduardo-paes:development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
eduardo-paes authored Oct 24, 2023
2 parents c12f693 + eb8cde4 commit 1911727
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 142 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/azure-functions-app-dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Deploy WebFunctions to Azure

on:
push:
branches: ["main"]

env:
AZURE_FUNCTIONAPP_NAME: "GPIC-Stg-WebFunctions" # set this to your function app name on Azure
AZURE_FUNCTIONAPP_PACKAGE_PATH: "src" # set this to the path to your function app project, defaults to the repository root
DOTNET_VERSION: "7.0" # set this to the dotnet version to use (e.g. '2.1.x', '3.1.x', '5.0.x')

jobs:
build-and-deploy:
runs-on: ubuntu-latest # For Linux, use ubuntu-latest
environment: dev
steps:
- name: "Checkout GitHub Action"
uses: actions/checkout@v3

- name: Setup DotNet ${{ env.DOTNET_VERSION }} Environment
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: "Resolve Project Dependencies Using Dotnet"
shell: bash # For Linux, use bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
dotnet build --configuration Release --output ./output
popd
- name: Create env
run: |
echo "AZURE_BLOB_STORAGE_CONNECTION_STRING=${{ secrets.AZURE_BLOB_STORAGE_CONNECTION_STRING }}
AZURE_BLOB_STORAGE_CONTAINER_NAME=${{ secrets.AZURE_BLOB_STORAGE_CONTAINER_NAME }}
POSTGRES_CONNECTION_STRING=${{ secrets.POSTGRES_CONNECTION_STRING }}
FRONTEND_URL=${{ secrets.FRONTEND_URL }}
ALLOW_ORIGINS=${{ secrets.ALLOW_ORIGINS }}
JWT_AUDIENCE=${{ secrets.JWT_AUDIENCE }}
JWT_EXPIRE_IN=${{ secrets.JWT_EXPIRE_IN }}
JWT_ISSUER=${{ secrets.JWT_ISSUER }}
JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}
SEQ_API_KEY=${{ secrets.SEQ_API_KEY }}
SEQ_URL=${{ secrets.SEQ_URL }}
SMTP_EMAIL_PASSWORD=${{ secrets.SMTP_EMAIL_PASSWORD }}
SMTP_EMAIL_USERNAME=${{ secrets.SMTP_EMAIL_USERNAME }}
EXECUTE_MIGRATION=${{ secrets.EXECUTE_MIGRATION }}" > src/Infrastructure/WebAPI/.env
- name: "Run Azure Functions Action"
uses: Azure/functions-action@v1
id: fa
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: "${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output"
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }} # Remove publish-profile to use Azure RBAC
52 changes: 0 additions & 52 deletions .github/workflows/azure-functions-app-dotnet.yml.stop

This file was deleted.

2 changes: 2 additions & 0 deletions .github/workflows/azure-webapps-dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
echo "AZURE_BLOB_STORAGE_CONNECTION_STRING=${{ secrets.AZURE_BLOB_STORAGE_CONNECTION_STRING }}
AZURE_BLOB_STORAGE_CONTAINER_NAME=${{ secrets.AZURE_BLOB_STORAGE_CONTAINER_NAME }}
POSTGRES_CONNECTION_STRING=${{ secrets.POSTGRES_CONNECTION_STRING }}
FRONTEND_URL=${{ secrets.FRONTEND_URL }}
ALLOW_ORIGINS=${{ secrets.ALLOW_ORIGINS }}
JWT_AUDIENCE=${{ secrets.JWT_AUDIENCE }}
JWT_EXPIRE_IN=${{ secrets.JWT_EXPIRE_IN }}
JWT_ISSUER=${{ secrets.JWT_ISSUER }}
Expand Down
28 changes: 2 additions & 26 deletions src/Infrastructure/IoC/InfrastructureDI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ namespace Infrastructure.IoC
{
public static class InfrastructureDI
{
public static IServiceCollection AddInfrastructure(this IServiceCollection services, HostBuilderContext? hostContext = null)
public static IServiceCollection AddInfrastructure(this IServiceCollection services, ref IConfiguration? configuration, HostBuilderContext? hostContext = null)
{
#region AppSettings e DotEnv
// Define valores das propriedades de configuração
IConfiguration configuration = SettingsConfiguration.GetConfiguration(hostContext);
configuration = SettingsConfiguration.GetConfiguration(hostContext);
services.AddSingleton(configuration);

// Carrega informações de ambiente (.env)
Expand All @@ -35,30 +35,6 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi
});
#endregion Serviço de Log

#region CORS
// TODO: Definir política de CORS
services.AddCors(options =>
{
options.AddDefaultPolicy(
policy =>
{
policy.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
#endregion CORS

#region Rate Limit
services.AddMemoryCache();
services.AddInMemoryRateLimiting();
services.Configure<ClientRateLimitOptions>(configuration.GetSection("IpRateLimiting"));
services.AddSingleton<IClientPolicyStore, MemoryCacheClientPolicyStore>();
services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>();
services.AddSingleton<IProcessingStrategy, AsyncKeyLockProcessingStrategy>();
services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
#endregion Rate Limit

return services;
}
}
Expand Down
72 changes: 12 additions & 60 deletions src/Infrastructure/IoC/Utils/DotEnvSecrets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,66 +13,18 @@ public DotEnvSecrets()
_ = DotNetEnv.Env.Load(Path.Combine(basePath!, ".env"));
}

public string GetFrontEndUrl()
{
return DotNetEnv.Env.GetString("FRONTEND_URL");
}

public string GetSeqUrl()
{
return DotNetEnv.Env.GetString("SEQ_URL");
}

public string GetSeqApiKey()
{
return DotNetEnv.Env.GetString("SEQ_API_KEY");
}

public string GetBlobStorageConnectionString()
{
return DotNetEnv.Env.GetString("AZURE_BLOB_STORAGE_CONNECTION_STRING");
}

public string GetBlobStorageContainerName()
{
return DotNetEnv.Env.GetString("AZURE_BLOB_STORAGE_CONTAINER_NAME");
}

public string GetDatabaseConnectionString()
{
return DotNetEnv.Env.GetString("POSTGRES_CONNECTION_STRING");
}

public string GetSmtpUserName()
{
return DotNetEnv.Env.GetString("SMTP_EMAIL_USERNAME");
}

public string GetSmtpUserPassword()
{
return DotNetEnv.Env.GetString("SMTP_EMAIL_PASSWORD");
}

public string GetJwtSecret()
{
return DotNetEnv.Env.GetString("JWT_SECRET_KEY");
}

public string GetJwtIssuer()
{
return DotNetEnv.Env.GetString("JWT_ISSUER");
}

public string GetJwtAudience()
{
return DotNetEnv.Env.GetString("JWT_AUDIENCE");
}

public string GetJwtExpirationTime()
{
return DotNetEnv.Env.GetString("JWT_EXPIRE_IN");
}

public string GetFrontEndUrl() => DotNetEnv.Env.GetString("FRONTEND_URL");
public string GetSeqUrl() => DotNetEnv.Env.GetString("SEQ_URL");
public string GetSeqApiKey() => DotNetEnv.Env.GetString("SEQ_API_KEY");
public string GetBlobStorageConnectionString() => DotNetEnv.Env.GetString("AZURE_BLOB_STORAGE_CONNECTION_STRING");
public string GetBlobStorageContainerName() => DotNetEnv.Env.GetString("AZURE_BLOB_STORAGE_CONTAINER_NAME");
public string GetDatabaseConnectionString() => DotNetEnv.Env.GetString("POSTGRES_CONNECTION_STRING");
public string GetSmtpUserName() => DotNetEnv.Env.GetString("SMTP_EMAIL_USERNAME");
public string GetSmtpUserPassword() => DotNetEnv.Env.GetString("SMTP_EMAIL_PASSWORD");
public string GetJwtSecret() => DotNetEnv.Env.GetString("JWT_SECRET_KEY");
public string GetJwtIssuer() => DotNetEnv.Env.GetString("JWT_ISSUER");
public string GetJwtAudience() => DotNetEnv.Env.GetString("JWT_AUDIENCE");
public string GetJwtExpirationTime() => DotNetEnv.Env.GetString("JWT_EXPIRE_IN");
public bool ExecuteMigration()
{
try
Expand Down
33 changes: 31 additions & 2 deletions src/Infrastructure/WebAPI/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace WebAPI
/// </summary>
public class Startup
{
private const string CORS_POLICY_NAME = "_allowSpecificOrigins";
private IConfiguration? _configuration;

/// <summary>
/// Realiza a configuração dos serviços de injeção de dependência.
/// </summary>
Expand All @@ -19,7 +22,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddControllers();

// Realiza comunicação com os demais Projetos.
services.AddInfrastructure();
services.AddInfrastructure(ref _configuration);
services.AddPersistence();
services.AddExternalServices();
services.AddApplication();
Expand All @@ -32,6 +35,32 @@ public void ConfigureServices(IServiceCollection services)

// Permite que rotas sejam acessíveis em lowercase
services.AddRouting(options => options.LowercaseUrls = true);

#region CORS
// Definição de política de CORS
services.AddCors(options =>
{
options.AddPolicy(name: CORS_POLICY_NAME,
policy =>
{
// Busca os valores de ALLOW_ORIGINS do arquivo .env
policy.WithOrigins(
origins: Environment.GetEnvironmentVariable("ALLOW_ORIGINS").Split(',')!)

Check warning on line 48 in src/Infrastructure/WebAPI/Startup.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 48 in src/Infrastructure/WebAPI/Startup.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 48 in src/Infrastructure/WebAPI/Startup.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
.AllowAnyHeader()
.AllowAnyMethod();
});
});
#endregion CORS

#region Rate Limit
services.AddMemoryCache();
services.AddInMemoryRateLimiting();
services.Configure<ClientRateLimitOptions>(_configuration.GetSection("IpRateLimiting"));

Check warning on line 58 in src/Infrastructure/WebAPI/Startup.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 58 in src/Infrastructure/WebAPI/Startup.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 58 in src/Infrastructure/WebAPI/Startup.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
services.AddSingleton<IClientPolicyStore, MemoryCacheClientPolicyStore>();
services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>();
services.AddSingleton<IProcessingStrategy, AsyncKeyLockProcessingStrategy>();
services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
#endregion Rate Limit
}

/// <summary>
Expand Down Expand Up @@ -66,7 +95,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseHttpsRedirection();

// Enable CORS
app.UseCors();
app.UseCors(CORS_POLICY_NAME);

// Enable routing for incoming requests
app.UseRouting();
Expand Down
1 change: 0 additions & 1 deletion src/Infrastructure/WebAPI/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"SiteUrl": "https://localhost:5001",
"Serilog": {
"Using": ["Serilog.Sinks.Console", "Serilog.Sinks.File"],
"MinimumLevel": {
Expand Down
4 changes: 3 additions & 1 deletion src/Infrastructure/WebFunctions/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Microsoft.Extensions.Hosting;
using Infrastructure.IoC;
using Microsoft.Extensions.Configuration;

var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices((hostContext, services) =>
{
services.AddInfrastructure(hostContext);
IConfiguration? configuration = null;
services.AddInfrastructure(ref configuration, hostContext);
services.AddPersistence();
services.AddExternalServices();
services.AddApplication();
Expand Down

0 comments on commit 1911727

Please sign in to comment.