Skip to content

Commit 4657f8c

Browse files
authored
(GH-158) Deprecate the use of authentication with username+passw… (#189)
(GH-158) Deprecate the use of authentication with username+password
2 parents 9b5862f + a5414b9 commit 4657f8c

File tree

13 files changed

+97
-69
lines changed

13 files changed

+97
-69
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)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
For Authentication it is recommended to use the token parameter.
2+
Authentication with a Username and Password have been deprecated, and
3+
will be removed in a future release of GitReleaseManager.
4+
This authentication method have also been deprecated officially at
5+
GitHub.com
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Deprecated Parameters
2+
3+
The following parameters have been deprecated and should not be used in new
4+
code. This will be removed in a future release.
5+
6+
- `-u, --username`: The username to access Version Control System with.
7+
This can't be used when using the token parameter.
8+
- `-p, --password`: The password to access Version Control System with.
9+
This can't be used when using the token parameter.

docs/input/docs/commands/add-assets.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ additional assets to the release using the addasset command.
88

99
## **Required Parameters**
1010

11-
- `-u, --username`: The username to access GitHub with. This can't be used when
12-
using the token parameter.
13-
- `-p, --password`: The password to access GitHub with. This can't be used when
14-
using the token parameter.
1511
- `--token`: The access token to access GitHub with. This can't be used when
1612
using the username and password parameters.
1713
- `-o, --owner`: The owner of the repository.
@@ -28,16 +24,18 @@ additional assets to the release using the addasset command.
2824
- `-l, -logFilePath`: Path to where log file should be created. Defaults to
2925
logging to console.
3026

27+
<?! Include "_deprecated-args.md /?>
28+
3129
## **Notes**
3230

33-
For Authentication use either username and password, or token parameter
31+
<?! Include "_auth-notes.md" /?>
3432

3533
## **Examples**
3634

3735
```bash
38-
gitreleasemanager.exe addasset -t 0.1.0 -u bob -p password -o repoOwner -r repo -a c:\buildartifacts\setup.exe,c:\buildartifacts\setup.nupkg
39-
40-
gitreleasemanager.exe create --tagName 0.1.0 --username bob --password password --owner repoOwner --repository repo --assets c:\buildartifacts\setup.exe,c:\buildartifacts\setup.nupkg
36+
gitreleasemanager.exe addasset -t 0.1.0 -u bob --token fsdfsf67657sdf5s7d5f -r repo -a c:\buildartifacts\setup.exe,c:\buildartifacts\setup.nupkg
4137

4238
gitreleasemanager.exe create --tagName 0.1.0 --token fsdfsf67657sdf5s7d5f --owner repoOwner --repository repo --assets c:\buildartifacts\setup.exe,c:\buildartifacts\setup.nupkg
39+
40+
gitreleasemanager.exe create --tagName 0.1.0 --username bob --password password --owner repoOwner --repository repo --assets c:\buildartifacts\setup.exe,c:\buildartifacts\setup.nupkg
4341
```

docs/input/docs/commands/close.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ milestone.
99

1010
## **Required Parameters**
1111

12-
- `-u, --username`: The username to access GitHub with. This can't be used when
13-
using the token parameter.
14-
- `-p, --password`: The password to access GitHub with. This can't be used when
15-
using the token parameter.
1612
- `--token`: The access token to access GitHub with. This can't be used when
1713
using the username and password parameters.
1814
- `-o, --owner`: The owner of the repository.
@@ -26,16 +22,18 @@ milestone.
2622
- `-l, --logFilePath`: Path to where log file should be created. Defaults to
2723
logging to console.
2824

25+
<?! Include "_deprecated-args.md /?>
26+
2927
## **Notes**
3028

31-
For Authentication use either username and password, or token parameter
29+
<?! Include "_auth-notes.md" /?>
3230

3331
## **Examples**
3432

3533
```bash
36-
gitreleasemanager.exe close -m 0.1.0 -u bob -p password -o repoOwner -r repo
37-
38-
gitreleasemanager.exe close --milestone 0.1.0 --username bob --password password --owner repoOwner --repository repo
34+
gitreleasemanager.exe close -m 0.1.0 --token fsdfsf67657sdf5s7d5f -o repoOwner -r repo
3935

4036
gitreleasemanager.exe close --milestone 0.1.0 --token fsdfsf67657sdf5s7d5f --owner repoOwner --repository repo
37+
38+
gitreleasemanager.exe close --milestone 0.1.0 --username bob --password password --owner repoOwner --repository repo
4139
```

docs/input/docs/commands/create.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ to include in the Release.
1313

1414
## **Required Parameters**
1515

16-
- `-u, --username`: The username to access GitHub with. This can't be used when
17-
using the token parameter.
18-
- `-p, --password`: The password to access GitHub with. This can't be used when
19-
using the token parameter.
2016
- `--token`: The access token to access GitHub with. This can't be used when
2117
using the username and password parameters.
2218
- `-o, --owner`: The owner of the repository.
@@ -39,29 +35,31 @@ to include in the Release.
3935
- `-l, --logFilePath`: Path to where log file should be created. Defaults to
4036
logging to console.
4137

38+
<?! Include "_deprecated-args.md /?>
39+
4240
## **Notes**
4341

44-
For Authentication use either username and password, or token parameter
42+
<?! Include "_auth-notes.md" /?>
4543

4644
## **Examples**
4745

4846
Use GitReleaseManager to create a Release, generating the release notes based on
4947
Milestone:
5048

5149
```bash
52-
gitreleasemanager.exe create -m 0.1.0 -u bob -p password -o repoOwner -r repo
53-
54-
gitreleasemanager.exe create --milestone 0.1.0 --username bob --password password --owner repoOwner --repository repo
50+
gitreleasemanager.exe create -m 0.1.0 --token fsdfsf67657sdf5s7d5f -o repoOwner -r repo
5551

5652
gitreleasemanager.exe create --milestone 0.1.0 --token fsdfsf67657sdf5s7d5f --owner repoOwner --repository repo
53+
54+
gitreleasemanager.exe create --milestone 0.1.0 --username bob --password password --owner repoOwner --repository repo
5755
```
5856

5957
Use GitReleaseManager to create a Release, taking the release notes as an input parameter:
6058

6159
```bash
62-
gitreleasemanager.exe create -i c:\temp\releasenotes.md -n 0.1.0 -u bob -p password -o repoOwner -r repo
63-
64-
gitreleasemanager.exe create --inputFilePath c:\temp\releasenotes.md --name 0.1.0 --username bob --password password --owner repoOwner --repository repo
60+
gitreleasemanager.exe create -i c:\temp\releasenotes.md -n 0.1.0 --token fsdfsf67657sdf5s7d5f -o repoOwner -r repo
6561

6662
gitreleasemanager.exe create --inputFilePath c:\temp\releasenotes.md --name 0.1.0 --token fsdfsf67657sdf5s7d5f --owner repoOwner --repository repo
63+
64+
gitreleasemanager.exe create --inputFilePath c:\temp\releasenotes.md --name 0.1.0 --username bob --password password --owner repoOwner --repository repo
6765
```

docs/input/docs/commands/discard.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ delete a published release.
1515

1616
## **Required Parameters**
1717

18-
- `-u, --username`: The username to access GitHub with. This can't be used when
19-
using the token parameter.
20-
- `-p, --password`: The password to access GitHub with. This can't be used when
21-
using the token parameter.
2218
- `--token`: The access token to access GitHub with. This can't be used when
2319
using the username and password parameters.
2420
- `-o, --owner`: The owner of the repository.
@@ -33,16 +29,18 @@ delete a published release.
3329
- `-l, -logFilePath`: Path to where log file should be created. Defaults to
3430
logging to console.
3531

32+
<?! Include "_deprecated-args.md /?>
33+
3634
## **Notes**
3735

38-
For Authentication use either username and password, or token parameter
36+
<?! Include "_auth-notes.md" /?>
3937

4038
## **Examples**
4139

4240
```bash
43-
gitreleasemanager.exe discard -m 0.1.0 -u bob -p password -o repoOwner -r repo
44-
45-
gitreleasemanager.exe discard --milestone 0.1.0 --username bob --password password --owner repoOwner --repository repo
41+
gitreleasemanager.exe discard -m 0.1.0 --token fsdfsf67657sdf5s7d5f -o repoOwner -r repo
4642

4743
gitreleasemanager.exe discard --milestone 0.1.0 --token fsdfsf67657sdf5s7d5f --owner repoOwner --repository repo
44+
45+
gitreleasemanager.exe discard --milestone 0.1.0 --username bob --password password --owner repoOwner --repository repo
4846
```

docs/input/docs/commands/export.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ using the tagName parameter.
1313

1414
## **Required Parameters**
1515

16-
- `-u, --username`: The username to access GitHub with. This can't be used when
17-
using the token parameter.
18-
- `-p, --password`: The password to access GitHub with. This can't be used when
19-
using the token parameter.
2016
- `--token`: The access token to access GitHub with. This can't be used when
2117
using the username and password parameters.
2218
- `-o, --owner`: The owner of the repository.
@@ -32,18 +28,20 @@ using the tagName parameter.
3228
- `-l, --logFilePath`: Path to where log file should be created. Defaults to
3329
logging to console.
3430

31+
<?! Include "_deprecated-args.md /?>
32+
3533
## **Notes**
3634

37-
For Authentication use either username and password, or token parameter
35+
<?! Include "_auth-notes.md" /?>
3836

3937
## **Examples**
4038

4139
Use GitReleaseManager to export all Release Notes:
4240

4341
```bash
44-
gitreleasemanager.exe export -u bob -p password -o repoOwner -r repo -f c:\temp\releases.md
45-
46-
gitreleasemanager.exe export --username bob --password password --owner repoOwner --repository repo --fileOutputPath c:\temp\releases.md
42+
gitreleasemanager.exe export --token fsdfsf67657sdf5s7d5f -o repoOwner -r repo -f c:\temp\releases.md
4743

4844
gitreleasemanager.exe export --token fsdfsf67657sdf5s7d5f --owner repoOwner --repository repo --fileOutputPath c:\temp\releases.md
45+
46+
gitreleasemanager.exe export --username bob --password password --owner repoOwner --repository repo --fileOutputPath c:\temp\releases.md
4947
```

0 commit comments

Comments
 (0)