From b749a0c2c1114265a310f239d8c5b5e31958f09d Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Fri, 9 Oct 2015 21:40:52 -0400 Subject: [PATCH] take github key through env var --- src/DotNetMashup.Web/Factory/RepositoryFactory.cs | 5 +++-- src/DotNetMashup.Web/Repositories/GitHubRepository.cs | 10 +++++++++- src/DotNetMashup.Web/Startup.cs | 6 ++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/DotNetMashup.Web/Factory/RepositoryFactory.cs b/src/DotNetMashup.Web/Factory/RepositoryFactory.cs index 5efc270..b52e3a6 100644 --- a/src/DotNetMashup.Web/Factory/RepositoryFactory.cs +++ b/src/DotNetMashup.Web/Factory/RepositoryFactory.cs @@ -6,6 +6,7 @@ using DotNetMashup.Web.Global; using DotNetMashup.Web.Model; using DotNetMashup.Web.Repositories; using Microsoft.Framework.Caching.Memory; +using Microsoft.Framework.Configuration; namespace DotNetMashup.Web.Factory { @@ -15,7 +16,7 @@ namespace DotNetMashup.Web.Factory private List Repos; private const string cacheKey = "data"; - public RepositoryFactory(IEnumerable data, ISiteSetting setting, IMemoryCache cache) + public RepositoryFactory(IEnumerable data, ISiteSetting setting, IMemoryCache cache, IConfiguration config) { if(data == null) { @@ -31,7 +32,7 @@ namespace DotNetMashup.Web.Factory } Repos = new List() { - new GitHubRepository(), + new GitHubRepository(config), new BlogPostRepository(data, setting) }; this.cache = cache; diff --git a/src/DotNetMashup.Web/Repositories/GitHubRepository.cs b/src/DotNetMashup.Web/Repositories/GitHubRepository.cs index 1bccedc..73569f4 100644 --- a/src/DotNetMashup.Web/Repositories/GitHubRepository.cs +++ b/src/DotNetMashup.Web/Repositories/GitHubRepository.cs @@ -2,12 +2,15 @@ using System.Linq; using System.Threading.Tasks; using DotNetMashup.Web.Model; +using Microsoft.Framework.Configuration; using Octokit; namespace DotNetMashup.Web.Repositories { public class GitHubRepository : IRepository { + private readonly IConfiguration config; + public string FactoryName { get @@ -16,13 +19,18 @@ namespace DotNetMashup.Web.Repositories } } + public GitHubRepository(IConfiguration config) + { + this.config = config; + } + public async Task> GetData() { CommonMark.CommonMarkSettings.Default.AdditionalFeatures = CommonMark.CommonMarkAdditionalFeatures.All; var client = new GitHubClient(new ProductHeaderValue("dotnetmashup")) { - Credentials = new Credentials("151e2514adab9e8e44ab99fe8c71899fffa34caa") + Credentials = new Credentials(config["github"]) }; var issues = await client.Issue.GetAllForRepository("aspnet", "Announcements"); return issues.Select(a => new GithubAnnouncement diff --git a/src/DotNetMashup.Web/Startup.cs b/src/DotNetMashup.Web/Startup.cs index 0539c13..3790070 100644 --- a/src/DotNetMashup.Web/Startup.cs +++ b/src/DotNetMashup.Web/Startup.cs @@ -7,6 +7,7 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.Dnx.Runtime; using Microsoft.Framework.Caching.Memory; +using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; using Newtonsoft.Json; @@ -16,9 +17,13 @@ namespace DotNetMashup.Web public class Startup { private IEnumerable _feedData = null; + private IConfiguration config = null; public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) { + config = new ConfigurationBuilder() + .AddEnvironmentVariables() + .Build(); _feedData = JsonConvert.DeserializeObject>(File.ReadAllText(Path.Combine(appEnv.ApplicationBasePath, "blogfeed.json"))); } @@ -27,6 +32,7 @@ namespace DotNetMashup.Web // This method gets called by the runtime. public void ConfigureServices(IServiceCollection services) { + services.AddInstance(config); services.AddSingleton(prov => { return new SiteSettings();