Exemple #1
0
 public BasicAuthenticationHandler(
     IOptionsMonitor <AuthenticationSchemeOptions> options,
     ILoggerFactory logger,
     UrlEncoder encoder,
     ISystemClock clock,
     IOptionsSnapshot <BaGetOptions> bagetOptions)
     : base(options, logger, encoder, clock)
 {
     _bagetOptions = bagetOptions?.Value;
 }
 public PackageDeletionService(
     IPackageService packages,
     IPackageStorageService storage,
     IOptionsSnapshot <BaGetOptions> options,
     ILogger <PackageDeletionService> logger)
 {
     _packages = packages ?? throw new ArgumentNullException(nameof(packages));
     _storage  = storage ?? throw new ArgumentNullException(nameof(storage));
     _options  = options?.Value ?? throw new ArgumentNullException(nameof(options));
     _logger   = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Exemple #3
0
        public ValidateOptionsResult Validate(string name, BaGetOptions options)
        {
            var failures = new List <string>();

            if (options.Database == null)
            {
                failures.Add($"The '{nameof(BaGetOptions.Database)}' config is required");
            }
            if (options.Mirror == null)
            {
                failures.Add($"The '{nameof(BaGetOptions.Mirror)}' config is required");
            }
            if (options.Search == null)
            {
                failures.Add($"The '{nameof(BaGetOptions.Search)}' config is required");
            }
            if (options.Storage == null)
            {
                failures.Add($"The '{nameof(BaGetOptions.Storage)}' config is required");
            }

            if (!ValidDatabaseTypes.Contains(options.Database?.Type))
            {
                failures.Add(
                    $"The '{nameof(BaGetOptions.Database)}:{nameof(DatabaseOptions.Type)}' config is invalid. " +
                    $"Allowed values: {string.Join(", ", ValidDatabaseTypes)}");
            }

            if (!ValidStorageTypes.Contains(options.Storage?.Type))
            {
                failures.Add(
                    $"The '{nameof(BaGetOptions.Storage)}:{nameof(StorageOptions.Type)}' config is invalid. " +
                    $"Allowed values: {string.Join(", ", ValidStorageTypes)}");
            }

            if (!ValidSearchTypes.Contains(options.Search?.Type))
            {
                failures.Add(
                    $"The '{nameof(BaGetOptions.Search)}:{nameof(SearchOptions.Type)}' config is invalid. " +
                    $"Allowed values: {string.Join(", ", ValidSearchTypes)}");
            }

            if (failures.Any())
            {
                return(ValidateOptionsResult.Fail(failures));
            }

            return(ValidateOptionsResult.Success);
        }
        public PackageDeletionServiceTests()
        {
            _packages = new Mock<IPackageService>();
            _storage = new Mock<IPackageStorageService>();
            _options = new BaGetOptions();

            var optionsSnapshot = new Mock<IOptionsSnapshot<BaGetOptions>>();
            optionsSnapshot.Setup(o => o.Value).Returns(_options);

            _target = new PackageDeletionService(
                _packages.Object,
                _storage.Object,
                optionsSnapshot.Object,
                Mock.Of<ILogger<PackageDeletionService>>());
        }