Skip to content

Commit

Permalink
Read encoded credentials from env variable. Checked-in token has been…
Browse files Browse the repository at this point in the history
… revoked
  • Loading branch information
jamesseanwright committed Nov 23, 2017
1 parent f12a6e0 commit aa43fc4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Responder/GitHubResponder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using GitHubAutoresponder.Shared;
using GitHubAutoresponder.Webhook;
using Microsoft.Net.Http.Headers;

Expand All @@ -15,18 +16,21 @@ public class GitHubResponder : IGitHubResponder {
private IResponseFactory responseFactory;
private HttpClient httpClient;
private IJsonSerialiser jsonSerialiser;
private IEnvironment environment;

public GitHubResponder(
IResponseFactory responseFactory,
HttpClient httpClient,
IJsonSerialiser jsonSerialiser
IJsonSerialiser jsonSerialiser,
IEnvironment environment
) {
this.httpClient = httpClient;
this.jsonSerialiser = jsonSerialiser;
this.responseFactory = responseFactory;
this.environment = environment;

this.httpClient.DefaultRequestHeaders.Add(HeaderNames.UserAgent, USER_AGENT_HEADER);
this.httpClient.DefaultRequestHeaders.Add(HeaderNames.Authorization, "Basic amFtZXNzZWFud3JpZ2h0OjFmYmJkYzBmZmJlMjA3ZWI3ZGU5MDQyYmEyMWM3YWYzM2U5NjAxN2Q=");
this.httpClient.DefaultRequestHeaders.Add(HeaderNames.Authorization, $"Basic {this.environment.EncodededCredentials}");
}

async Task<bool> IGitHubResponder.RespondAsync(Payload payload) {
Expand Down
1 change: 1 addition & 0 deletions Responder/JsonSerialiser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using GitHubAutoresponder.Shared;
using Newtonsoft.Json;

namespace GitHubAutoresponder.Responder {
Expand Down
3 changes: 2 additions & 1 deletion Dependencies.cs → Shared/Dependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
using GitHubAutoresponder.Webhook;
using Microsoft.Extensions.DependencyInjection;

namespace GitHubAutoresponder {
namespace GitHubAutoresponder.Shared {
public static class Dependencies {
public static void Register(IServiceCollection services) {
services.AddSingleton(typeof (IGitHubResponder), typeof (GitHubResponder));
services.AddSingleton(typeof (IResponseFactory), typeof (ResponseFactory));
services.AddSingleton(typeof (IModelStateConverter), typeof (ModelStateConverter));
services.AddSingleton(typeof (IJsonSerialiser), typeof (JsonSerialiser));
services.AddSingleton(typeof (IEnvironment), typeof (Environment));
services.AddSingleton(typeof (HttpClient), typeof (HttpClient));
}
}
Expand Down
6 changes: 6 additions & 0 deletions Shared/Environment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace GitHubAutoresponder.Shared {
public class Environment : IEnvironment
{
public string EncodededCredentials => System.Environment.GetEnvironmentVariable("GHAR_CREDENTIALS");
}
}
5 changes: 5 additions & 0 deletions Shared/IEnvironment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace GitHubAutoresponder.Shared {
public interface IEnvironment {
string EncodededCredentials { get; }
}
}
2 changes: 1 addition & 1 deletion JsonContractResolver.cs → Shared/JsonContractResolver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Newtonsoft.Json.Serialization;

namespace GitHubAutoresponder {
namespace GitHubAutoresponder.Shared {
public static class JsonContractResolver {
private static IContractResolver resolver;

Expand Down
1 change: 1 addition & 0 deletions Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using GitHubAutoresponder.Shared;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
Expand Down

0 comments on commit aa43fc4

Please sign in to comment.