-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2acd980
commit b59d4bb
Showing
6 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...ance/Maintenance/ResetStripeApiCredentials/ResetStripeApiCredentialsMaintenanceOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.ResetStripeApiCredentials; | ||
|
||
public class ResetStripeApiCredentialsMaintenanceOptions | ||
{ | ||
public bool IsEnabled { get; set; } | ||
} |
65 changes: 65 additions & 0 deletions
65
...nce/Maintenance/ResetStripeApiCredentials/ResetStripeApiCredentialsMaintenanceProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Lombiq.Hosting.Tenants.Maintenance.Extensions; | ||
using Lombiq.Hosting.Tenants.Maintenance.Models; | ||
using Lombiq.Hosting.Tenants.Maintenance.Services; | ||
using Microsoft.AspNetCore.DataProtection; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.IdentityModel.Tokens; | ||
using OrchardCore.Commerce.Payment.Stripe.Models; | ||
using OrchardCore.Commerce.Payment.Stripe.Services; | ||
using OrchardCore.Entities; | ||
using OrchardCore.Environment.Shell; | ||
using OrchardCore.Settings; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.ResetStripeApiCredentials; | ||
|
||
public class ResetStripeApiCredentialsMaintenanceProvider : MaintenanceProviderBase | ||
{ | ||
private readonly IOptions<ResetStripeApiCredentialsMaintenanceOptions> _options; | ||
private readonly ISiteService _siteService; | ||
private readonly IDataProtectionProvider _dataProtectionProvider; | ||
private readonly IShellFeaturesManager _shellFeaturesManager; | ||
|
||
public ResetStripeApiCredentialsMaintenanceProvider( | ||
IOptions<ResetStripeApiCredentialsMaintenanceOptions> options, | ||
ISiteService siteService, | ||
IDataProtectionProvider dataProtectionProvider, | ||
IShellFeaturesManager shellFeaturesManager) | ||
{ | ||
_options = options; | ||
_siteService = siteService; | ||
_dataProtectionProvider = dataProtectionProvider; | ||
_shellFeaturesManager = shellFeaturesManager; | ||
} | ||
|
||
public override async Task<bool> ShouldExecuteAsync(MaintenanceTaskExecutionContext context) => | ||
_options.Value.IsEnabled && | ||
!context.WasLatestExecutionSuccessful() && | ||
(await _shellFeaturesManager.GetEnabledFeaturesAsync()).Any(feature => | ||
feature.Id == "OrchardCore.Commerce.Payment.Stripe"); | ||
|
||
public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) | ||
{ | ||
var siteSettings = await _siteService.GetSiteSettingsAsync(); | ||
var settings = siteSettings.As<StripeApiSettings>(); | ||
|
||
if (!settings.SecretKey.IsNullOrEmpty() || | ||
!settings.PublishableKey.IsNullOrEmpty() || | ||
!settings.WebhookSigningSecret.IsNullOrEmpty()) | ||
{ | ||
siteSettings.Alter<StripeApiSettings>(nameof(StripeApiSettings), settings => | ||
{ | ||
// These are publicly available test keys. | ||
settings.PublishableKey = | ||
"pk_test_51H59owJmQoVhz82aWAoi9M5s8PC6sSAqFI7KfAD2NRKun5riDIOM0dvu2caM25a5f5JbYLMc5Umxw8Dl7dBIDNwM00yVbSX8uS"; | ||
|
||
var protector = _dataProtectionProvider.CreateProtector(nameof(StripeApiSettingsConfiguration)); | ||
settings.SecretKey = protector | ||
.Protect("sk_test_51H59owJmQoVhz82aOUNOuCVbK0u1zjyRFKkFp9EfrqzWaUWqQni3oSxljsdTIu2YZ9XvlbeGjZRU7B7ye2EjJQE000Dm2DtMWD"); | ||
|
||
settings.WebhookSigningSecret = string.Empty; | ||
}); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Lombiq.Hosting.Tenants.Maintenance/Maintenance/ResetStripeApiCredentials/Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Lombiq.Hosting.Tenants.Maintenance.Constants; | ||
using Lombiq.Hosting.Tenants.Maintenance.Services; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using OrchardCore.Environment.Shell.Configuration; | ||
using OrchardCore.Modules; | ||
|
||
namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.ResetStripeApiCredentials; | ||
|
||
[Feature(FeatureNames.ResetStripeApiCredentials)] | ||
public class Startup : StartupBase | ||
{ | ||
private readonly IShellConfiguration _shellConfiguration; | ||
|
||
public Startup(IShellConfiguration shellConfiguration) => | ||
_shellConfiguration = shellConfiguration; | ||
|
||
public override void ConfigureServices(IServiceCollection services) | ||
{ | ||
var options = new ResetStripeApiCredentialsMaintenanceOptions(); | ||
var configSection = _shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:ResetStripeApiCredentials"); | ||
configSection.Bind(options); | ||
services.Configure<ResetStripeApiCredentialsMaintenanceOptions>(configSection); | ||
|
||
services.AddScoped<IMaintenanceProvider, ResetStripeApiCredentialsMaintenanceProvider>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters