Skip to content

Commit

Permalink
Stop using the BAR token in darc (#4415)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
premun authored Feb 5, 2025
1 parent 71e3456 commit b5e6b42
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 31 deletions.
18 changes: 6 additions & 12 deletions src/Microsoft.DotNet.Darc/Darc/Helpers/LocalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.IO;
using Microsoft.DotNet.Darc.Options;
using Microsoft.DotNet.ProductConstructionService.Client;
using Microsoft.Extensions.Logging;
Expand All @@ -14,11 +15,6 @@ namespace Microsoft.DotNet.Darc.Helpers;
/// </summary>
internal class LocalSettings
{
public string BuildAssetRegistryToken { get; set; }

// Old way of storing the settings had the password and not the token so we keep both to deserialize these correctly.
public string BuildAssetRegistryPassword { get; set; }

public string GitHubToken { get; set; }

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

if (string.IsNullOrEmpty(localSettings.BuildAssetRegistryToken))
{
// Old way of storing the settings had the password and not the token
localSettings.BuildAssetRegistryToken = localSettings.BuildAssetRegistryPassword;
}

localSettings.AzureDevOpsToken = PreferOptionToSetting(options.AzureDevOpsPat, localSettings.AzureDevOpsToken);
localSettings.GitHubToken = PreferOptionToSetting(options.GitHubPat, localSettings.GitHubToken);
localSettings.BuildAssetRegistryToken = PreferOptionToSetting(options.BuildAssetRegistryToken, localSettings.BuildAssetRegistryToken);
localSettings.BuildAssetRegistryBaseUri = options.BuildAssetRegistryBaseUri
?? localSettings.BuildAssetRegistryBaseUri
?? ProductConstructionServiceApiOptions.ProductionMaestroUri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ internal class AuthenticateEditorPopUp : EditorPopUp
{
private readonly ILogger _logger;

private const string BarPasswordElement = "bar_password";
private const string GithubTokenElement = "github_token";
private const string AzureDevOpsTokenElement = "azure_devops_token";
private const string BarBaseUriElement = "build_asset_registry_base_uri";
Expand All @@ -40,12 +39,6 @@ public AuthenticateEditorPopUp(string path, ILogger logger)
// Initialize line contents.
Contents =
[
new("[DEPRECATED]", isComment: true),
new("BAR tokens (formerly created at https://maestro.dot.net/Account/Tokens) are now deprecated.", isComment: true),
new("Interactive sign-in through a security group is now enabled.", isComment: true),
new("See https://github.com/dotnet/arcade/blob/main/Documentation/Darc.md#setting-up-your-darc-client for more information.", isComment: true),
new($"{BarPasswordElement}={GetCurrentSettingForDisplay(settings.BuildAssetRegistryToken, string.Empty, true)}"),
new(string.Empty),
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),
new($"{GithubTokenElement}={GetCurrentSettingForDisplay(settings.GitHubToken, string.Empty, true)}"),
new(string.Empty),
Expand All @@ -72,15 +65,6 @@ public override Task<int> ProcessContents(IList<Line> contents)

switch (keyValue[0])
{
case BarPasswordElement:
settings.BuildAssetRegistryToken = ParseSetting(keyValue[1], settings.BuildAssetRegistryToken, true);

if (!string.IsNullOrEmpty(settings.BuildAssetRegistryToken))
{
_logger.LogWarning("BAR password is being deprecated and will stop working soon.");
}

break;
case GithubTokenElement:
settings.GitHubToken = ParseSetting(keyValue[1], settings.GitHubToken, true);
break;
Expand Down
15 changes: 12 additions & 3 deletions src/Microsoft.DotNet.Darc/Darc/Options/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,19 @@ public override Operation GetOperation(ServiceProvider sp)
public abstract class CommandLineOptions : ICommandLineOptions
{
[Option('p', "password",
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.")]
HelpText = "[DEPRECATED] Token used to authenticate to BAR. Please use Azure CLI or an interactive browser login flow.")]
[RedactFromLogging]
public string BuildAssetRegistryToken { get; set; }
public string BuildAssetRegistryToken
{
get => null;
set
{
if (!string.IsNullOrEmpty(value))
{
Console.WriteLine("The --password option is deprecated. Please use Azure CLI or an interactive browser login flow.");
}
}
}

[Option("github-pat", HelpText = "Token used to authenticate GitHub.")]
[RedactFromLogging]
Expand Down Expand Up @@ -106,7 +116,6 @@ public void InitializeFromSettings(ILogger logger)
AzureDevOpsPat ??= localSettings.AzureDevOpsToken;
GitHubPat ??= localSettings.GitHubToken;
BuildAssetRegistryBaseUri ??= localSettings.BuildAssetRegistryBaseUri;
BuildAssetRegistryToken ??= localSettings.BuildAssetRegistryToken;
}

/// <summary>
Expand Down

0 comments on commit b5e6b42

Please sign in to comment.