-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add Phase 2 CLI commands - flows, connections, connection references, deployment settings #227
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
Merged
Merged
feat: Add Phase 2 CLI commands - flows, connections, connection references, deployment settings #227
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
241 changes: 241 additions & 0 deletions
241
src/PPDS.Cli/Commands/ConnectionReferences/AnalyzeCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,241 @@ | ||
| using System.CommandLine; | ||
| using System.Text.Json.Serialization; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using PPDS.Cli.Infrastructure; | ||
| using PPDS.Cli.Infrastructure.Errors; | ||
| using PPDS.Cli.Infrastructure.Output; | ||
| using PPDS.Dataverse.Services; | ||
|
|
||
| namespace PPDS.Cli.Commands.ConnectionReferences; | ||
|
|
||
| /// <summary> | ||
| /// Analyze flow-connection reference relationships and detect orphans. | ||
| /// </summary> | ||
| public static class AnalyzeCommand | ||
| { | ||
| public static Command Create() | ||
| { | ||
| var orphansOnlyOption = new Option<bool>("--orphans-only") | ||
| { | ||
| Description = "Only show orphaned relationships" | ||
| }; | ||
|
|
||
| var command = new Command("analyze", "Analyze flow-connection reference relationships (orphan detection)") | ||
| { | ||
| ConnectionReferencesCommandGroup.SolutionOption, | ||
| orphansOnlyOption, | ||
| ConnectionReferencesCommandGroup.ProfileOption, | ||
| ConnectionReferencesCommandGroup.EnvironmentOption | ||
| }; | ||
|
|
||
| GlobalOptions.AddToCommand(command); | ||
|
|
||
| command.SetAction(async (parseResult, cancellationToken) => | ||
| { | ||
| var solution = parseResult.GetValue(ConnectionReferencesCommandGroup.SolutionOption); | ||
| var orphansOnly = parseResult.GetValue(orphansOnlyOption); | ||
| var profile = parseResult.GetValue(ConnectionReferencesCommandGroup.ProfileOption); | ||
| var environment = parseResult.GetValue(ConnectionReferencesCommandGroup.EnvironmentOption); | ||
| var globalOptions = GlobalOptions.GetValues(parseResult); | ||
|
|
||
| return await ExecuteAsync(solution, orphansOnly, profile, environment, globalOptions, cancellationToken); | ||
| }); | ||
|
|
||
| return command; | ||
| } | ||
|
|
||
| private static async Task<int> ExecuteAsync( | ||
| string? solution, | ||
| bool orphansOnly, | ||
| string? profile, | ||
| string? environment, | ||
| GlobalOptionValues globalOptions, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| var writer = ServiceFactory.CreateOutputWriter(globalOptions); | ||
|
|
||
| try | ||
| { | ||
| await using var serviceProvider = await ProfileServiceFactory.CreateFromProfilesAsync( | ||
| profile, | ||
| environment, | ||
| globalOptions.Verbose, | ||
| globalOptions.Debug, | ||
| ProfileServiceFactory.DefaultDeviceCodeCallback, | ||
| cancellationToken); | ||
|
|
||
| var crService = serviceProvider.GetRequiredService<IConnectionReferenceService>(); | ||
|
|
||
| if (!globalOptions.IsJsonMode) | ||
| { | ||
| var connectionInfo = serviceProvider.GetRequiredService<ResolvedConnectionInfo>(); | ||
| ConsoleHeader.WriteConnectedAs(connectionInfo); | ||
| Console.Error.WriteLine(); | ||
| } | ||
|
|
||
| var analysis = await crService.AnalyzeAsync(solution, cancellationToken); | ||
|
|
||
| var relationships = orphansOnly | ||
| ? analysis.Relationships.Where(r => r.Type != RelationshipType.FlowToConnectionReference).ToList() | ||
| : analysis.Relationships; | ||
|
|
||
| if (globalOptions.IsJsonMode) | ||
| { | ||
| var output = new AnalysisOutput | ||
| { | ||
| Summary = new AnalysisSummary | ||
| { | ||
| ValidCount = analysis.ValidCount, | ||
| OrphanedFlowCount = analysis.OrphanedFlowCount, | ||
| OrphanedConnectionReferenceCount = analysis.OrphanedConnectionReferenceCount, | ||
| HasOrphans = analysis.HasOrphans | ||
| }, | ||
| Relationships = relationships.Select(r => new RelationshipOutput | ||
| { | ||
| Type = r.Type.ToString(), | ||
| FlowUniqueName = r.FlowUniqueName, | ||
| FlowDisplayName = r.FlowDisplayName, | ||
| ConnectionReferenceLogicalName = r.ConnectionReferenceLogicalName, | ||
| ConnectionReferenceDisplayName = r.ConnectionReferenceDisplayName, | ||
| ConnectorId = r.ConnectorId, | ||
| IsBound = r.IsBound | ||
| }).ToList() | ||
| }; | ||
|
|
||
| writer.WriteSuccess(output); | ||
| } | ||
| else | ||
| { | ||
| Console.Error.WriteLine("Flow-Connection Reference Analysis"); | ||
| Console.Error.WriteLine("==================================="); | ||
| Console.Error.WriteLine(); | ||
| Console.Error.WriteLine($" Valid relationships: {analysis.ValidCount}"); | ||
| Console.Error.WriteLine($" Orphaned flows (missing CRs): {analysis.OrphanedFlowCount}"); | ||
| Console.Error.WriteLine($" Orphaned connection references (unused): {analysis.OrphanedConnectionReferenceCount}"); | ||
| Console.Error.WriteLine(); | ||
|
|
||
| if (!analysis.HasOrphans && orphansOnly) | ||
| { | ||
| Console.Error.WriteLine("No orphans detected."); | ||
| return ExitCodes.Success; | ||
| } | ||
|
|
||
| if (relationships.Count == 0) | ||
| { | ||
| Console.Error.WriteLine("No relationships found."); | ||
| return ExitCodes.Success; | ||
| } | ||
|
|
||
| // Group by type for cleaner output | ||
| var orphanedFlows = relationships.Where(r => r.Type == RelationshipType.OrphanedFlow).ToList(); | ||
| var orphanedCRs = relationships.Where(r => r.Type == RelationshipType.OrphanedConnectionReference).ToList(); | ||
| var validRelationships = relationships.Where(r => r.Type == RelationshipType.FlowToConnectionReference).ToList(); | ||
|
|
||
| if (orphanedFlows.Count > 0) | ||
| { | ||
| Console.Error.WriteLine(); | ||
| Console.Error.WriteLine("ORPHANED FLOWS (referencing missing connection references):"); | ||
| Console.Error.WriteLine("------------------------------------------------------------"); | ||
| foreach (var r in orphanedFlows) | ||
| { | ||
| Console.Error.WriteLine($" Flow: {r.FlowDisplayName ?? r.FlowUniqueName}"); | ||
| Console.Error.WriteLine($" References missing CR: {r.ConnectionReferenceLogicalName}"); | ||
| Console.Error.WriteLine(); | ||
| } | ||
| } | ||
|
|
||
| if (orphanedCRs.Count > 0) | ||
| { | ||
| Console.Error.WriteLine(); | ||
| Console.Error.WriteLine("ORPHANED CONNECTION REFERENCES (not used by any flow):"); | ||
| Console.Error.WriteLine("------------------------------------------------------"); | ||
| foreach (var r in orphanedCRs) | ||
| { | ||
| var boundStatus = r.IsBound == true ? "Bound" : "Unbound"; | ||
| Console.Error.WriteLine($" {r.ConnectionReferenceDisplayName ?? r.ConnectionReferenceLogicalName}"); | ||
| Console.Error.WriteLine($" Name: {r.ConnectionReferenceLogicalName} Status: {boundStatus}"); | ||
| if (r.ConnectorId != null) | ||
| { | ||
| Console.Error.WriteLine($" Connector: {r.ConnectorId}"); | ||
| } | ||
| Console.Error.WriteLine(); | ||
| } | ||
| } | ||
|
|
||
| if (!orphansOnly && validRelationships.Count > 0) | ||
| { | ||
| Console.Error.WriteLine(); | ||
| Console.Error.WriteLine("VALID RELATIONSHIPS:"); | ||
| Console.Error.WriteLine("--------------------"); | ||
| foreach (var r in validRelationships) | ||
| { | ||
| var boundStatus = r.IsBound == true ? "Bound" : "Unbound"; | ||
| Console.Error.WriteLine($" Flow: {r.FlowDisplayName ?? r.FlowUniqueName}"); | ||
| Console.Error.WriteLine($" -> CR: {r.ConnectionReferenceLogicalName} ({boundStatus})"); | ||
| Console.Error.WriteLine(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return ExitCodes.Success; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| var error = ExceptionMapper.Map(ex, context: "analyzing connection references", debug: globalOptions.Debug); | ||
| writer.WriteError(error); | ||
| return ExceptionMapper.ToExitCode(ex); | ||
| } | ||
| } | ||
|
|
||
| #region Output Models | ||
|
|
||
| private sealed class AnalysisOutput | ||
| { | ||
| [JsonPropertyName("summary")] | ||
| public AnalysisSummary Summary { get; set; } = new(); | ||
|
|
||
| [JsonPropertyName("relationships")] | ||
| public List<RelationshipOutput> Relationships { get; set; } = new(); | ||
| } | ||
|
|
||
| private sealed class AnalysisSummary | ||
| { | ||
| [JsonPropertyName("validCount")] | ||
| public int ValidCount { get; set; } | ||
|
|
||
| [JsonPropertyName("orphanedFlowCount")] | ||
| public int OrphanedFlowCount { get; set; } | ||
|
|
||
| [JsonPropertyName("orphanedConnectionReferenceCount")] | ||
| public int OrphanedConnectionReferenceCount { get; set; } | ||
|
|
||
| [JsonPropertyName("hasOrphans")] | ||
| public bool HasOrphans { get; set; } | ||
| } | ||
|
|
||
| private sealed class RelationshipOutput | ||
| { | ||
| [JsonPropertyName("type")] | ||
| public string Type { get; set; } = string.Empty; | ||
|
|
||
| [JsonPropertyName("flowUniqueName")] | ||
| public string? FlowUniqueName { get; set; } | ||
|
|
||
| [JsonPropertyName("flowDisplayName")] | ||
| public string? FlowDisplayName { get; set; } | ||
|
|
||
| [JsonPropertyName("connectionReferenceLogicalName")] | ||
| public string? ConnectionReferenceLogicalName { get; set; } | ||
|
|
||
| [JsonPropertyName("connectionReferenceDisplayName")] | ||
| public string? ConnectionReferenceDisplayName { get; set; } | ||
|
|
||
| [JsonPropertyName("connectorId")] | ||
| public string? ConnectorId { get; set; } | ||
|
|
||
| [JsonPropertyName("isBound")] | ||
| public bool? IsBound { get; set; } | ||
| } | ||
|
|
||
| #endregion | ||
| } | ||
43 changes: 43 additions & 0 deletions
43
src/PPDS.Cli/Commands/ConnectionReferences/ConnectionReferencesCommandGroup.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using System.CommandLine; | ||
|
|
||
| namespace PPDS.Cli.Commands.ConnectionReferences; | ||
|
|
||
| /// <summary> | ||
| /// Command group for connection reference operations. | ||
| /// </summary> | ||
| public static class ConnectionReferencesCommandGroup | ||
| { | ||
| /// <summary>Shared profile option.</summary> | ||
| public static readonly Option<string?> ProfileOption = new("--profile", "-p") | ||
| { | ||
| Description = "Authentication profile name" | ||
| }; | ||
|
|
||
| /// <summary>Shared environment option.</summary> | ||
| public static readonly Option<string?> EnvironmentOption = new("--environment", "-e") | ||
| { | ||
| Description = "Environment URL override" | ||
| }; | ||
|
|
||
| /// <summary>Shared solution filter option.</summary> | ||
| public static readonly Option<string?> SolutionOption = new("--solution", "-s") | ||
| { | ||
| Description = "Filter by solution unique name" | ||
| }; | ||
|
|
||
| /// <summary> | ||
| /// Creates the connectionreferences command group. | ||
| /// </summary> | ||
| public static Command Create() | ||
| { | ||
| var command = new Command("connectionreferences", "Manage connection references"); | ||
|
|
||
| command.Subcommands.Add(ListCommand.Create()); | ||
| command.Subcommands.Add(GetCommand.Create()); | ||
| command.Subcommands.Add(FlowsCommand.Create()); | ||
| command.Subcommands.Add(ConnectionsCommand.Create()); | ||
| command.Subcommands.Add(AnalyzeCommand.Create()); | ||
|
|
||
| return command; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.