-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Encapsulate fetching ApiKey into EnvironmentVariablesLoader class
- Loading branch information
Showing
8 changed files
with
52 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Microsoft.Extensions.Configuration.EnvironmentVariables; | ||
|
||
namespace ProjectX.Core | ||
{ | ||
public class EnvironmentVariableLoader | ||
{ | ||
private readonly EnvironmentVariablesConfigurationProvider _provider; | ||
public EnvironmentVariableLoader() | ||
{ | ||
_provider = new EnvironmentVariablesConfigurationProvider(); | ||
_provider.Load(); | ||
} | ||
public string FromEnvironmentVariable(string envVariable) | ||
{ | ||
string? value = null; | ||
if (!_provider.TryGet(envVariable, out value) || string.IsNullOrEmpty(value)) | ||
{ | ||
throw new Exception($"Blow up: cannot get compulsory market data api key from environment variable '${envVariable}'"); | ||
} | ||
|
||
return value; | ||
} | ||
} | ||
|
||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
using Microsoft.Extensions.Configuration.EnvironmentVariables; | ||
|
||
namespace ProjectX.MarketData; | ||
|
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 |
---|---|---|
@@ -1,20 +1,5 @@ | ||
namespace ProjectX.MarketData; | ||
|
||
public class FMPStockMarketSourceOptions | ||
{ | ||
public string ApiKey { get; set; } | ||
|
||
public static string GetFromEnvironment() | ||
{ | ||
var provider = new Microsoft.Extensions.Configuration.EnvironmentVariables.EnvironmentVariablesConfigurationProvider(); | ||
provider.Load(); | ||
|
||
string? apiKey = null; | ||
if (!provider.TryGet("fmpapikey", out apiKey)) | ||
{ | ||
throw new Exception($"Blow up: cannot get compulsory market data api key from environment variable 'fmpapikey'"); | ||
} | ||
|
||
return apiKey; | ||
} | ||
} |