Skip to content

Commit 5ffd1cf

Browse files
authored
settings: support scoped enterprise settings (#1149)
Add support for remote URL-scoped enterprise default settings. Fixes #983
2 parents c12409f + 8122dc0 commit 5ffd1cf

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/shared/Core.Tests/SettingsTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Linq;
43
using System.Net;
54
using GitCredentialManager.Tests.Objects;

src/shared/Core/Interop/Windows/WindowsSettings.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public WindowsSettings(IEnvironment environment, IGit git, ITrace trace)
1717
PlatformUtils.EnsureWindows();
1818
}
1919

20-
protected override bool TryGetExternalDefault(string section, string property, out string value)
20+
protected override bool TryGetExternalDefault(string section, string scope, string property, out string value)
2121
{
2222
value = null;
2323

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

35-
string name = $"{section}.{property}";
35+
string name = string.IsNullOrWhiteSpace(scope)
36+
? $"{section}.{property}"
37+
: $"{section}.{scope}.{property}";
38+
3639
object registryValue = configKey.GetValue(name);
3740
if (registryValue is null)
3841
{
@@ -46,7 +49,7 @@ protected override bool TryGetExternalDefault(string section, string property, o
4649
return true;
4750
}
4851
#else
49-
return base.TryGetExternalDefault(section, property, out value);
52+
return base.TryGetExternalDefault(section, scope, property, out value);
5053
#endif
5154
}
5255
}

src/shared/Core/Settings.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,12 @@ public IEnumerable<string> GetSettingValues(string envarName, string section, st
408408
{
409409
yield return value;
410410
}
411+
412+
// Check for an externally specified default value
413+
if (TryGetExternalDefault(section, scope, property, out value))
414+
{
415+
yield return value;
416+
}
411417
}
412418
}
413419

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

426-
// Check for an externally specified default value
427-
if (TryGetExternalDefault(section, property, out string defaultValue))
432+
// Check for an externally specified default value without a scope
433+
if (TryGetExternalDefault(section, null, property, out value))
428434
{
429-
yield return defaultValue;
435+
yield return value;
430436
}
431437
}
432438
}
@@ -436,10 +442,11 @@ public IEnumerable<string> GetSettingValues(string envarName, string section, st
436442
/// This may come from external policies or the Operating System.
437443
/// </summary>
438444
/// <param name="section">Configuration section name.</param>
445+
/// <param name="scope">Optional configuration scope.</param>
439446
/// <param name="property">Configuration property name.</param>
440447
/// <param name="value">Value of the configuration setting, or null.</param>
441448
/// <returns>True if a default setting has been set, false otherwise.</returns>
442-
protected virtual bool TryGetExternalDefault(string section, string property, out string value)
449+
protected virtual bool TryGetExternalDefault(string section, string scope, string property, out string value)
443450
{
444451
value = null;
445452
return false;

0 commit comments

Comments
 (0)