// Copyright (c) Microsoft. All rights reserved.
//
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NuGet.Protocol.Plugins;
using NuGetCredentialProvider.CredentialProviders;
using NuGetCredentialProvider.Logging;
namespace NuGetCredentialProvider.RequestHandlers
{
///
/// Handles a and replies with the supported operations.
///
internal class GetOperationClaimsRequestHandler : RequestHandlerBase
{
///
/// A when a registered credential provider can provide credentials for the current request.
///
private static readonly GetOperationClaimsResponse CanProvideCredentialsResponse = new GetOperationClaimsResponse(new List
{
OperationClaim.Authentication
});
///
/// A when no registered credential providers can provide credentials for the current request.
///
private static readonly GetOperationClaimsResponse EmptyGetOperationClaimsResponse = new GetOperationClaimsResponse(new List());
private readonly IReadOnlyCollection _credentialProviders;
///
/// Initializes a new instance of the class.
///
/// A to use for logging.
/// An containing credential providers.
public GetOperationClaimsRequestHandler(ILogger logger, IReadOnlyCollection credentialProviders)
: base(logger)
{
_credentialProviders = credentialProviders ?? throw new ArgumentNullException(nameof(credentialProviders));
}
public override Task HandleRequestAsync(GetOperationClaimsRequest request)
{
if (request.PackageSourceRepository != null || request.ServiceIndex != null)
{
return Task.FromResult(EmptyGetOperationClaimsResponse);
}
return Task.FromResult(CanProvideCredentialsResponse);
}
}
}