Skip to content

Commit b1bbdcb

Browse files
committed
(GH-158) Deprecate the usage of Username and password
fixes #158
1 parent 9b5862f commit b1bbdcb

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

Source/GitReleaseManager.Cli/Options/BaseVcsSubOptions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@
55

66
namespace GitReleaseManager.Cli.Options
77
{
8+
using System;
89
using CommandLine;
910
using Destructurama.Attributed;
1011

1112
public abstract class BaseVcsOptions : BaseSubOptions
1213
{
13-
[Option('u', "username", HelpText = "The username to access Version Control System with.", Required = true, SetName = "Basic Auth")]
14+
internal const string OBSOLETE_MESSAGE = "Authentication using username and password have been deprecated, and will be removed in a future release. Please use --token instead!";
15+
16+
[Obsolete(OBSOLETE_MESSAGE)]
17+
[Option('u', "username", HelpText = "(DEPRECATED) The username to access Version Control System with.", Required = true, SetName = "Basic Auth")]
1418
public string UserName { get; set; }
1519

20+
[Obsolete(OBSOLETE_MESSAGE)]
1621
[LogMasked(Text = "[REDACTED]")]
17-
[Option('p', "password", HelpText = "The password to access Version Control System with.", Required = true, SetName = "Basic Auth")]
22+
[Option('p', "password", HelpText = "(DEPRECATED) The password to access Version Control System with.", Required = true, SetName = "Basic Auth")]
1823
public string Password { get; set; }
1924

2025
[LogMasked(Text = "[REDACTED]")]

Source/GitReleaseManager.Cli/Program.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ private static async Task<int> Main(string[] args)
4242
.WithParsed<BaseSubOptions>(LogConfiguration.ConfigureLogging)
4343
.WithParsed<BaseSubOptions>(CreateFiglet)
4444
.WithParsed<BaseSubOptions>(LogOptions)
45+
.WithParsed<BaseVcsOptions>(ReportUsernamePasswordDeprecation)
4546
.MapResult(
4647
(CreateSubOptions opts) => CreateReleaseAsync(opts),
4748
(DiscardSubOptions opts) => DiscardReleaseAsync(opts),
@@ -76,6 +77,14 @@ private static async Task<int> Main(string[] args)
7677
}
7778
}
7879

80+
private static void ReportUsernamePasswordDeprecation(BaseVcsOptions options)
81+
{
82+
if (!string.IsNullOrEmpty(options.UserName) || !string.IsNullOrEmpty(options.Password))
83+
{
84+
Log.Warning(BaseVcsOptions.OBSOLETE_MESSAGE);
85+
}
86+
}
87+
7988
private static void CreateFiglet(BaseSubOptions options)
8089
{
8190
if (options.NoLogo)

Source/GitReleaseManager/GitHubProvider.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,21 @@ public class GitHubProvider : IVcsProvider
3333
private readonly IMapper _mapper;
3434
private GitHubClient _gitHubClient;
3535

36+
[Obsolete("Use overload with token only instead")]
3637
public GitHubProvider(IMapper mapper, Config configuration, string userName, string password, string token)
3738
{
3839
_mapper = mapper;
3940
_configuration = configuration;
4041
CreateClient(userName, password, token);
4142
}
4243

44+
public GitHubProvider(IMapper mapper, Config configuration, string token)
45+
{
46+
_mapper = mapper;
47+
_configuration = configuration;
48+
CreateClient(token);
49+
}
50+
4351
public Task<int> GetNumberOfCommitsBetween(Milestone previousMilestone, Milestone currentMilestone, string user, string repository)
4452
{
4553
if (currentMilestone is null)
@@ -95,6 +103,7 @@ public async Task<ReadOnlyCollection<Milestone>> GetReadOnlyMilestonesAsync(stri
95103
return new ReadOnlyCollection<Milestone>(_mapper.Map<List<Milestone>>(closed.Concat(open).ToList()));
96104
}
97105

106+
[Obsolete("Use overload with token only instead")]
98107
public void CreateClient(string userName, string password, string token)
99108
{
100109
var credentials = string.IsNullOrWhiteSpace(token)
@@ -105,6 +114,13 @@ public void CreateClient(string userName, string password, string token)
105114
_gitHubClient = github;
106115
}
107116

117+
public void CreateClient(string token)
118+
{
119+
var credentials = new Credentials(token);
120+
var github = new GitHubClient(new ProductHeaderValue("GitReleaseManager")) { Credentials = credentials };
121+
_gitHubClient = github;
122+
}
123+
108124
public string GetCommitsLink(string user, string repository, Milestone milestone, Milestone previousMilestone)
109125
{
110126
if (milestone is null)

0 commit comments

Comments
 (0)