Skip to content

Commit b5e6b42

Browse files
authored
Stop using the BAR token in darc (#4415)
Token is no longer supported (#4312) `darc` will - stop reading/storing the BAR token from the local settings - stop using it if it's supplied as an argument (but not fail yet) - warn if it's supplied - stop giving a warning when the user has not called `darc authenticate` yet
1 parent 71e3456 commit b5e6b42

File tree

3 files changed

+18
-31
lines changed

3 files changed

+18
-31
lines changed

src/Microsoft.DotNet.Darc/Darc/Helpers/LocalSettings.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5+
using System.IO;
56
using Microsoft.DotNet.Darc.Options;
67
using Microsoft.DotNet.ProductConstructionService.Client;
78
using Microsoft.Extensions.Logging;
@@ -14,11 +15,6 @@ namespace Microsoft.DotNet.Darc.Helpers;
1415
/// </summary>
1516
internal class LocalSettings
1617
{
17-
public string BuildAssetRegistryToken { get; set; }
18-
19-
// Old way of storing the settings had the password and not the token so we keep both to deserialize these correctly.
20-
public string BuildAssetRegistryPassword { get; set; }
21-
2218
public string GitHubToken { get; set; }
2319

2420
public string AzureDevOpsToken { get; set; }
@@ -55,6 +51,11 @@ public static LocalSettings GetSettings(ICommandLineOptions options, ILogger log
5551
{
5652
localSettings = LoadSettingsFile();
5753
}
54+
catch (FileNotFoundException)
55+
{
56+
// User has not called darc authenticate yet
57+
// Not a problem of it self unless the operation they run needs the GitHub token
58+
}
5859
catch (Exception e)
5960
{
6061
if (!options.IsCi && options.OutputFormat != DarcOutputType.json)
@@ -71,15 +72,8 @@ static string PreferOptionToSetting(string option, string localSetting)
7172
// Prefer the command line options over the settings file
7273
localSettings ??= new LocalSettings();
7374

74-
if (string.IsNullOrEmpty(localSettings.BuildAssetRegistryToken))
75-
{
76-
// Old way of storing the settings had the password and not the token
77-
localSettings.BuildAssetRegistryToken = localSettings.BuildAssetRegistryPassword;
78-
}
79-
8075
localSettings.AzureDevOpsToken = PreferOptionToSetting(options.AzureDevOpsPat, localSettings.AzureDevOpsToken);
8176
localSettings.GitHubToken = PreferOptionToSetting(options.GitHubPat, localSettings.GitHubToken);
82-
localSettings.BuildAssetRegistryToken = PreferOptionToSetting(options.BuildAssetRegistryToken, localSettings.BuildAssetRegistryToken);
8377
localSettings.BuildAssetRegistryBaseUri = options.BuildAssetRegistryBaseUri
8478
?? localSettings.BuildAssetRegistryBaseUri
8579
?? ProductConstructionServiceApiOptions.ProductionMaestroUri;

src/Microsoft.DotNet.Darc/Darc/Models/PopUps/AuthenticateEditorPopUp.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ internal class AuthenticateEditorPopUp : EditorPopUp
1313
{
1414
private readonly ILogger _logger;
1515

16-
private const string BarPasswordElement = "bar_password";
1716
private const string GithubTokenElement = "github_token";
1817
private const string AzureDevOpsTokenElement = "azure_devops_token";
1918
private const string BarBaseUriElement = "build_asset_registry_base_uri";
@@ -40,12 +39,6 @@ public AuthenticateEditorPopUp(string path, ILogger logger)
4039
// Initialize line contents.
4140
Contents =
4241
[
43-
new("[DEPRECATED]", isComment: true),
44-
new("BAR tokens (formerly created at https://maestro.dot.net/Account/Tokens) are now deprecated.", isComment: true),
45-
new("Interactive sign-in through a security group is now enabled.", isComment: true),
46-
new("See https://github.com/dotnet/arcade/blob/main/Documentation/Darc.md#setting-up-your-darc-client for more information.", isComment: true),
47-
new($"{BarPasswordElement}={GetCurrentSettingForDisplay(settings.BuildAssetRegistryToken, string.Empty, true)}"),
48-
new(string.Empty),
4942
new("Create new GitHub personal access tokens at https://github.com/settings/tokens (no scopes needed but needs SSO enabled on the PAT)", isComment: true),
5043
new($"{GithubTokenElement}={GetCurrentSettingForDisplay(settings.GitHubToken, string.Empty, true)}"),
5144
new(string.Empty),
@@ -72,15 +65,6 @@ public override Task<int> ProcessContents(IList<Line> contents)
7265

7366
switch (keyValue[0])
7467
{
75-
case BarPasswordElement:
76-
settings.BuildAssetRegistryToken = ParseSetting(keyValue[1], settings.BuildAssetRegistryToken, true);
77-
78-
if (!string.IsNullOrEmpty(settings.BuildAssetRegistryToken))
79-
{
80-
_logger.LogWarning("BAR password is being deprecated and will stop working soon.");
81-
}
82-
83-
break;
8468
case GithubTokenElement:
8569
settings.GitHubToken = ParseSetting(keyValue[1], settings.GitHubToken, true);
8670
break;

src/Microsoft.DotNet.Darc/Darc/Options/CommandLineOptions.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,19 @@ public override Operation GetOperation(ServiceProvider sp)
2828
public abstract class CommandLineOptions : ICommandLineOptions
2929
{
3030
[Option('p', "password",
31-
HelpText = "Token used to authenticate to BAR. If it or the federated token are omitted, auth falls back to Azure CLI or an interactive browser login flow.")]
31+
HelpText = "[DEPRECATED] Token used to authenticate to BAR. Please use Azure CLI or an interactive browser login flow.")]
3232
[RedactFromLogging]
33-
public string BuildAssetRegistryToken { get; set; }
33+
public string BuildAssetRegistryToken
34+
{
35+
get => null;
36+
set
37+
{
38+
if (!string.IsNullOrEmpty(value))
39+
{
40+
Console.WriteLine("The --password option is deprecated. Please use Azure CLI or an interactive browser login flow.");
41+
}
42+
}
43+
}
3444

3545
[Option("github-pat", HelpText = "Token used to authenticate GitHub.")]
3646
[RedactFromLogging]
@@ -106,7 +116,6 @@ public void InitializeFromSettings(ILogger logger)
106116
AzureDevOpsPat ??= localSettings.AzureDevOpsToken;
107117
GitHubPat ??= localSettings.GitHubToken;
108118
BuildAssetRegistryBaseUri ??= localSettings.BuildAssetRegistryBaseUri;
109-
BuildAssetRegistryToken ??= localSettings.BuildAssetRegistryToken;
110119
}
111120

112121
/// <summary>

0 commit comments

Comments
 (0)