Skip to content

Commit

Permalink
Add ability to toggle SSI (#1163)
Browse files Browse the repository at this point in the history
* Added config AppSettings.SSIEnabledEnvironments

* Update Yoma API Config

---------

Co-authored-by: adrianwium <[email protected]>
  • Loading branch information
rblaine95 and adrianwium authored Dec 4, 2024
1 parent 93860f9 commit 5e8ed88
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions helm/yoma-api/conf/base/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ appSettings:
SendGridEnabledEnvironments: ENC[AES256_GCM,data:m6ptYdvShuuk0WCZHBTXpMXxSQ==,iv:OGmHmlQsk9MfJIfuPb4bB9qkFZeEqS41NeAdcg4CTBY=,tag:1h09nDXkB5Yqr6O1fvJy3Q==,type:str]
SentryEnabledEnvironments: ENC[AES256_GCM,data:jdo8lzYAb5Azo45q/IcEj1qqOFOAD1f/kl/oEkT1D/4=,iv:FfSPImDFqOsHf+i6SLNfNquRefenKZqzKNmgtHppZMo=,tag:MJFs3rB+xI8wsQ4ezT5I7Q==,type:str]
ShortLinkProviderAsSourceEnabledEnvironments: ENC[AES256_GCM,data:QuUZy5IfTOCOqsV6vEwgHA5uRKrJU8ToXFdRtqDPBC0=,iv:HPQ3D6kO2mhSIyKlbmSlF3na5UKStH/glxX9HHRfNuE=,tag:NuX/i74VXl75m5g7ptCTaw==,type:str]
SSIEnabledEnvironments: ENC[AES256_GCM,data:7yqVIXux2vVOm7g9H0MwKiGQlrJwAE9Ir15td+/a6WzACep0gJcL,iv:kRU9kh1ARhxbGnaoDmM2YJipBRjOquiLcwr/zr0ePLI=,tag:Hnse9OryCdwUMSvj1G0C7A==,type:str]
SSIMaximumRetryAttempts: ENC[AES256_GCM,data:qnA=,iv:zLoG3pp8JLu2Tue1Gz8B988RGI8OgvfTn+NTjtEzbSY=,tag:LHD49BW8+/qDZJN1/sFCMg==,type:int]
SSISchemaFullNameYoID: ENC[AES256_GCM,data:kZ1P/MCXT6BBxgBw,iv:EcudBBc2G/o+1RzoKOLV/cU1eaZHGx7Hp9Lbz6n/psI=,tag:ZiOQJhFC8nmTMoCaDawBMA==,type:str]
SwaggerScopesAuthorizationCode: ENC[AES256_GCM,data:0MKc5on8UGd7LaH27z5HmFvqaWyy+/G7VxVQMmcaqZA9I434YexoLIeVRUU=,iv:tHldbbPJnqQkiTLwJbAsOiKFhU6FYyIypzvbjuBQavM=,tag:es6pRdyOvMR6GBPfDjjmOQ==,type:str]
Expand Down Expand Up @@ -248,8 +249,8 @@ sops:
azure_kv: []
hc_vault: []
age: []
lastmodified: "2024-11-12T08:07:59Z"
mac: ENC[AES256_GCM,data:p7JPGA8qJKSWypxRaglWU90DvsR0dKqebPif7H77e9E+HybiEb8EISariyrGqxSApHMc5rVEhdzZSe8xR3XkUYKgW4HNJ3VzBDp/dn1PJYWBjzrzQuPKDRpITYdPNkyVVmksQSzr0XUlM4lN50QbQu682rBc1gVbAFtnfuDPxOo=,iv:dynzSqMjWZErF74asAQeucBeRwCzp5+hnC/m1lbwy9w=,tag:0nIi7JHNKkvXT+t6YgsdWA==,type:str]
lastmodified: "2024-12-02T07:42:53Z"
mac: ENC[AES256_GCM,data:riHNXfWZAhnISOL/9saSgATM5KsFm0Q1v8nbrBQ7y09Oj1kelQHYpHPLedChW/L8XRIT1e6lHtNiJDsDc+zVzply6SJzZ291a+RQXAp6ZbQ8Xv82kQkE/e1ajNmkkhuj+GEXexU4ii8FJrOytxa8+fhrfQzAZaVPiOd84YxGWxU=,iv:2ZlflEbkLSM+bPDsdlL2R5U30Id7klJFvvQXclPJfXs=,tag:i0rA/fIgxJTi31vjNtV9cQ==,type:str]
pgp: []
unencrypted_suffix: _unencrypted
version: 3.9.1
1 change: 1 addition & 0 deletions src/api/src/application/Yoma.Core.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"HttpsRedirectionEnabledEnvironments": null,
"LaborMarketProviderAsSourceEnabledEnvironments": "Production",
"ShortLinkProviderAsSourceEnabledEnvironments": "Development, Staging, Production",
"SSIEnabledEnvironments": "Local, Development, Staging, Production",
"PartnerSharingEnabledEnvironments": null,
"PartnerSharingMaximumRetryAttempts": 5,
"MarketplaceItemReservationExpirationInMinutes": 30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public CacheItemType CacheEnabledByCacheItemTypesAsEnum

public Environment PartnerSharingEnabledEnvironmentsAsEnum => ParseEnvironmentInput(PartnerSharingEnabledEnvironments);

public string SSIEnabledEnvironments { get; set; }

public Environment SSIEnabledEnvironmentsAsEnum => ParseEnvironmentInput(SSIEnabledEnvironments);

/// <summary>
/// -1: Represents infinite retries. Never transitions to an error state.
/// 0: Represents no retries. Immediately transitions to an error state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class SSIBackgroundService : ISSIBackgroundService
#region Class Variables
private readonly ILogger<SSIBackgroundService> _logger;
private readonly AppSettings _appSettings;
private readonly IEnvironmentProvider _environmentProvider;
private readonly ScheduleJobOptions _scheduleJobOptions;
private readonly IUserService _userService;
private readonly IOrganizationService _organizationService;
Expand All @@ -40,6 +41,7 @@ public class SSIBackgroundService : ISSIBackgroundService
#region Constructor
public SSIBackgroundService(ILogger<SSIBackgroundService> logger,
IOptions<AppSettings> appSettings,
IEnvironmentProvider environmentProvider,
IOptions<ScheduleJobOptions> scheduleJobOptions,
IUserService userService,
IOrganizationService organizationService,
Expand All @@ -53,6 +55,7 @@ public SSIBackgroundService(ILogger<SSIBackgroundService> logger,
{
_logger = logger;
_appSettings = appSettings.Value;
_environmentProvider = environmentProvider;
_scheduleJobOptions = scheduleJobOptions.Value;
_userService = userService;
_organizationService = organizationService;
Expand All @@ -75,6 +78,12 @@ public async Task SeedSchemas()
const string lockIdentifier = "ssi_seed_schemas";
var lockDuration = TimeSpan.FromHours(_scheduleJobOptions.DefaultScheduleMaxIntervalInHours) + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes);

if (!_appSettings.SSIEnabledEnvironmentsAsEnum.HasFlag(_environmentProvider.Environment))
{
_logger.LogInformation("{Process} skipped for environment '{environment}' at {dateStamp} as SSI is not enabled.", nameof(SeedSchemas), _environmentProvider.Environment, DateTimeOffset.UtcNow);
return;
}

if (!await _distributedLockService.TryAcquireLockAsync(lockIdentifier, lockDuration))
{
_logger.LogInformation("{Process} is already running. Skipping execution attempt at {dateStamp}", nameof(SeedSchemas), DateTimeOffset.UtcNow);
Expand Down Expand Up @@ -122,6 +131,12 @@ public async Task ProcessTenantCreation()
var executeUntil = dateTimeNow.AddHours(_scheduleJobOptions.SSITenantCreationScheduleMaxIntervalInHours);
var lockDuration = executeUntil - dateTimeNow + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes);

if (!_appSettings.SSIEnabledEnvironmentsAsEnum.HasFlag(_environmentProvider.Environment))
{
_logger.LogInformation("{Process} skipped for environment '{environment}' at {dateStamp} as SSI is not enabled.", nameof(ProcessTenantCreation), _environmentProvider.Environment, DateTimeOffset.UtcNow);
return;
}

if (!await _distributedLockService.TryAcquireLockAsync(lockIdentifier, lockDuration))
{
_logger.LogInformation("{Process} is already running. Skipping execution attempt at {dateStamp}", nameof(ProcessTenantCreation), DateTimeOffset.UtcNow);
Expand Down Expand Up @@ -234,6 +249,12 @@ public async Task ProcessCredentialIssuance()
var executeUntil = dateTimeNow.AddHours(_scheduleJobOptions.SSICredentialIssuanceScheduleMaxIntervalInHours);
var lockDuration = executeUntil - dateTimeNow + TimeSpan.FromMinutes(_scheduleJobOptions.DistributedLockDurationBufferInMinutes);

if (!_appSettings.SSIEnabledEnvironmentsAsEnum.HasFlag(_environmentProvider.Environment))
{
_logger.LogInformation("{Process} skipped for environment '{environment}' at {dateStamp} as SSI is not enabled.", nameof(ProcessCredentialIssuance), _environmentProvider.Environment, DateTimeOffset.UtcNow);
return;
}

if (!await _distributedLockService.TryAcquireLockAsync(lockIdentifier, lockDuration))
{
_logger.LogInformation("{Process} is already running. Skipping execution attempt at {dateStamp}", nameof(ProcessCredentialIssuance), DateTimeOffset.UtcNow);
Expand Down

0 comments on commit 5e8ed88

Please sign in to comment.