From 7ddda569872d02422294bb6968bb9e672bc90aeb Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Wed, 15 Jan 2025 15:16:36 -0700 Subject: [PATCH] Moved GetEnvironmentVariable calls to Application_Start --- Fab2ApprovalSystem/Controllers/AccountController.cs | 7 ++----- Fab2ApprovalSystem/Controllers/ChangeControlController.cs | 8 ++------ Fab2ApprovalSystem/Controllers/MRBController.cs | 8 ++------ Fab2ApprovalSystem/Controllers/PCRBController.cs | 4 +--- Fab2ApprovalSystem/Models/AppSettings.cs | 6 ++++++ 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/Fab2ApprovalSystem/Controllers/AccountController.cs b/Fab2ApprovalSystem/Controllers/AccountController.cs index 2f56686..ed95e29 100644 --- a/Fab2ApprovalSystem/Controllers/AccountController.cs +++ b/Fab2ApprovalSystem/Controllers/AccountController.cs @@ -24,12 +24,9 @@ namespace Fab2ApprovalSystem.Controllers; [Authorize] public class AccountController : Controller { - private string _apiBaseUrl; public AccountController() : this(new UserManager(new UserStore(new ApplicationDbContext()))) { - _apiBaseUrl = Environment.GetEnvironmentVariable("FabApprovalApiBaseUrl") ?? - throw new ArgumentNullException("FabApprovalApiBaseUrl environment variable not found"); } public AccountController(UserManager userManager) { @@ -69,7 +66,7 @@ public class AccountController : Controller { bool isLoginValid; HttpClient httpClient = HttpClientFactory.Create(); - httpClient.BaseAddress = new Uri(_apiBaseUrl); + httpClient.BaseAddress = new Uri(GlobalVars.AppSettings.ApiBaseUrl); LoginResult loginResult = await AccountDMO.LoginAsync(httpClient, model); @@ -121,7 +118,7 @@ public class AccountController : Controller { bool isLoginValid; HttpClient httpClient = HttpClientFactory.Create(); - httpClient.BaseAddress = new Uri(_apiBaseUrl); + httpClient.BaseAddress = new Uri(GlobalVars.AppSettings.ApiBaseUrl); LoginResult loginResult = await AccountDMO.ExternalAuthSetupAsync(httpClient, authAttempt); diff --git a/Fab2ApprovalSystem/Controllers/ChangeControlController.cs b/Fab2ApprovalSystem/Controllers/ChangeControlController.cs index 6464fe3..ddd8aea 100644 --- a/Fab2ApprovalSystem/Controllers/ChangeControlController.cs +++ b/Fab2ApprovalSystem/Controllers/ChangeControlController.cs @@ -52,9 +52,7 @@ public class ChangeControlController : Controller { string encodedJwt = System.Net.WebUtility.UrlEncode(jwt); string refreshToken = Session["RefreshToken"].ToString(); string encodedRefreshToken = System.Net.WebUtility.UrlEncode(refreshToken); - string wasmClientUrl = Environment.GetEnvironmentVariable("FabApprovalWasmClientUrl") ?? - "https://localhost:7255"; - string mrbUrl = $"{wasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=/pcrb/{issueID}"; + string mrbUrl = $"{GlobalVars.AppSettings.WasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=/pcrb/{issueID}"; return Redirect(mrbUrl); } @@ -64,9 +62,7 @@ public class ChangeControlController : Controller { string encodedJwt = System.Net.WebUtility.UrlEncode(jwt); string refreshToken = Session["RefreshToken"].ToString(); string encodedRefreshToken = System.Net.WebUtility.UrlEncode(refreshToken); - string wasmClientUrl = Environment.GetEnvironmentVariable("FabApprovalWasmClientUrl") ?? - "https://localhost:7255"; - string mrbUrl = $"{wasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=/pcrb/{issueID}"; + string mrbUrl = $"{GlobalVars.AppSettings.WasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=/pcrb/{issueID}"; return Redirect(mrbUrl); } diff --git a/Fab2ApprovalSystem/Controllers/MRBController.cs b/Fab2ApprovalSystem/Controllers/MRBController.cs index c90d591..4c28292 100644 --- a/Fab2ApprovalSystem/Controllers/MRBController.cs +++ b/Fab2ApprovalSystem/Controllers/MRBController.cs @@ -79,9 +79,7 @@ public class MRBController : Controller { string encodedJwt = System.Net.WebUtility.UrlEncode(jwt); string refreshToken = Session["RefreshToken"].ToString(); string encodedRefreshToken = System.Net.WebUtility.UrlEncode(refreshToken); - string wasmClientUrl = Environment.GetEnvironmentVariable("FabApprovalWasmClientUrl") ?? - "https://localhost:7255"; - string mrbUrl = $"{wasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=/mrb/{issueID}"; + string mrbUrl = $"{GlobalVars.AppSettings.WasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=/mrb/{issueID}"; return Redirect(mrbUrl); } @@ -104,9 +102,7 @@ public class MRBController : Controller { string encodedJwt = System.Net.WebUtility.UrlEncode(jwt); string refreshToken = Session["RefreshToken"].ToString(); string encodedRefreshToken = System.Net.WebUtility.UrlEncode(refreshToken); - string wasmClientUrl = Environment.GetEnvironmentVariable("FabApprovalWasmClientUrl") ?? - "https://localhost:7255"; - string mrbUrl = $"{wasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=/mrb/{issueID}"; + string mrbUrl = $"{GlobalVars.AppSettings.WasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=/mrb/{issueID}"; return Redirect(mrbUrl); } diff --git a/Fab2ApprovalSystem/Controllers/PCRBController.cs b/Fab2ApprovalSystem/Controllers/PCRBController.cs index b72e10a..03ee413 100644 --- a/Fab2ApprovalSystem/Controllers/PCRBController.cs +++ b/Fab2ApprovalSystem/Controllers/PCRBController.cs @@ -13,9 +13,7 @@ public class PCRBController : Controller { string encodedJwt = System.Net.WebUtility.UrlEncode(jwt); string refreshToken = Session["RefreshToken"].ToString(); string encodedRefreshToken = System.Net.WebUtility.UrlEncode(refreshToken); - string wasmClientUrl = Environment.GetEnvironmentVariable("FabApprovalWasmClientUrl") ?? - "https://localhost:7255"; - string mrbUrl = $"{wasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=/pcrb/{issueID}"; + string mrbUrl = $"{GlobalVars.AppSettings.WasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=/pcrb/{issueID}"; return Redirect(mrbUrl); } diff --git a/Fab2ApprovalSystem/Models/AppSettings.cs b/Fab2ApprovalSystem/Models/AppSettings.cs index a3a4037..d34d2b4 100644 --- a/Fab2ApprovalSystem/Models/AppSettings.cs +++ b/Fab2ApprovalSystem/Models/AppSettings.cs @@ -46,6 +46,7 @@ public class AppSettings { string urls, int userId, bool userIsAdmin, + string wasmClientUrl, string wsr_URL, string? workingDirectoryName) { AdminNotificationRecepient = adminNotificationRecepient; @@ -88,6 +89,7 @@ public class AppSettings { UserId = userId; UserIsAdmin = userIsAdmin; WSR_URL = wsr_URL; + WasmClientUrl = wasmClientUrl; WorkingDirectoryName = workingDirectoryName; } @@ -130,6 +132,7 @@ public class AppSettings { public string URLs { get; } public int UserId { get; } public bool UserIsAdmin { get; } + public string WasmClientUrl { get; } public string WSR_URL { get; } public string? WorkingDirectoryName { get; } @@ -217,6 +220,8 @@ public class AppSettings { string? smtpServer = ConfigurationManager.AppSettings["SMTP Server"]?.ToString(); string? urls = ConfigurationManager.AppSettings["URLs"]?.ToString(); string? workingDirectoryName = ConfigurationManager.AppSettings["WorkingDirectoryName"]?.ToString(); + string wasmClientUrl = Environment.GetEnvironmentVariable("FabApprovalWasmClientUrl") ?? + "https://localhost:7255"; result = new(adminNotificationRecepient: adminNotificationRecepient, apiBaseUrl: apiBaseUrl, attachmentFolder: attachmentFolder, @@ -256,6 +261,7 @@ public class AppSettings { urls: urls, userId: userId, userIsAdmin: Misc.GlobalVars.USER_ISADMIN, + wasmClientUrl: wasmClientUrl, wsr_URL: Misc.GlobalVars.WSR_URL, workingDirectoryName: workingDirectoryName); return result;