Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --allow-custom-scopes flag to skip scope validation. #369

Merged
merged 5 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- `--no-validate` flag to skip scope validation for `ado pat`. This allows addition of non-public ADO scopes.

## [0.8.4] - 2023-09-05
### Changed
Expand Down
25 changes: 19 additions & 6 deletions src/AzureAuth/Commands/Ado/CommandPat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class CommandPat
private const string ScopeOption = "--scope";
private const string ScopeHelp = "A token scope for accessing Azure DevOps resources. Repeated invocations allowed.";

private const string NoValidationFlag = "--no-validate";
private const string NoValidationHelp = "Flag to skip scope validation. Allows addition of non-public ADO scopes.";
Haard30 marked this conversation as resolved.
Show resolved Hide resolved

private const string OutputOption = "--output";
private const string OutputHelp = "How PAT information is displayed. [default: token]\n[possible values: none, status, token, base64, header, headervalue, json]";

Expand Down Expand Up @@ -75,6 +78,9 @@ private enum OutputMode
[Option(ScopeOption, ScopeHelp, CommandOptionType.MultipleValue)]
private IEnumerable<string> RawScopes { get; set; } = null;

[Option(NoValidationFlag, NoValidationHelp, CommandOptionType.NoValue)]
private bool NoScopeValidation { get; set; }

[Option(OutputOption, OutputHelp, CommandOptionType.SingleValue)]
private OutputMode Output { get; set; } = OutputMode.Token;

Expand Down Expand Up @@ -168,15 +174,22 @@ private bool ValidOptions(ILogger logger)
}
else
{
var invalidScopes = AdoPat.Scopes.Validate(this.Scopes);
if (!invalidScopes.IsEmpty)
if(NoScopeValidation)
{
logger.LogWarning($"Received {NoValidationFlag} flag. AzureAuth will skip validation of scopes.");
Haard30 marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
foreach (var scope in invalidScopes)
var invalidScopes = AdoPat.Scopes.Validate(this.Scopes);
if (!invalidScopes.IsEmpty)
{
logger.LogError($"{scope} is not a valid Azure DevOps PAT scope.");
foreach (var scope in invalidScopes)
Haard30 marked this conversation as resolved.
Show resolved Hide resolved
{
logger.LogError($"{scope} is not a valid Azure DevOps PAT scope.");
}
logger.LogError($"Consult {AdoPat.Constants.PatListURL} for a list of valid scopes.");
Haard30 marked this conversation as resolved.
Show resolved Hide resolved
validOptions = false;
}
logger.LogError($"Consult {AdoPat.Constants.PatListURL} for a list of valid scopes.");
validOptions = false;
}
}

Expand Down
Loading