summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/StardewModdingAPI.Web/Controllers/ModsController.cs17
-rw-r--r--src/StardewModdingAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs6
-rw-r--r--src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs6
-rw-r--r--src/StardewModdingAPI.Web/Startup.cs1
-rw-r--r--src/StardewModdingAPI.Web/appsettings.json2
5 files changed, 29 insertions, 3 deletions
diff --git a/src/StardewModdingAPI.Web/Controllers/ModsController.cs b/src/StardewModdingAPI.Web/Controllers/ModsController.cs
index 4b1abde4..4715d379 100644
--- a/src/StardewModdingAPI.Web/Controllers/ModsController.cs
+++ b/src/StardewModdingAPI.Web/Controllers/ModsController.cs
@@ -44,8 +44,21 @@ namespace StardewModdingAPI.Web.Controllers
this.Repositories =
new IModRepository[]
{
- new GitHubRepository(config.GitHubKey, config.GitHubBaseUrl, config.GitHubReleaseUrlFormat, config.GitHubUserAgent, config.GitHubAcceptHeader),
- new NexusRepository(config.NexusKey, config.NexusUserAgent, config.NexusBaseUrl, config.NexusModUrlFormat)
+ new GitHubRepository(
+ vendorKey: config.GitHubKey,
+ baseUrl: config.GitHubBaseUrl,
+ releaseUrlFormat: config.GitHubReleaseUrlFormat,
+ userAgent: config.GitHubUserAgent,
+ acceptHeader: config.GitHubAcceptHeader,
+ username: config.GitHubUsername,
+ password: config.GitHubPassword
+ ),
+ new NexusRepository(
+ vendorKey: config.NexusKey,
+ userAgent: config.NexusUserAgent,
+ baseUrl: config.NexusBaseUrl,
+ modUrlFormat: config.NexusModUrlFormat
+ )
}
.ToDictionary(p => p.VendorKey, StringComparer.CurrentCultureIgnoreCase);
}
diff --git a/src/StardewModdingAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs b/src/StardewModdingAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs
index 4dbad506..5d55ba18 100644
--- a/src/StardewModdingAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs
+++ b/src/StardewModdingAPI.Web/Framework/ConfigModels/ModUpdateCheckConfig.cs
@@ -30,6 +30,12 @@ namespace StardewModdingAPI.Web.Framework.ConfigModels
/// <summary>The Accept header value expected by the GitHub API.</summary>
public string GitHubAcceptHeader { get; set; }
+ /// <summary>The username with which to authenticate to the GitHub API (if any).</summary>
+ public string GitHubUsername { get; set; }
+
+ /// <summary>The password with which to authenticate to the GitHub API (if any).</summary>
+ public string GitHubPassword { get; set; }
+
/****
** Nexus Mods
****/
diff --git a/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs b/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs
index c5772ad9..67e706ed 100644
--- a/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs
+++ b/src/StardewModdingAPI.Web/Framework/ModRepositories/GitHubRepository.cs
@@ -35,7 +35,9 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
/// <param name="releaseUrlFormat">The URL for a Nexus Mods API query excluding the <paramref name="baseUrl"/>, where {0} is the mod ID.</param>
/// <param name="userAgent">The user agent for the GitHub API client.</param>
/// <param name="acceptHeader">The Accept header value expected by the GitHub API.</param>
- public GitHubRepository(string vendorKey, string baseUrl, string releaseUrlFormat, string userAgent, string acceptHeader)
+ /// <param name="username">The username with which to authenticate to the GitHub API.</param>
+ /// <param name="password">The password with which to authenticate to the GitHub API.</param>
+ public GitHubRepository(string vendorKey, string baseUrl, string releaseUrlFormat, string userAgent, string acceptHeader, string username, string password)
{
this.VendorKey = vendorKey;
this.ReleaseUrlFormat = releaseUrlFormat;
@@ -43,6 +45,8 @@ namespace StardewModdingAPI.Web.Framework.ModRepositories
this.Client = new FluentClient(baseUrl)
.SetUserAgent(string.Format(userAgent, this.GetType().Assembly.GetName().Version))
.AddDefault(req => req.WithHeader("Accept", acceptHeader));
+ if (!string.IsNullOrWhiteSpace(username))
+ this.Client = this.Client.SetBasicAuthentication(username, password);
}
/// <summary>Get metadata about a mod in the repository.</summary>
diff --git a/src/StardewModdingAPI.Web/Startup.cs b/src/StardewModdingAPI.Web/Startup.cs
index b668c63e..4806aefe 100644
--- a/src/StardewModdingAPI.Web/Startup.cs
+++ b/src/StardewModdingAPI.Web/Startup.cs
@@ -29,6 +29,7 @@ namespace StardewModdingAPI.Web
{
this.Configuration = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
+ .AddEnvironmentVariables()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables()
diff --git a/src/StardewModdingAPI.Web/appsettings.json b/src/StardewModdingAPI.Web/appsettings.json
index f996157c..29fb195e 100644
--- a/src/StardewModdingAPI.Web/appsettings.json
+++ b/src/StardewModdingAPI.Web/appsettings.json
@@ -13,6 +13,8 @@
"GitHubBaseUrl": "https://api.github.com",
"GitHubReleaseUrlFormat": "repos/{0}/releases/latest",
"GitHubAcceptHeader": "application/vnd.github.v3+json",
+ "GitHubUsername": null, /* set via environment properties */
+ "GitHubPassword": null, /* set via environment properties */
"NexusKey": "Nexus",
"NexusUserAgent": "Nexus Client v0.63.15",