38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
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);
|
|
}
|
|
}
|