take github key through env var

This commit is contained in:
Tommy Parnell
2015-10-09 21:40:52 -04:00
parent a46940393d
commit b749a0c2c1
3 changed files with 18 additions and 3 deletions

View File

@@ -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<IRepository> Repos;
private const string cacheKey = "data";
public RepositoryFactory(IEnumerable<IBlogMetaData> data, ISiteSetting setting, IMemoryCache cache)
public RepositoryFactory(IEnumerable<IBlogMetaData> data, ISiteSetting setting, IMemoryCache cache, IConfiguration config)
{
if(data == null)
{
@@ -31,7 +32,7 @@ namespace DotNetMashup.Web.Factory
}
Repos = new List<IRepository>()
{
new GitHubRepository(),
new GitHubRepository(config),
new BlogPostRepository(data, setting)
};
this.cache = cache;

View File

@@ -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<IEnumerable<IExternalData>> 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

View File

@@ -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<IBlogMetaData> _feedData = null;
private IConfiguration config = null;
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
config = new ConfigurationBuilder()
.AddEnvironmentVariables()
.Build();
_feedData = JsonConvert.DeserializeObject<IEnumerable<BlogMetaData>>(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<ISiteSetting>(prov =>
{
return new SiteSettings();