Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

settings: support scoped enterprise settings #1149

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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