From 23de1b12cc075dfe18d13955576e12be58c8ab07 Mon Sep 17 00:00:00 2001 From: Joel Verhagen Date: Wed, 9 Oct 2024 16:07:33 -0400 Subject: [PATCH] Add flight for using federated credentials --- src/AccountDeleter/EmptyFeatureFlagService.cs | 7 ++++++- .../Fakes/FakeFeatureFlagService.cs | 7 ++++++- .../Configuration/FeatureFlagService.cs | 12 +++++++++--- .../Configuration/IFeatureFlagService.cs | 7 ++++++- src/NuGetGallery/App_Data/Files/Content/flags.json | 8 +++++++- .../Fakes/FakeFeatureFlagService.cs | 4 +++- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/AccountDeleter/EmptyFeatureFlagService.cs b/src/AccountDeleter/EmptyFeatureFlagService.cs index 4b1cdb7ad2..db300232c8 100644 --- a/src/AccountDeleter/EmptyFeatureFlagService.cs +++ b/src/AccountDeleter/EmptyFeatureFlagService.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -323,5 +323,10 @@ public bool IsAdvancedFrameworkFilteringEnabled(User user) { throw new NotImplementedException(); } + + public bool CanUseFederatedCredentials(User user) + { + throw new NotImplementedException(); + } } } diff --git a/src/GitHubVulnerabilities2Db/Fakes/FakeFeatureFlagService.cs b/src/GitHubVulnerabilities2Db/Fakes/FakeFeatureFlagService.cs index 612fe7bac9..776be62af0 100644 --- a/src/GitHubVulnerabilities2Db/Fakes/FakeFeatureFlagService.cs +++ b/src/GitHubVulnerabilities2Db/Fakes/FakeFeatureFlagService.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -324,5 +324,10 @@ public bool IsAdvancedFrameworkFilteringEnabled(User user) { throw new NotImplementedException(); } + + public bool CanUseFederatedCredentials(User user) + { + throw new NotImplementedException(); + } } } diff --git a/src/NuGetGallery.Services/Configuration/FeatureFlagService.cs b/src/NuGetGallery.Services/Configuration/FeatureFlagService.cs index c5b3cbfca1..3ae66e189b 100644 --- a/src/NuGetGallery.Services/Configuration/FeatureFlagService.cs +++ b/src/NuGetGallery.Services/Configuration/FeatureFlagService.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -63,6 +63,7 @@ public class FeatureFlagService : IFeatureFlagService private const string FrameworkFilteringFeatureName = GalleryPrefix + "FrameworkFiltering"; private const string DisplayTfmBadgesFeatureName = GalleryPrefix + "DisplayTfmBadges"; private const string AdvancedFrameworkFilteringFeatureName = GalleryPrefix + "AdvancedFrameworkFiltering"; + private const string FederatedCredentialsFeatureName = GalleryPrefix + "FederatedCredentials"; private const string ODataV1GetAllNonHijackedFeatureName = GalleryPrefix + "ODataV1GetAllNonHijacked"; private const string ODataV1GetAllCountNonHijackedFeatureName = GalleryPrefix + "ODataV1GetAllCountNonHijacked"; @@ -120,7 +121,7 @@ public bool IsPackagesAtomFeedEnabled() /// /// The number of versions a package needs to have before it should be flighted using instead of . /// - private const int _manageDeprecationForManyVersionsThreshold = 500; + private const int ManageDeprecationForManyVersionsThreshold = 500; public bool IsManageDeprecationEnabled(User user, PackageRegistration registration) { @@ -144,7 +145,7 @@ public bool IsManageDeprecationEnabled(User user, IEnumerable allVersio return false; } - return allVersions.Count() < _manageDeprecationForManyVersionsThreshold + return allVersions.Count() < ManageDeprecationForManyVersionsThreshold || _client.IsEnabled(ManageDeprecationForManyVersionsFeatureName, user, defaultValue: true); } @@ -421,5 +422,10 @@ public bool IsAdvancedFrameworkFilteringEnabled(User user) { return _client.IsEnabled(AdvancedFrameworkFilteringFeatureName, user, defaultValue: false); } + + public bool CanUseFederatedCredentials(User user) + { + return _client.IsEnabled(FederatedCredentialsFeatureName, user, defaultValue: false); + } } } diff --git a/src/NuGetGallery.Services/Configuration/IFeatureFlagService.cs b/src/NuGetGallery.Services/Configuration/IFeatureFlagService.cs index 68bbf227ec..c58a19b0a9 100644 --- a/src/NuGetGallery.Services/Configuration/IFeatureFlagService.cs +++ b/src/NuGetGallery.Services/Configuration/IFeatureFlagService.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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.Collections.Generic; @@ -342,5 +342,10 @@ public interface IFeatureFlagService /// Whether or not to allow filtering by frameworks on NuGet.org search /// bool IsAdvancedFrameworkFilteringEnabled(User user); + + /// + /// Whether or not the user specified in a package owner scope can use federated credentials. + /// + bool CanUseFederatedCredentials(User user); } } diff --git a/src/NuGetGallery/App_Data/Files/Content/flags.json b/src/NuGetGallery/App_Data/Files/Content/flags.json index 8d9a69ec0a..b702e453c6 100644 --- a/src/NuGetGallery/App_Data/Files/Content/flags.json +++ b/src/NuGetGallery/App_Data/Files/Content/flags.json @@ -145,6 +145,12 @@ "SiteAdmins": false, "Accounts": [], "Domains": [] + }, + "NuGetGallery.FederatedCredentials": { + "All": true, + "SiteAdmins": false, + "Accounts": [], + "Domains": [] } } -} +} \ No newline at end of file diff --git a/src/VerifyMicrosoftPackage/Fakes/FakeFeatureFlagService.cs b/src/VerifyMicrosoftPackage/Fakes/FakeFeatureFlagService.cs index 4d89d4fb4a..7b3ab36c67 100644 --- a/src/VerifyMicrosoftPackage/Fakes/FakeFeatureFlagService.cs +++ b/src/VerifyMicrosoftPackage/Fakes/FakeFeatureFlagService.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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; @@ -135,5 +135,7 @@ public class FakeFeatureFlagService : IFeatureFlagService public bool IsDisplayTfmBadgesEnabled(User user) => throw new NotImplementedException(); public bool IsAdvancedFrameworkFilteringEnabled(User user) => throw new NotImplementedException(); + + public bool CanUseFederatedCredentials(User user) => throw new NotImplementedException(); } }