Skip to content

Commit 27d88ac

Browse files
authored
Add --allow-custom-scopes flag to skip scope validation. (#369)
* Add no-validate flag to skip scope validation * Shorten help text for no-validate flag * rename the flag and address review comments * Fix typo in doc
1 parent 61a45bb commit 27d88ac

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
### Added
9+
- Added `--allow-custom-scopes` flag to skip validation and allow custom Azure DevOps PAT scopes.
910
- Added new sub-command `azureauth ado pat scopes` to list the set of actual scopes the `pat` command validates against and print the short-link to the pat scopes docs.
1011

1112
## [0.8.4] - 2023-09-05

src/AdoPat/Scopes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ public static class Scopes
145145

146146
/// <summary>Validate the given scopes.</summary>
147147
/// <param name="scopes">The scopes to validate.</param>
148-
/// <returns>The set of invalid scopes present in the given scopes. The
149-
/// empty set means no scopes were invalid.</returns>
148+
/// <returns>The set of unknown scopes present in the given scopes. The
149+
/// empty set means no scopes were unknown.</returns>
150150
public static ImmutableHashSet<string> Validate(IEnumerable<string> scopes)
151151
{
152152
return scopes.Except(ValidScopes).ToImmutableHashSet();

src/AzureAuth/Commands/Ado/CommandPat.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public class CommandPat
3737
private const string ScopeOption = "--scope";
3838
private const string ScopeHelp = "A token scope for accessing Azure DevOps resources. Repeated invocations allowed.";
3939

40+
private const string AllowCustomScopesFlag = "--allow-custom-scopes";
41+
private const string AllowCustomScopesHelp = "Skip validation and allow custom Azure DevOps PAT scopes.";
42+
4043
private const string OutputOption = "--output";
4144
private const string OutputHelp = "How PAT information is displayed. [default: token]\n[possible values: none, status, token, base64, header, headervalue, json]";
4245

@@ -76,6 +79,9 @@ private enum OutputMode
7679
[Option(ScopeOption, ScopeHelp, CommandOptionType.MultipleValue)]
7780
private IEnumerable<string> RawScopes { get; set; } = null;
7881

82+
[Option(AllowCustomScopesFlag, AllowCustomScopesHelp, CommandOptionType.NoValue)]
83+
private bool AllowCustomScopes { get; set; }
84+
7985
[Option(OutputOption, OutputHelp, CommandOptionType.SingleValue)]
8086
private OutputMode Output { get; set; } = OutputMode.Token;
8187

@@ -167,16 +173,21 @@ private bool ValidOptions(ILogger logger)
167173
logger.LogError($"The {ScopeOption} field is required.");
168174
validOptions = false;
169175
}
176+
else if (AllowCustomScopes)
177+
{
178+
logger.LogWarning($"Skipping scopes validation.");
179+
}
170180
else
171181
{
172-
var invalidScopes = AdoPat.Scopes.Validate(this.Scopes);
173-
if (!invalidScopes.IsEmpty)
182+
var unknownScopes = AdoPat.Scopes.Validate(this.Scopes);
183+
if (!unknownScopes.IsEmpty)
174184
{
175-
foreach (var scope in invalidScopes)
185+
foreach (var scope in unknownScopes)
176186
{
177-
logger.LogError($"{scope} is not a valid Azure DevOps PAT scope.");
187+
logger.LogError($"{scope} is not a known Azure DevOps PAT scope.");
178188
}
179-
logger.LogError($"Consult {AdoPat.Constants.PatListURL} for a list of valid scopes.");
189+
logger.LogError($"Consult {AdoPat.Constants.PatListURL} for a list of known scopes.");
190+
logger.LogError($"Use {AllowCustomScopesFlag} to create a PAT with custom scopes.");
180191
validOptions = false;
181192
}
182193
}

0 commit comments

Comments
 (0)