Last active
November 29, 2019 07:05
-
-
Save skarllot/11e94ed8901a9ddabdf05c0e5c08dbc5 to your computer and use it in GitHub Desktop.
Amazon Elastic Beanstalk variables configuration provider implementation for Microsoft.Extensions.Configuration.
This file contains hidden or 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
using Microsoft.Extensions.Configuration; | |
using Newtonsoft.Json.Linq; | |
using System.IO; | |
using System.Linq; | |
namespace SklLib.Configuration.Amazon | |
{ | |
public class AmazonEBConfigurationProvider : ConfigurationProvider | |
{ | |
private const string ConfigurationFilename = @"C:\Program Files\Amazon\ElasticBeanstalk\config\containerconfiguration"; | |
public override void Load() | |
{ | |
if (!File.Exists(ConfigurationFilename)) | |
return; | |
string configJson; | |
try | |
{ | |
configJson = File.ReadAllText(ConfigurationFilename); | |
} | |
catch | |
{ | |
return; | |
} | |
var config = JObject.Parse(configJson); | |
var env = (JArray)config["iis"]["env"]; | |
if (env.Count == 0) | |
return; | |
foreach (var item in env.Select(i => (string)i)) | |
{ | |
int eqIndex = item.IndexOf('='); | |
Data[item.Substring(0, eqIndex)] = item.Substring(eqIndex + 1); | |
} | |
} | |
} | |
} |
This file contains hidden or 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
using Microsoft.Extensions.Configuration; | |
namespace SklLib.Configuration.Amazon | |
{ | |
public class AmazonEBConfigurationSource : IConfigurationSource | |
{ | |
public IConfigurationProvider Build(IConfigurationBuilder builder) | |
{ | |
return new AmazonEBConfigurationProvider(); | |
} | |
} | |
} |
This file contains hidden or 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
using Microsoft.Extensions.Configuration; | |
namespace SklLib.Configuration.Amazon | |
{ | |
public static class AmazonEBExtensions | |
{ | |
public static IConfigurationBuilder AddAmazonElasticBeanstalk(this IConfigurationBuilder configurationBuilder) | |
{ | |
configurationBuilder.Add(new AmazonEBConfigurationSource()); | |
return configurationBuilder; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment