-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tests Add more configs Fix test Clean up Integrate feature flag service Remove unneeded code Cleanup Add missing configs Try #2 WIP
- Loading branch information
1 parent
91a4d51
commit 4178449
Showing
18 changed files
with
252 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/NuGetGallery.Core/Features/FeatureFlagFileStorageService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
using NuGet.Services.FeatureFlags; | ||
|
||
namespace NuGetGallery.Features | ||
{ | ||
public class FeatureFlagFileStorageService : IFeatureFlagStorageService | ||
{ | ||
private readonly ICoreFileStorageService _storage; | ||
private readonly FeatureFlagOptions _options; | ||
private readonly JsonSerializer _serializer; | ||
|
||
public FeatureFlagFileStorageService(ICoreFileStorageService storage, FeatureFlagOptions options) | ||
{ | ||
_storage = storage ?? throw new ArgumentNullException(nameof(storage)); | ||
_options = options ?? throw new ArgumentNullException(nameof(options)); | ||
_serializer = new JsonSerializer(); | ||
} | ||
|
||
public async Task<FeatureFlagsState> GetAsync() | ||
{ | ||
using (var stream = await _storage.GetFileAsync(CoreConstants.Folders.FeatureFlagsContainerFolderName, CoreConstants.FeatureFlagsFileName)) | ||
using (var streamReader = new StreamReader(stream)) | ||
using (var reader = new JsonTextReader(streamReader)) | ||
{ | ||
return _serializer.Deserialize<FeatureFlagsState>(reader); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"Features": { | ||
}, | ||
|
||
"Flights": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using NuGet.Services.Entities; | ||
using NuGet.Services.FeatureFlags; | ||
|
||
namespace NuGetGallery | ||
{ | ||
public class FeatureFlagService : IFeatureFlagService | ||
{ | ||
private const string GalleryPrefix = "NuGetGallery."; | ||
|
||
// Typosquatting detection | ||
private const string TyposquattingFeatureName = GalleryPrefix + "Typosquatting"; | ||
private const string TyposquattingFlightName = GalleryPrefix + "TyposquattingFlight"; | ||
|
||
private readonly IFeatureFlagClient _featureFlagClient; | ||
private readonly IFlightClient _flightClient; | ||
|
||
public FeatureFlagService(IFeatureFlagClient featureFlagClient, IFlightClient flightClient) | ||
{ | ||
_featureFlagClient = featureFlagClient ?? throw new ArgumentNullException(nameof(featureFlagClient)); | ||
_flightClient = flightClient ?? throw new ArgumentNullException(nameof(flightClient)); | ||
} | ||
|
||
public bool IsTyposquattingEnabled() | ||
{ | ||
return _featureFlagClient.IsEnabled(TyposquattingFeatureName, @default: false); | ||
} | ||
|
||
public bool IsTyposquattingEnabled(User user) | ||
{ | ||
return _flightClient.IsEnabled(TyposquattingFlightName, user, @default: false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using NuGet.Services.Entities; | ||
|
||
namespace NuGetGallery | ||
{ | ||
public interface IFeatureFlagService | ||
{ | ||
/// <summary> | ||
/// Whether typosquatting detection is enabled on package uploads. If true, new packages | ||
/// cannot have an id that is similar to existing packages' ids. | ||
/// </summary> | ||
/// <returns></returns> | ||
bool IsTyposquattingEnabled(); | ||
|
||
/// <summary> | ||
/// Whether typosquatting detection is enabled for a specific user's package uploads. If true, | ||
/// new packages from this user cannot have an id that is similar to existing packages' ids. | ||
/// </summary> | ||
/// <param name="user"></param> | ||
/// <returns></returns> | ||
bool IsTyposquattingEnabled(User user); | ||
} | ||
} |
Oops, something went wrong.