Restructure solution layout by module
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using StellaOps.Auth.Abstractions;
|
||||
|
||||
namespace StellaOps.Cartographer.Options;
|
||||
|
||||
/// <summary>
|
||||
/// Applies Cartographer-specific defaults to <see cref="CartographerAuthorityOptions"/>.
|
||||
/// </summary>
|
||||
internal static class CartographerAuthorityOptionsConfigurator
|
||||
{
|
||||
/// <summary>
|
||||
/// Ensures required scopes are present and duplicates are removed case-insensitively.
|
||||
/// </summary>
|
||||
/// <param name="options">Target options.</param>
|
||||
public static void ApplyDefaults(CartographerAuthorityOptions options)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(options);
|
||||
|
||||
EnsureScope(options.RequiredScopes, StellaOpsScopes.GraphRead);
|
||||
EnsureScope(options.RequiredScopes, StellaOpsScopes.GraphWrite);
|
||||
}
|
||||
|
||||
private static void EnsureScope(ICollection<string> scopes, string scope)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(scopes);
|
||||
ArgumentException.ThrowIfNullOrEmpty(scope);
|
||||
|
||||
if (scopes.Any(existing => string.Equals(existing, scope, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
scopes.Add(scope);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user