Skip to content

Commit

Permalink
settings: support scoped enterprise settings (#1149)
Browse files Browse the repository at this point in the history
Add support for remote URL-scoped enterprise default settings.

Fixes #983
  • Loading branch information
mjcheetham committed Mar 14, 2023
2 parents c12409f + 8122dc0 commit 5ffd1cf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/shared/Core.Tests/SettingsTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using GitCredentialManager.Tests.Objects;
Expand Down
9 changes: 6 additions & 3 deletions src/shared/Core/Interop/Windows/WindowsSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public WindowsSettings(IEnvironment environment, IGit git, ITrace trace)
PlatformUtils.EnsureWindows();
}

protected override bool TryGetExternalDefault(string section, string property, out string value)
protected override bool TryGetExternalDefault(string section, string scope, string property, out string value)
{
value = null;

Expand All @@ -32,7 +32,10 @@ protected override bool TryGetExternalDefault(string section, string property, o
return false;
}

string name = $"{section}.{property}";
string name = string.IsNullOrWhiteSpace(scope)
? $"{section}.{property}"
: $"{section}.{scope}.{property}";

object registryValue = configKey.GetValue(name);
if (registryValue is null)
{
Expand All @@ -46,7 +49,7 @@ protected override bool TryGetExternalDefault(string section, string property, o
return true;
}
#else
return base.TryGetExternalDefault(section, property, out value);
return base.TryGetExternalDefault(section, scope, property, out value);
#endif
}
}
Expand Down
15 changes: 11 additions & 4 deletions src/shared/Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,12 @@ public IEnumerable<string> GetSettingValues(string envarName, string section, st
{
yield return value;
}

// Check for an externally specified default value
if (TryGetExternalDefault(section, scope, property, out value))
{
yield return value;
}
}
}

Expand All @@ -423,10 +429,10 @@ public IEnumerable<string> GetSettingValues(string envarName, string section, st
yield return value;
}

// Check for an externally specified default value
if (TryGetExternalDefault(section, property, out string defaultValue))
// Check for an externally specified default value without a scope
if (TryGetExternalDefault(section, null, property, out value))
{
yield return defaultValue;
yield return value;
}
}
}
Expand All @@ -436,10 +442,11 @@ public IEnumerable<string> GetSettingValues(string envarName, string section, st
/// This may come from external policies or the Operating System.
/// </summary>
/// <param name="section">Configuration section name.</param>
/// <param name="scope">Optional configuration scope.</param>
/// <param name="property">Configuration property name.</param>
/// <param name="value">Value of the configuration setting, or null.</param>
/// <returns>True if a default setting has been set, false otherwise.</returns>
protected virtual bool TryGetExternalDefault(string section, string property, out string value)
protected virtual bool TryGetExternalDefault(string section, string scope, string property, out string value)
{
value = null;
return false;
Expand Down

0 comments on commit 5ffd1cf

Please sign in to comment.