diff --git a/src/Confix.Tool/src/Confix.Library/Entities/Component/Providers/Git/GitComponentProvider.cs b/src/Confix.Tool/src/Confix.Library/Entities/Component/Providers/Git/GitComponentProvider.cs index 1c8f5dbf..cd17edf8 100644 --- a/src/Confix.Tool/src/Confix.Library/Entities/Component/Providers/Git/GitComponentProvider.cs +++ b/src/Confix.Tool/src/Confix.Library/Entities/Component/Providers/Git/GitComponentProvider.cs @@ -52,10 +52,10 @@ public async Task ExecuteAsync(IComponentProviderContext context) { var components = context.ComponentReferences.Where(x => x.Provider == _name && x.IsEnabled); - var refs = await FetchRefsAsync(context.CancellationToken); + var refs = await FetchRefsAsync(context); var tasks = components - .Select(x => ProcessComponentAsync(x, refs, context.Logger, context.CancellationToken)) + .Select(x => ProcessComponentAsync(x, refs, context)) .ToArray(); List? errors = null; @@ -82,18 +82,20 @@ public async Task ExecuteAsync(IComponentProviderContext context) } private async Task> FetchRefsAsync( - CancellationToken cancellationToken) + IComponentProviderContext context) { var directory = new DirectoryInfo(Path.Combine(_cloneDirectory.FullName, "__refs")); var refs = new Dictionary(); + + string gitUrl = GitUrl.Create(_repositoryUrl, context.Parameter); var sparseConfig = - new GitSparseCheckoutConfiguration(_repositoryUrl, directory.FullName, _arguments); - await _git.SparseCheckoutAsync(sparseConfig, cancellationToken); + new GitSparseCheckoutConfiguration(gitUrl, directory.FullName, _arguments); + await _git.SparseCheckoutAsync(sparseConfig, context.CancellationToken); var showRefConfig = new GitShowRefsConfiguration(directory.FullName, _arguments); - var refsOutput = await _git.ShowRefsAsync(showRefConfig, cancellationToken); + var refsOutput = await _git.ShowRefsAsync(showRefConfig, context.CancellationToken); foreach (var line in refsOutput.Split('\n')) { @@ -115,8 +117,7 @@ private async Task> FetchRefsAsync( private async Task ProcessComponentAsync( ComponentReferenceDefinition definition, IReadOnlyDictionary refs, - IConsoleLogger logger, - CancellationToken cancellationToken) + IComponentProviderContext context) { var version = definition.Version ?? "latest"; var componentName = definition.ComponentName; @@ -129,13 +130,15 @@ private async Task> FetchRefsAsync( directory.EnsureFolder(); var cloneArgument = _arguments.ToList(); + + string gitUrl = GitUrl.Create(_repositoryUrl, context.Parameter); var cloneConfiguration = new GitCloneConfiguration( - _repositoryUrl, + gitUrl, directory.FullName, cloneArgument.ToArray()); - await _git.CloneAsync(cloneConfiguration, cancellationToken); + await _git.CloneAsync(cloneConfiguration, context.CancellationToken); if (version is not "latest") { @@ -147,7 +150,7 @@ private async Task> FetchRefsAsync( await _git.CheckoutAsync( new GitCheckoutConfiguration(directory.FullName, hash, cloneArgument.ToArray()), - cancellationToken); + context.CancellationToken); } var pathToComponent = Path @@ -159,7 +162,7 @@ await _git.CheckoutAsync( $"Could not find component {componentName} ({version}) in git repository"); } - logger.FoundComponent(componentName, version); + context.Logger.FoundComponent(componentName, version); var json = JsonSchema.FromFile(pathToComponent); var component = diff --git a/src/Confix.Tool/src/Confix.Library/Entities/Component/Providers/Git/GitUrl.cs b/src/Confix.Tool/src/Confix.Library/Entities/Component/Providers/Git/GitUrl.cs new file mode 100644 index 00000000..22cb7bdd --- /dev/null +++ b/src/Confix.Tool/src/Confix.Library/Entities/Component/Providers/Git/GitUrl.cs @@ -0,0 +1,28 @@ +using Confix.Tool.Common.Pipelines; + +namespace Confix.Tool.Entities.Components.Git; + +public static class GitUrl +{ + public static string Create(string repositoryUrl, IParameterCollection parameters) + { + parameters.TryGet(GitUsernameOptions.Instance, out string? username); + parameters.TryGet(GitTokenOptions.Instance, out string? token); + + if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(token)) + { + if (repositoryUrl.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) + { + var uri = new Uri(repositoryUrl); + var builder = new UriBuilder(uri) + { + UserName = username, + Password = token + }; + return builder.Uri.ToString(); + } + } + + return repositoryUrl; + } +} \ No newline at end of file diff --git a/src/Confix.Tool/src/Confix.Library/Middlewares/Project/BuildProjectMiddleware.cs b/src/Confix.Tool/src/Confix.Library/Middlewares/Project/BuildProjectMiddleware.cs index 03f1d10b..3cb5c793 100644 --- a/src/Confix.Tool/src/Confix.Library/Middlewares/Project/BuildProjectMiddleware.cs +++ b/src/Confix.Tool/src/Confix.Library/Middlewares/Project/BuildProjectMiddleware.cs @@ -9,6 +9,10 @@ public sealed class BuildProjectMiddleware : IMiddleware /// public async Task InvokeAsync(IMiddlewareContext context, MiddlewareDelegate next) { + var variableContext = new VariableProviderContext( + context.Parameter, + context.CancellationToken); + context.SetStatus("Building the project files"); var cancellationToken = context.CancellationToken; @@ -32,7 +36,7 @@ public async Task InvokeAsync(IMiddlewareContext context, MiddlewareDelegate nex context.Logger.ReplaceVariablesOfConfigurationFile(file); file.Content = await variableReplacer - .RewriteOrThrowAsync(content, context.CancellationToken); + .RewriteOrThrowAsync(content, variableContext); } await next(context); diff --git a/src/Confix.Tool/src/Confix.Library/Middlewares/Project/RestoreProjectMiddleware.cs b/src/Confix.Tool/src/Confix.Library/Middlewares/Project/RestoreProjectMiddleware.cs index 9e2c6d5d..36af06df 100644 --- a/src/Confix.Tool/src/Confix.Library/Middlewares/Project/RestoreProjectMiddleware.cs +++ b/src/Confix.Tool/src/Confix.Library/Middlewares/Project/RestoreProjectMiddleware.cs @@ -5,6 +5,7 @@ using Confix.Tool.Entities.Components.DotNet; using Confix.Tool.Middlewares.JsonSchemas; using Confix.Tool.Schema; +using Confix.Variables; namespace Confix.Tool.Middlewares.Project; @@ -30,6 +31,10 @@ public async Task InvokeAsync(IMiddlewareContext context, MiddlewareDelegate nex var jsonSchemas = context.Features.Get(); var configuration = context.Features.Get(); var files = context.Features.Get().Files; + + var variableContext = new VariableProviderContext( + context.Parameter, + context.CancellationToken); configuration.EnsureProjectScope(); @@ -42,7 +47,7 @@ public async Task InvokeAsync(IMiddlewareContext context, MiddlewareDelegate nex context.SetStatus("Loading variables..."); var variableResolver = context.Features.Get().Resolver; - var variables = await variableResolver.ListVariables(cancellationToken); + var variables = await variableResolver.ListVariables(variableContext); context.SetStatus("Composing the schema..."); var jsonSchema = _projectComposer.Compose(components, variables); diff --git a/src/Confix.Tool/src/Confix.Library/Options/GitTokenOptions.cs b/src/Confix.Tool/src/Confix.Library/Options/GitTokenOptions.cs new file mode 100644 index 00000000..dd6e54b3 --- /dev/null +++ b/src/Confix.Tool/src/Confix.Library/Options/GitTokenOptions.cs @@ -0,0 +1,15 @@ +using System.CommandLine; + +namespace Confix.Tool; + +internal sealed class GitTokenOptions : Option +{ + public static GitTokenOptions Instance { get; } = new(); + + private GitTokenOptions() + : base("--git-token") + { + Arity = ArgumentArity.ZeroOrOne; + Description = "The token used for git authentication."; + } +} diff --git a/src/Confix.Tool/src/Confix.Library/Options/GitUsernameOptions.cs b/src/Confix.Tool/src/Confix.Library/Options/GitUsernameOptions.cs new file mode 100644 index 00000000..d126a9d8 --- /dev/null +++ b/src/Confix.Tool/src/Confix.Library/Options/GitUsernameOptions.cs @@ -0,0 +1,15 @@ +using System.CommandLine; + +namespace Confix.Tool; + +internal sealed class GitUsernameOptions : Option +{ + public static GitUsernameOptions Instance { get; } = new(); + + private GitUsernameOptions() + : base("--git-username") + { + Arity = ArgumentArity.ZeroOrOne; + Description = "The username used for git authentication."; + } +} diff --git a/src/Confix.Tool/src/Confix.Library/Pipelines/BuildCommandPipeline.cs b/src/Confix.Tool/src/Confix.Library/Pipelines/BuildCommandPipeline.cs index dca1b9ce..25e55fe1 100644 --- a/src/Confix.Tool/src/Confix.Library/Pipelines/BuildCommandPipeline.cs +++ b/src/Confix.Tool/src/Confix.Library/Pipelines/BuildCommandPipeline.cs @@ -17,6 +17,8 @@ protected override void Configure(IPipelineDescriptor builder) .AddOption(ActiveEnvironmentOption.Instance) .AddOption(OutputFileOption.Instance) .AddOption(EncryptionOption.Instance) + .AddOption(GitUsernameOptions.Instance) + .AddOption(GitTokenOptions.Instance) .UseHandler(InvokeAsync); } diff --git a/src/Confix.Tool/src/Confix.Library/Pipelines/Project/ProjectBuildPipeline.cs b/src/Confix.Tool/src/Confix.Library/Pipelines/Project/ProjectBuildPipeline.cs index 573cb9f7..99054abc 100644 --- a/src/Confix.Tool/src/Confix.Library/Pipelines/Project/ProjectBuildPipeline.cs +++ b/src/Confix.Tool/src/Confix.Library/Pipelines/Project/ProjectBuildPipeline.cs @@ -12,6 +12,8 @@ protected override void Configure(IPipelineDescriptor builder) { builder .AddOption(NoRestoreOptions.Instance) + .AddOption(GitUsernameOptions.Instance) + .AddOption(GitTokenOptions.Instance) .Use() .UseReadConfigurationFiles() .UseEnvironment() diff --git a/src/Confix.Tool/src/Confix.Library/Pipelines/Reporting/ProjectReportMiddleware.cs b/src/Confix.Tool/src/Confix.Library/Pipelines/Reporting/ProjectReportMiddleware.cs index 0bc739bb..6de3d1c3 100644 --- a/src/Confix.Tool/src/Confix.Library/Pipelines/Reporting/ProjectReportMiddleware.cs +++ b/src/Confix.Tool/src/Confix.Library/Pipelines/Reporting/ProjectReportMiddleware.cs @@ -9,6 +9,7 @@ using Confix.Tool.Middlewares.Reporting; using Confix.Tool.Schema; using Confix.Utilities; +using Confix.Variables; using Microsoft.Extensions.DependencyInjection; namespace Confix.Tool.Reporting; @@ -215,11 +216,18 @@ private static async Task> GetVariablesAsync( ConfigurationFile file, CancellationToken ct) { + var variableContext = new VariableProviderContext( + context.Parameter, + context.CancellationToken); + var variablesFeature = context.Features.Get(); var variables = new List(); var content = await file.TryLoadContentAsync(ct); - foreach (var variable in await variablesFeature.Extractor.ExtractAsync(content, ct)) + var variableInfos = await variablesFeature.Extractor + .ExtractAsync(content, variableContext); + + foreach (var variable in variableInfos) { var hash = SHA256.HashData(Encoding.UTF8.GetBytes(variable.VariableValue)); diff --git a/src/Confix.Tool/src/Confix.Library/Pipelines/RestoreCommandPipeline.cs b/src/Confix.Tool/src/Confix.Library/Pipelines/RestoreCommandPipeline.cs index 17b4c11a..98ebbb46 100644 --- a/src/Confix.Tool/src/Confix.Library/Pipelines/RestoreCommandPipeline.cs +++ b/src/Confix.Tool/src/Confix.Library/Pipelines/RestoreCommandPipeline.cs @@ -13,6 +13,8 @@ protected override void Configure(IPipelineDescriptor builder) { builder .AddOption(DotnetConfigurationOptions.Instance) + .AddOption(GitUsernameOptions.Instance) + .AddOption(GitTokenOptions.Instance) .Use() .UseEnvironment() .UseHandler(InvokeAsync); diff --git a/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableCopyPipeline.cs b/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableCopyPipeline.cs index 7a53a256..ac29ca80 100644 --- a/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableCopyPipeline.cs +++ b/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableCopyPipeline.cs @@ -23,7 +23,9 @@ protected override void Configure(IPipelineDescriptor builder) private static async Task InvokeAsync(IMiddlewareContext context) { - var cancellationToken = context.CancellationToken; + var variableContext = new VariableProviderContext( + context.Parameter, + context.CancellationToken); var variableFeature = context.Features.Get(); @@ -48,9 +50,9 @@ private static async Task InvokeAsync(IMiddlewareContext context) context.Status.Message = $"Copy variable {fromVariablePath.ToString().AsHighlighted()} to {toVariablePath.ToString().AsHighlighted()}..."; - var fromValue = await fromResolver.ResolveOrThrowAsync(fromVariablePath, cancellationToken); + var fromValue = await fromResolver.ResolveOrThrowAsync(fromVariablePath, variableContext); - var result = await toResolver.SetVariable(toVariablePath, fromValue, cancellationToken); + var result = await toResolver.SetVariable(toVariablePath, fromValue, variableContext); context.Logger.VariableSet(result); } diff --git a/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableGetPipeline.cs b/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableGetPipeline.cs index 05e2277f..e2ef8dda 100644 --- a/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableGetPipeline.cs +++ b/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableGetPipeline.cs @@ -20,6 +20,10 @@ protected override void Configure(IPipelineDescriptor builder) private static async Task InvokeAsync(IMiddlewareContext context) { + var variableContext = new VariableProviderContext( + context.Parameter, + context.CancellationToken); + var resolver = context.Features.Get().Resolver; if (!context.Parameter.TryGet(VariableNameOption.Instance, out string variableName)) @@ -32,7 +36,7 @@ private static async Task InvokeAsync(IMiddlewareContext context) context.Status.Message = $"Resolving variable {variablePath.ToString().AsHighlighted()}..."; var result = await resolver - .ResolveOrThrowAsync(variablePath, context.CancellationToken); + .ResolveOrThrowAsync(variablePath, variableContext); context.Logger.PrintVariableResolved(variablePath, result.ToJsonString()); diff --git a/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableListPipeline.cs b/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableListPipeline.cs index 6eaed6ec..8c02fce8 100644 --- a/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableListPipeline.cs +++ b/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableListPipeline.cs @@ -26,16 +26,20 @@ private static async Task InvokeAsync(IMiddlewareContext context) IEnumerable variables; context.Status.Message = "Fetching Variables..."; + + var variableContext = new VariableProviderContext( + context.Parameter, + context.CancellationToken); if (context.Parameter .TryGet(VariableProviderNameOption.Instance, out string? variableProviderName)) { variables = - await resolver.ListVariables(variableProviderName, context.CancellationToken); + await resolver.ListVariables(variableProviderName, variableContext); } else { - variables = await resolver.ListVariables(context.CancellationToken); + variables = await resolver.ListVariables(variableContext); } context.Logger.PrintVariables(variables); diff --git a/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableSetPipeline.cs b/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableSetPipeline.cs index bcdc3e43..c82d52df 100644 --- a/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableSetPipeline.cs +++ b/src/Confix.Tool/src/Confix.Library/Pipelines/Variable/VariableSetPipeline.cs @@ -25,6 +25,10 @@ private static async Task InvokeAsync(IMiddlewareContext context) { context.Features.Get().EnsureProjectScope(); + var variableContext = new VariableProviderContext( + context.Parameter, + context.CancellationToken); + var resolver = context.Features.Get().Resolver; if (!context.Parameter.TryGet(VariableNameOption.Instance, out string variableName)) { @@ -44,7 +48,7 @@ private static async Task InvokeAsync(IMiddlewareContext context) $"Setting variable {parsed.Value.ToString().AsHighlighted()}..."; var result = await resolver - .SetVariable(parsed.Value, value, context.CancellationToken); + .SetVariable(parsed.Value, value, variableContext); context.Logger.VariableSet(result); } diff --git a/src/Confix.Tool/src/Confix.Library/Utilities/Git/GitService.cs b/src/Confix.Tool/src/Confix.Library/Utilities/Git/GitService.cs index 011f14f9..b95ebdcb 100644 --- a/src/Confix.Tool/src/Confix.Library/Utilities/Git/GitService.cs +++ b/src/Confix.Tool/src/Confix.Library/Utilities/Git/GitService.cs @@ -582,6 +582,7 @@ public static void GitSparseCheckoutOutput(this IConsoleLogger log, string outpu public static void GitSparseCheckoutFailed(this IConsoleLogger log, Exception ex) { + log.LogException(ex); log.Exception("Git sparse checkout failed", ex); } @@ -599,6 +600,7 @@ public static void GitShowRefsOutput(this IConsoleLogger log, string output) public static void GitShowRefsFailed(this IConsoleLogger log, Exception ex) { + log.LogException(ex); log.Exception("Git show refs failed", ex); } @@ -614,6 +616,7 @@ public static void GitCheckoutOutput(this IConsoleLogger log, string output) public static void GitCheckoutFailed(this IConsoleLogger log, Exception ex) { + log.LogException(ex); log.Exception("Git checkout failed", ex); } @@ -629,6 +632,7 @@ public static void GitGetInfoOutput(this IConsoleLogger log, string output) public static void GitGetInfoFailed(this IConsoleLogger log, Exception ex) { + log.LogException(ex); log.Exception("Git get info failed", ex); } @@ -644,6 +648,7 @@ public static void GitGetBranchOutput(this IConsoleLogger log, string output) public static void GitGetBranchFailed(this IConsoleLogger log, Exception ex) { + log.LogException(ex); log.Exception("Git get branch failed", ex); } @@ -659,6 +664,7 @@ public static void GitGetTagOutput(this IConsoleLogger log, string output) public static void GitGetTagFailed(this IConsoleLogger log, Exception ex) { + log.LogException(ex); log.Exception("Git get tag failed", ex); } @@ -674,6 +680,7 @@ public static void GitGetRootOutput(this IConsoleLogger log, string output) public static void GitGetRootFailed(this IConsoleLogger log, Exception ex) { + log.LogException(ex); log.Exception("Git get repository root failed", ex); } @@ -689,6 +696,18 @@ public static void GitGetOriginUrlOutput(this IConsoleLogger log, string output) public static void GitGetOriginUrlFailed(this IConsoleLogger log, Exception ex) { + log.LogException(ex); log.Exception("Git get origin url failed", ex); } + + private static void LogException( + this IConsoleLogger log, + Exception ex) + { + log.Error(ex.Message); + if (ex.InnerException != null) + { + log.Error(ex.InnerException.Message); + } + } } \ No newline at end of file diff --git a/src/Confix.Tool/src/Confix.Library/Variables/IVariableExtractorService.cs b/src/Confix.Tool/src/Confix.Library/Variables/IVariableExtractorService.cs index fd3bc7b9..e4c08db8 100644 --- a/src/Confix.Tool/src/Confix.Library/Variables/IVariableExtractorService.cs +++ b/src/Confix.Tool/src/Confix.Library/Variables/IVariableExtractorService.cs @@ -6,5 +6,5 @@ public interface IVariableExtractorService { Task> ExtractAsync( JsonNode? node, - CancellationToken cancellationToken); + IVariableProviderContext context); } diff --git a/src/Confix.Tool/src/Confix.Library/Variables/IVariableReplacerService.cs b/src/Confix.Tool/src/Confix.Library/Variables/IVariableReplacerService.cs index ec0707f2..ff9a9f9d 100644 --- a/src/Confix.Tool/src/Confix.Library/Variables/IVariableReplacerService.cs +++ b/src/Confix.Tool/src/Confix.Library/Variables/IVariableReplacerService.cs @@ -4,5 +4,5 @@ namespace Confix.Variables; public interface IVariableReplacerService { - Task RewriteAsync(JsonNode? node, CancellationToken cancellationToken); + Task RewriteAsync(JsonNode? node, IVariableProviderContext context); } diff --git a/src/Confix.Tool/src/Confix.Library/Variables/IVariableResolver.cs b/src/Confix.Tool/src/Confix.Library/Variables/IVariableResolver.cs index 5e7a699c..0643d3cc 100644 --- a/src/Confix.Tool/src/Confix.Library/Variables/IVariableResolver.cs +++ b/src/Confix.Tool/src/Confix.Library/Variables/IVariableResolver.cs @@ -7,21 +7,21 @@ public interface IVariableResolver Task SetVariable( VariablePath path, JsonNode value, - CancellationToken cancellationToken); + IVariableProviderContext context); - Task> ListVariables(CancellationToken cancellationToken); + Task> ListVariables(IVariableProviderContext context); Task> ListVariables( string providerName, - CancellationToken cancellationToken); + IVariableProviderContext context); IEnumerable ListProviders(); string GetProviderType(string name); - Task ResolveVariable(VariablePath key, CancellationToken cancellationToken); + Task ResolveVariable(VariablePath key, IVariableProviderContext context); Task> ResolveVariables( IReadOnlyList keys, - CancellationToken cancellationToken); + IVariableProviderContext context); } diff --git a/src/Confix.Tool/src/Confix.Library/Variables/Providers/AzureKeyVault/AzureKeyVaultProvider.cs b/src/Confix.Tool/src/Confix.Library/Variables/Providers/AzureKeyVault/AzureKeyVaultProvider.cs index a864ff25..fe310200 100644 --- a/src/Confix.Tool/src/Confix.Library/Variables/Providers/AzureKeyVault/AzureKeyVaultProvider.cs +++ b/src/Confix.Tool/src/Confix.Library/Variables/Providers/AzureKeyVault/AzureKeyVaultProvider.cs @@ -34,13 +34,13 @@ public AzureKeyVaultProvider(SecretClient client) /// public static string Type => "azure-keyvault"; - public Task> ListAsync(CancellationToken cancellationToken) + public Task> ListAsync(IVariableProviderContext context) => KeyVaultExtension.HandleKeyVaultException>(async () => { App.Log.ListSecrets(_client.VaultUri); var secrets = new List(); - await foreach (var secret in _client.GetPropertiesOfSecretsAsync(cancellationToken)) + await foreach (var secret in _client.GetPropertiesOfSecretsAsync(context.CancellationToken)) { secrets.Add(secret.Name.ToConfixPath()); } @@ -48,20 +48,20 @@ public Task> ListAsync(CancellationToken cancellationToken return secrets; }); - public Task ResolveAsync(string path, CancellationToken cancellationToken) + public Task ResolveAsync(string path, IVariableProviderContext context) => KeyVaultExtension.HandleKeyVaultException(async () => { KeyVaultSecret result = await _client.GetSecretAsync(path.ToKeyVaultCompatiblePath(), - cancellationToken: cancellationToken); + cancellationToken: context.CancellationToken); return JsonValue.Create(result.Value)!; }, path); public Task> ResolveManyAsync( IReadOnlyList paths, - CancellationToken cancellationToken) - => paths.ResolveMany(ResolveAsync, cancellationToken); + IVariableProviderContext context) + => paths.ResolveMany(ResolveAsync, context); - public Task SetAsync(string path, JsonNode value, CancellationToken ct) + public Task SetAsync(string path, JsonNode value, IVariableProviderContext context) => KeyVaultExtension.HandleKeyVaultException(async () => { if (value.GetSchemaValueType() != SchemaValueType.String) @@ -70,7 +70,7 @@ public Task SetAsync(string path, JsonNode value, CancellationToken ct) } KeyVaultSecret result = await _client - .SetSecretAsync(path.ToKeyVaultCompatiblePath(), (string)value!, ct); + .SetSecretAsync(path.ToKeyVaultCompatiblePath(), (string)value!, context.CancellationToken); return result.Name.ToConfixPath(); }, path); diff --git a/src/Confix.Tool/src/Confix.Library/Variables/Providers/Git/GitVariableProvider.cs b/src/Confix.Tool/src/Confix.Library/Variables/Providers/Git/GitVariableProvider.cs index 68c172f5..c1d76da5 100644 --- a/src/Confix.Tool/src/Confix.Library/Variables/Providers/Git/GitVariableProvider.cs +++ b/src/Confix.Tool/src/Confix.Library/Variables/Providers/Git/GitVariableProvider.cs @@ -1,5 +1,7 @@ using System.Text.Json.Nodes; using Confix.Tool; +using Confix.Tool.Common.Pipelines; +using Confix.Tool.Entities.Components.Git; using Confix.Utilities; namespace Confix.Variables; @@ -40,39 +42,41 @@ public GitVariableProvider( public static string Type => "git"; - public async Task> ListAsync(CancellationToken cancellationToken) + public async Task> ListAsync(IVariableProviderContext context) { - await EnsureClonedAsync(true, cancellationToken); - return await _localVariableProvider.ListAsync(cancellationToken); + await EnsureClonedAsync(true, context); + return await _localVariableProvider.ListAsync(context); } - public async Task ResolveAsync(string path, CancellationToken cancellationToken) + public async Task ResolveAsync(string path, IVariableProviderContext context) { - await EnsureClonedAsync(true, cancellationToken); - return await _localVariableProvider.ResolveAsync(path, cancellationToken); + await EnsureClonedAsync(true, context); + return await _localVariableProvider.ResolveAsync(path, context); } public async Task> ResolveManyAsync( IReadOnlyList paths, - CancellationToken cancellationToken) + IVariableProviderContext context) { - await EnsureClonedAsync(true, cancellationToken); - return await _localVariableProvider.ResolveManyAsync(paths, cancellationToken); + await EnsureClonedAsync(true, context); + return await _localVariableProvider.ResolveManyAsync(paths, context); } public async Task SetAsync( string path, JsonNode value, - CancellationToken ct) + IVariableProviderContext context) { - await EnsureClonedAsync(true, ct); - var result = await _localVariableProvider.SetAsync(path, value, ct); + await EnsureClonedAsync(true, context); + var result = await _localVariableProvider.SetAsync(path, value, context); + + var ct = context.CancellationToken; await _git.AddAsync(new GitAddConfiguration(_cloneDirectory, _definition.Arguments), ct); var commitMessage = $"Update {path} in {_definition.FilePath}"; await _git.CommitAsync( - new GitCommitConfiguration(_cloneDirectory, commitMessage, _definition.Arguments), + new GitCommitConfiguration(_cloneDirectory, commitMessage, _definition.Arguments), ct); await _git.PushAsync(new GitPushConfiguration(_cloneDirectory, _definition.Arguments), ct); @@ -108,8 +112,9 @@ private static void DeleteFile(string file) File.Delete(file); } - private async Task EnsureClonedAsync(bool forcePull, CancellationToken ct) + private async Task EnsureClonedAsync(bool forcePull, IVariableProviderContext context) { + var ct = context.CancellationToken; if (Directory.Exists(_cloneDirectory)) { if (!forcePull) @@ -121,8 +126,10 @@ private async Task EnsureClonedAsync(bool forcePull, CancellationToken ct) } else { + var gitUrl = GitUrl.Create(_definition.RepositoryUrl, context.Parameters); + GitCloneConfiguration configuration = - new(_definition.RepositoryUrl, _cloneDirectory, _definition.Arguments); + new(gitUrl, _cloneDirectory, _definition.Arguments); await _git.CloneAsync(configuration, ct); } diff --git a/src/Confix.Tool/src/Confix.Library/Variables/Providers/IVariableProvider.cs b/src/Confix.Tool/src/Confix.Library/Variables/Providers/IVariableProvider.cs index 068ec8d7..445579cb 100644 --- a/src/Confix.Tool/src/Confix.Library/Variables/Providers/IVariableProvider.cs +++ b/src/Confix.Tool/src/Confix.Library/Variables/Providers/IVariableProvider.cs @@ -9,28 +9,22 @@ public interface IVariableProvider : IAsyncDisposable /// /// Gets all available variables /// - /// The cancellation token. /// A list of variable paths available on this provider - Task> ListAsync(CancellationToken cancellationToken); + Task> ListAsync(IVariableProviderContext context); /// /// Gets the value of the variable at the given path. /// - /// The path to the variable. - /// The cancellation token. /// The value of the variable. - Task ResolveAsync(string path, CancellationToken cancellationToken); + Task ResolveAsync(string path, IVariableProviderContext context); Task> ResolveManyAsync( IReadOnlyList paths, - CancellationToken cancellationToken); + IVariableProviderContext context); /// /// Sets the value of the variable at the given path. /// - /// The path to the variable. - /// The value to set. - /// The cancellation token. /// The path of the variable. - Task SetAsync(string path, JsonNode value, CancellationToken ct); + Task SetAsync(string path, JsonNode value, IVariableProviderContext context); } diff --git a/src/Confix.Tool/src/Confix.Library/Variables/Providers/IVariableProviderContext.cs b/src/Confix.Tool/src/Confix.Library/Variables/Providers/IVariableProviderContext.cs new file mode 100644 index 00000000..390d2096 --- /dev/null +++ b/src/Confix.Tool/src/Confix.Library/Variables/Providers/IVariableProviderContext.cs @@ -0,0 +1,16 @@ +using Confix.Tool.Common.Pipelines; + +namespace Confix.Variables; + +public interface IVariableProviderContext +{ + /// + /// The parameter collection. + /// + IParameterCollection Parameters { get; } + + /// + /// The cancellation token. + /// + CancellationToken CancellationToken { get; } +} \ No newline at end of file diff --git a/src/Confix.Tool/src/Confix.Library/Variables/Providers/Local/LocalVariableProvider.cs b/src/Confix.Tool/src/Confix.Library/Variables/Providers/Local/LocalVariableProvider.cs index 7050e7fd..f0200cce 100644 --- a/src/Confix.Tool/src/Confix.Library/Variables/Providers/Local/LocalVariableProvider.cs +++ b/src/Confix.Tool/src/Confix.Library/Variables/Providers/Local/LocalVariableProvider.cs @@ -2,6 +2,7 @@ using System.Text.Json.Nodes; using Confix.Tool; using Confix.Tool.Commands.Logging; +using Confix.Tool.Common.Pipelines; using Confix.Tool.Schema; using Confix.Utilities.Json; using HotChocolate.Types; @@ -37,10 +38,10 @@ public LocalVariableProvider(LocalVariableProviderDefinition definition) public static string Type => "local"; - public Task> ListAsync(CancellationToken cancellationToken) + public Task> ListAsync(IVariableProviderContext context) => Task.FromResult>(_parsedLocalFile.Value.Keys.ToArray()); - public Task ResolveAsync(string path, CancellationToken cancellationToken) + public Task ResolveAsync(string path, IVariableProviderContext context) { EnsureConfigFile(); @@ -54,10 +55,10 @@ public Task ResolveAsync(string path, CancellationToken cancellationTo public Task> ResolveManyAsync( IReadOnlyList paths, - CancellationToken cancellationToken) - => paths.ResolveMany(ResolveAsync, cancellationToken); + IVariableProviderContext context) + => paths.ResolveMany(ResolveAsync, context); - public Task SetAsync(string path, JsonNode value, CancellationToken ct) + public Task SetAsync(string path, JsonNode value, IVariableProviderContext context) { EnsureConfigFile(); diff --git a/src/Confix.Tool/src/Confix.Library/Variables/Providers/Secret/SecretVariableProvider.cs b/src/Confix.Tool/src/Confix.Library/Variables/Providers/Secret/SecretVariableProvider.cs index 192f5e59..8f5439cb 100644 --- a/src/Confix.Tool/src/Confix.Library/Variables/Providers/Secret/SecretVariableProvider.cs +++ b/src/Confix.Tool/src/Confix.Library/Variables/Providers/Secret/SecretVariableProvider.cs @@ -28,10 +28,10 @@ public SecretVariableProvider(SecretVariableProviderDefinition definition) public static string Type => "secret"; - public Task> ListAsync(CancellationToken cancellationToken) + public Task> ListAsync(IVariableProviderContext context) => Task.FromResult>(Array.Empty()); - public Task ResolveAsync(string path, CancellationToken cancellationToken) + public Task ResolveAsync(string path, IVariableProviderContext context) { byte[] valueToDecrypt = Convert.FromBase64String(path); byte[] encryptedValue = Decrypt(valueToDecrypt, _privateKey.Value); @@ -42,10 +42,10 @@ public Task ResolveAsync(string path, CancellationToken cancellationTo public Task> ResolveManyAsync( IReadOnlyList paths, - CancellationToken cancellationToken) - => paths.ResolveMany(ResolveAsync, cancellationToken); + IVariableProviderContext context) + => paths.ResolveMany(ResolveAsync, context); - public Task SetAsync(string path, JsonNode value, CancellationToken ct) + public Task SetAsync(string path, JsonNode value, IVariableProviderContext context) { string valueToEncrypt = value.ToJsonString(); byte[] bytesToEncrypt = Encoding.UTF8.GetBytes(valueToEncrypt); diff --git a/src/Confix.Tool/src/Confix.Library/Variables/Providers/VariableProviderContext.cs b/src/Confix.Tool/src/Confix.Library/Variables/Providers/VariableProviderContext.cs new file mode 100644 index 00000000..5eeebaff --- /dev/null +++ b/src/Confix.Tool/src/Confix.Library/Variables/Providers/VariableProviderContext.cs @@ -0,0 +1,17 @@ +using Confix.Tool.Common.Pipelines; + +namespace Confix.Variables; + +public class VariableProviderContext : IVariableProviderContext +{ + public VariableProviderContext( + IParameterCollection parameters, + CancellationToken cancellationToken) + { + Parameters = parameters; + CancellationToken = cancellationToken; + } + + public IParameterCollection Parameters { get; } + public CancellationToken CancellationToken { get; } +} \ No newline at end of file diff --git a/src/Confix.Tool/src/Confix.Library/Variables/Providers/VariableProviderExtensions.cs b/src/Confix.Tool/src/Confix.Library/Variables/Providers/VariableProviderExtensions.cs index fdd3f7cc..4146cfb0 100644 --- a/src/Confix.Tool/src/Confix.Library/Variables/Providers/VariableProviderExtensions.cs +++ b/src/Confix.Tool/src/Confix.Library/Variables/Providers/VariableProviderExtensions.cs @@ -7,15 +7,15 @@ internal static class VariableProviderExtensions { public static async Task> ResolveMany( this IEnumerable paths, - Func> resolveAsync, - CancellationToken cancellationToken) + Func> resolveAsync, + IVariableProviderContext context) { var errors = new ConcurrentQueue(); var resolvedVariables = new ConcurrentDictionary(); - var parallelOptions = new ParallelOptions { CancellationToken = cancellationToken }; + var parallelOptions = new ParallelOptions { CancellationToken = context.CancellationToken }; - async ValueTask ForEachAsync(string path, CancellationToken ctx) + async ValueTask ForEachAsync(string path, IVariableProviderContext ctx) { try { @@ -28,7 +28,7 @@ async ValueTask ForEachAsync(string path, CancellationToken ctx) } } - await Parallel.ForEachAsync(paths, parallelOptions, ForEachAsync); + await Parallel.ForEachAsync(paths, parallelOptions, (path, _) => ForEachAsync(path, context)); if (!errors.IsEmpty) { diff --git a/src/Confix.Tool/src/Confix.Library/Variables/VariableExtractorService.cs b/src/Confix.Tool/src/Confix.Library/Variables/VariableExtractorService.cs index 1553b089..bede9c11 100644 --- a/src/Confix.Tool/src/Confix.Library/Variables/VariableExtractorService.cs +++ b/src/Confix.Tool/src/Confix.Library/Variables/VariableExtractorService.cs @@ -1,7 +1,6 @@ using System.Text.Json.Nodes; using Confix.Tool.Commands.Logging; using Json.More; -using Json.Pointer; using Json.Schema; namespace Confix.Variables; @@ -18,7 +17,7 @@ public VariableExtractorService(IVariableResolver variableResolver) public async Task> ExtractAsync( JsonNode? node, - CancellationToken cancellationToken) + IVariableProviderContext context) { if (node is null) { @@ -30,7 +29,7 @@ public async Task> ExtractAsync( App.Log.DetectedVariables(variables.Length); var resolved = await _variableResolver - .ResolveVariables(variables.Select(x => x.Path).ToArray(), cancellationToken); + .ResolveVariables(variables.Select(x => x.Path).ToArray(), context); var infos = new List(); diff --git a/src/Confix.Tool/src/Confix.Library/Variables/VariableReplacerService.cs b/src/Confix.Tool/src/Confix.Library/Variables/VariableReplacerService.cs index f43af826..96496744 100644 --- a/src/Confix.Tool/src/Confix.Library/Variables/VariableReplacerService.cs +++ b/src/Confix.Tool/src/Confix.Library/Variables/VariableReplacerService.cs @@ -14,22 +14,22 @@ public VariableReplacerService(IVariableResolver variableResolver) _variableResolver = variableResolver; } - public async Task RewriteAsync(JsonNode? node, CancellationToken cancellationToken) + public async Task RewriteAsync(JsonNode? node, IVariableProviderContext context) { if (node is null) { return null; } - return await RewriteAsync(node, ImmutableHashSet.Empty, cancellationToken); + return await RewriteAsync(node, ImmutableHashSet.Empty, context); } private async Task RewriteAsync( JsonNode node, IReadOnlySet resolvedPaths, - CancellationToken cancellationToken) + IVariableProviderContext context) { - var resolvedVariables = await ResolveVariables(node, resolvedPaths, cancellationToken); + var resolvedVariables = await ResolveVariables(node, resolvedPaths, context); return new JsonVariableRewriter().Rewrite(node, new(resolvedVariables)); } @@ -51,7 +51,7 @@ private static IEnumerable GetVariables(JsonNode node) private async Task> ResolveVariables( JsonNode node, IReadOnlySet resolvedPaths, - CancellationToken cancellationToken) + IVariableProviderContext context) { var variables = GetVariables(node).ToArray(); if (variables.Length == 0) @@ -64,7 +64,7 @@ private async Task> ResolveVariables throw new CircularVariableReferenceException(variables.First(v => resolvedPaths.Contains(v))); } - var resolvedVariables = await _variableResolver.ResolveVariables(variables, cancellationToken); + var resolvedVariables = await _variableResolver.ResolveVariables(variables, context); var resolved = new Dictionary(); foreach (var variable in resolvedVariables) @@ -74,7 +74,7 @@ private async Task> ResolveVariables resolved[variable.Key] = await RewriteAsync( variable.Value, currentPath, - cancellationToken); + context); } return resolved; diff --git a/src/Confix.Tool/src/Confix.Library/Variables/VariableResolver.cs b/src/Confix.Tool/src/Confix.Library/Variables/VariableResolver.cs index 8c024bec..06bd7c10 100644 --- a/src/Confix.Tool/src/Confix.Library/Variables/VariableResolver.cs +++ b/src/Confix.Tool/src/Confix.Library/Variables/VariableResolver.cs @@ -1,4 +1,3 @@ -using System.Reactive.Linq; using System.Text.Json.Nodes; using Confix.Tool; using Confix.Tool.Commands.Logging; @@ -25,29 +24,29 @@ public VariableResolver( public async Task SetVariable( VariablePath path, JsonNode value, - CancellationToken cancellationToken) + IVariableProviderContext context) { var configuration = GetProviderConfiguration(path.ProviderName); await using var provider = _variableProviderFactory.CreateProvider(configuration); - await provider.SetAsync(path.Path, value, cancellationToken); + await provider.SetAsync(path.Path, value, context); return path; } - public async Task> ListVariables(CancellationToken cancellationToken) + public async Task> ListVariables(IVariableProviderContext context) { var variables = await _configurations - .Select(c => ListVariables(c.Name, cancellationToken)) - .ToListAsync(cancellationToken); + .Select(c => ListVariables(c.Name, context)) + .ToListAsync(context.CancellationToken); return variables.SelectMany(v => v); } public async Task> ListVariables( string providerName, - CancellationToken cancellationToken) + IVariableProviderContext context) { var configuration = GetProviderConfiguration(providerName); @@ -57,7 +56,7 @@ public async Task> ListVariables( } await using var provider = _variableProviderFactory.CreateProvider(configuration); - var variableKeys = await provider.ListAsync(cancellationToken); + var variableKeys = await provider.ListAsync(context); var items = variableKeys.Select(k => new VariablePath(providerName, k)).ToArray(); _variableListCache.TryAdd(configuration, items); @@ -78,18 +77,18 @@ public string GetProviderType(string name) public async Task ResolveVariable( VariablePath key, - CancellationToken cancellationToken) + IVariableProviderContext context) { App.Log.ResolvingVariable(key); var configuration = GetProviderConfiguration(key.ProviderName); await using var provider = _variableProviderFactory.CreateProvider(configuration); - return await provider.ResolveAsync(key.Path, cancellationToken); + return await provider.ResolveAsync(key.Path, context); } public async Task> ResolveVariables( IReadOnlyList keys, - CancellationToken cancellationToken) + IVariableProviderContext context) { List> resolvedVariables = new(keys.Count); @@ -97,7 +96,7 @@ public async Task> ResolveVariables( { var paths = group.Select(k => k.Path).Distinct().ToList(); - var providerResults = await ResolveVariables(group.Key, paths, cancellationToken); + var providerResults = await ResolveVariables(group.Key, paths, context); resolvedVariables.AddRange(providerResults); } @@ -108,7 +107,7 @@ public async Task> ResolveVariables( private async Task> ResolveVariables( string providerName, IReadOnlyList paths, - CancellationToken cancellationToken) + IVariableProviderContext context) { App.Log.ResolvingVariables(providerName, paths.Count); var resolvedVariables = new Dictionary(); @@ -116,7 +115,7 @@ private async Task> ResolveVariables var providerConfiguration = GetProviderConfiguration(providerName); await using var provider = _variableProviderFactory.CreateProvider(providerConfiguration); - var resolvedValues = await provider.ResolveManyAsync(paths, cancellationToken); + var resolvedValues = await provider.ResolveManyAsync(paths, context); foreach (var (key, value) in resolvedValues) { resolvedVariables.Add(new(providerName, key), value); diff --git a/src/Confix.Tool/src/Confix.Library/Variables/VariableResolverExtensions.cs b/src/Confix.Tool/src/Confix.Library/Variables/VariableResolverExtensions.cs index dc211e88..74707fd0 100644 --- a/src/Confix.Tool/src/Confix.Library/Variables/VariableResolverExtensions.cs +++ b/src/Confix.Tool/src/Confix.Library/Variables/VariableResolverExtensions.cs @@ -8,11 +8,11 @@ public static class VariableResolverExtensions public static async Task ResolveOrThrowAsync( this IVariableResolver resolver, VariablePath path, - CancellationToken cancellationToken) + IVariableProviderContext context) { try { - return await resolver.ResolveVariable(path, cancellationToken); + return await resolver.ResolveVariable(path, context); } catch (AggregateException ex) { @@ -37,11 +37,11 @@ public static async Task ResolveOrThrowAsync( public static async Task RewriteOrThrowAsync( this IVariableReplacerService service, JsonNode? node, - CancellationToken cancellationToken) + IVariableProviderContext context) { try { - return await service.RewriteAsync(node, cancellationToken); + return await service.RewriteAsync(node, context); } catch (AggregateException ex) { diff --git a/src/Confix.Tool/src/Confix.Nuke/Confix.Tool.Generated.cs b/src/Confix.Tool/src/Confix.Nuke/Confix.Tool.Generated.cs index 93c7301b..6321c847 100644 --- a/src/Confix.Tool/src/Confix.Nuke/Confix.Tool.Generated.cs +++ b/src/Confix.Tool/src/Confix.Nuke/Confix.Tool.Generated.cs @@ -71,13 +71,13 @@ public partial class ConfixTasks : ToolTasks ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --environment via
  • --only-components via
  • --output-file via
  • --verbosity via
public static IEnumerable<(ConfixProjectRestoreSettings Settings, IReadOnlyCollection Output)> ConfixProjectRestore(CombinatorialConfigure configurator, int degreeOfParallelism = 1, bool completeOnFailure = false) => configurator.Invoke(ConfixProjectRestore, degreeOfParallelism, completeOnFailure); ///

Replaces all variables in the project files with their values

For more details, visit the official website.

- ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --encrypt via
  • --environment via
  • --no-restore via
  • --only-components via
  • --output-file via
  • --verbosity via
+ ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --encrypt via
  • --environment via
  • --git-token via
  • --git-username via
  • --no-restore via
  • --only-components via
  • --output-file via
  • --verbosity via
public static IReadOnlyCollection ConfixProjectBuild(ConfixProjectBuildSettings options = null) => new ConfixTasks().Run(options); ///

Replaces all variables in the project files with their values

For more details, visit the official website.

- ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --encrypt via
  • --environment via
  • --no-restore via
  • --only-components via
  • --output-file via
  • --verbosity via
+ ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --encrypt via
  • --environment via
  • --git-token via
  • --git-username via
  • --no-restore via
  • --only-components via
  • --output-file via
  • --verbosity via
public static IReadOnlyCollection ConfixProjectBuild(Configure configurator) => new ConfixTasks().Run(configurator.Invoke(new ConfixProjectBuildSettings())); ///

Replaces all variables in the project files with their values

For more details, visit the official website.

- ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --encrypt via
  • --environment via
  • --no-restore via
  • --only-components via
  • --output-file via
  • --verbosity via
+ ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --encrypt via
  • --environment via
  • --git-token via
  • --git-username via
  • --no-restore via
  • --only-components via
  • --output-file via
  • --verbosity via
public static IEnumerable<(ConfixProjectBuildSettings Settings, IReadOnlyCollection Output)> ConfixProjectBuild(CombinatorialConfigure configurator, int degreeOfParallelism = 1, bool completeOnFailure = false) => configurator.Invoke(ConfixProjectBuild, degreeOfParallelism, completeOnFailure); ///

Initializes a project and creates a project file

For more details, visit the official website.

///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --output-file via
  • --verbosity via
@@ -179,22 +179,22 @@ public partial class ConfixTasks : ToolTasks ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --environment via
  • --from via
  • --to via
  • --to-environment via
  • --verbosity via
public static IEnumerable<(ConfixVariableCopySettings Settings, IReadOnlyCollection Output)> ConfixVariableCopy(CombinatorialConfigure configurator, int degreeOfParallelism = 1, bool completeOnFailure = false) => configurator.Invoke(ConfixVariableCopy, degreeOfParallelism, completeOnFailure); ///

For more details, visit the official website.

- ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --encrypt via
  • --environment via
  • --output-file via
  • --verbosity via
+ ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --encrypt via
  • --environment via
  • --git-token via
  • --git-username via
  • --output-file via
  • --verbosity via
public static IReadOnlyCollection ConfixBuild(ConfixBuildSettings options = null) => new ConfixTasks().Run(options); ///

For more details, visit the official website.

- ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --encrypt via
  • --environment via
  • --output-file via
  • --verbosity via
+ ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --encrypt via
  • --environment via
  • --git-token via
  • --git-username via
  • --output-file via
  • --verbosity via
public static IReadOnlyCollection ConfixBuild(Configure configurator) => new ConfixTasks().Run(configurator.Invoke(new ConfixBuildSettings())); ///

For more details, visit the official website.

- ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --encrypt via
  • --environment via
  • --output-file via
  • --verbosity via
+ ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --encrypt via
  • --environment via
  • --git-token via
  • --git-username via
  • --output-file via
  • --verbosity via
public static IEnumerable<(ConfixBuildSettings Settings, IReadOnlyCollection Output)> ConfixBuild(CombinatorialConfigure configurator, int degreeOfParallelism = 1, bool completeOnFailure = false) => configurator.Invoke(ConfixBuild, degreeOfParallelism, completeOnFailure); ///

For more details, visit the official website.

- ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --dotnet-configuration via
  • --environment via
  • --verbosity via
+ ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --dotnet-configuration via
  • --environment via
  • --git-token via
  • --git-username via
  • --verbosity via
public static IReadOnlyCollection ConfixRestore(ConfixRestoreSettings options = null) => new ConfixTasks().Run(options); ///

For more details, visit the official website.

- ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --dotnet-configuration via
  • --environment via
  • --verbosity via
+ ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --dotnet-configuration via
  • --environment via
  • --git-token via
  • --git-username via
  • --verbosity via
public static IReadOnlyCollection ConfixRestore(Configure configurator) => new ConfixTasks().Run(configurator.Invoke(new ConfixRestoreSettings())); ///

For more details, visit the official website.

- ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --dotnet-configuration via
  • --environment via
  • --verbosity via
+ ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --dotnet-configuration via
  • --environment via
  • --git-token via
  • --git-username via
  • --verbosity via
public static IEnumerable<(ConfixRestoreSettings Settings, IReadOnlyCollection Output)> ConfixRestore(CombinatorialConfigure configurator, int degreeOfParallelism = 1, bool completeOnFailure = false) => configurator.Invoke(ConfixRestore, degreeOfParallelism, completeOnFailure); ///

Validates the schema of all the projects

For more details, visit the official website.

///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --environment via
  • --verbosity via
@@ -347,6 +347,10 @@ public partial class ConfixProjectBuildSettings : ToolOptions { /// Disables restoring of schemas [Argument(Format = "--no-restore {value}")] public string NoRestore => Get(() => NoRestore); + /// The username used for git authentication. + [Argument(Format = "--git-username {value}")] public string GitUsername => Get(() => GitUsername); + /// The token used for git authentication. + [Argument(Format = "--git-token {value}")] public string GitToken => Get(() => GitToken); /// Specifies the output file [Argument(Format = "--output-file {value}")] public string OutputFile => Get(() => OutputFile); /// The name of the environment to run the command in. Overrules the active environment set in .confixrc @@ -557,6 +561,10 @@ public partial class ConfixBuildSettings : ToolOptions [Argument(Format = "--output-file {value}")] public string OutputFile => Get(() => OutputFile); /// Encrypt the output file [Argument(Format = "--encrypt {value}")] public string Encrypt => Get(() => Encrypt); + /// The username used for git authentication. + [Argument(Format = "--git-username {value}")] public string GitUsername => Get(() => GitUsername); + /// The token used for git authentication. + [Argument(Format = "--git-token {value}")] public string GitToken => Get(() => GitToken); /// Sets the verbosity level [Argument(Format = "--verbosity {value}")] public string Verbosity => Get(() => Verbosity); /// @@ -572,6 +580,10 @@ public partial class ConfixRestoreSettings : ToolOptions { /// The configuration passed to dotnet commands. Defaults to 'Debug'. [Argument(Format = "--dotnet-configuration {value}")] public string DotnetConfiguration => Get(() => DotnetConfiguration); + /// The username used for git authentication. + [Argument(Format = "--git-username {value}")] public string GitUsername => Get(() => GitUsername); + /// The token used for git authentication. + [Argument(Format = "--git-token {value}")] public string GitToken => Get(() => GitToken); /// The name of the environment to run the command in. Overrules the active environment set in .confixrc [Argument(Format = "--environment {value}")] public string Environment => Get(() => Environment); /// Sets the verbosity level @@ -902,6 +914,22 @@ [Pure] [Builder(Type = typeof(ConfixProjectBuildSettings), Property = nameof(Con [Pure] [Builder(Type = typeof(ConfixProjectBuildSettings), Property = nameof(ConfixProjectBuildSettings.NoRestore))] public static T ResetNoRestore(this T o) where T : ConfixProjectBuildSettings => o.Modify(b => b.Remove(() => o.NoRestore)); #endregion + #region GitUsername + /// + [Pure] [Builder(Type = typeof(ConfixProjectBuildSettings), Property = nameof(ConfixProjectBuildSettings.GitUsername))] + public static T SetGitUsername(this T o, string v) where T : ConfixProjectBuildSettings => o.Modify(b => b.Set(() => o.GitUsername, v)); + /// + [Pure] [Builder(Type = typeof(ConfixProjectBuildSettings), Property = nameof(ConfixProjectBuildSettings.GitUsername))] + public static T ResetGitUsername(this T o) where T : ConfixProjectBuildSettings => o.Modify(b => b.Remove(() => o.GitUsername)); + #endregion + #region GitToken + /// + [Pure] [Builder(Type = typeof(ConfixProjectBuildSettings), Property = nameof(ConfixProjectBuildSettings.GitToken))] + public static T SetGitToken(this T o, string v) where T : ConfixProjectBuildSettings => o.Modify(b => b.Set(() => o.GitToken, v)); + /// + [Pure] [Builder(Type = typeof(ConfixProjectBuildSettings), Property = nameof(ConfixProjectBuildSettings.GitToken))] + public static T ResetGitToken(this T o) where T : ConfixProjectBuildSettings => o.Modify(b => b.Remove(() => o.GitToken)); + #endregion #region OutputFile /// [Pure] [Builder(Type = typeof(ConfixProjectBuildSettings), Property = nameof(ConfixProjectBuildSettings.OutputFile))] @@ -1406,6 +1434,22 @@ [Pure] [Builder(Type = typeof(ConfixBuildSettings), Property = nameof(ConfixBuil [Pure] [Builder(Type = typeof(ConfixBuildSettings), Property = nameof(ConfixBuildSettings.Encrypt))] public static T ResetEncrypt(this T o) where T : ConfixBuildSettings => o.Modify(b => b.Remove(() => o.Encrypt)); #endregion + #region GitUsername + /// + [Pure] [Builder(Type = typeof(ConfixBuildSettings), Property = nameof(ConfixBuildSettings.GitUsername))] + public static T SetGitUsername(this T o, string v) where T : ConfixBuildSettings => o.Modify(b => b.Set(() => o.GitUsername, v)); + /// + [Pure] [Builder(Type = typeof(ConfixBuildSettings), Property = nameof(ConfixBuildSettings.GitUsername))] + public static T ResetGitUsername(this T o) where T : ConfixBuildSettings => o.Modify(b => b.Remove(() => o.GitUsername)); + #endregion + #region GitToken + /// + [Pure] [Builder(Type = typeof(ConfixBuildSettings), Property = nameof(ConfixBuildSettings.GitToken))] + public static T SetGitToken(this T o, string v) where T : ConfixBuildSettings => o.Modify(b => b.Set(() => o.GitToken, v)); + /// + [Pure] [Builder(Type = typeof(ConfixBuildSettings), Property = nameof(ConfixBuildSettings.GitToken))] + public static T ResetGitToken(this T o) where T : ConfixBuildSettings => o.Modify(b => b.Remove(() => o.GitToken)); + #endregion #region Verbosity /// [Pure] [Builder(Type = typeof(ConfixBuildSettings), Property = nameof(ConfixBuildSettings.Verbosity))] @@ -1438,6 +1482,22 @@ [Pure] [Builder(Type = typeof(ConfixRestoreSettings), Property = nameof(ConfixRe [Pure] [Builder(Type = typeof(ConfixRestoreSettings), Property = nameof(ConfixRestoreSettings.DotnetConfiguration))] public static T ResetDotnetConfiguration(this T o) where T : ConfixRestoreSettings => o.Modify(b => b.Remove(() => o.DotnetConfiguration)); #endregion + #region GitUsername + /// + [Pure] [Builder(Type = typeof(ConfixRestoreSettings), Property = nameof(ConfixRestoreSettings.GitUsername))] + public static T SetGitUsername(this T o, string v) where T : ConfixRestoreSettings => o.Modify(b => b.Set(() => o.GitUsername, v)); + /// + [Pure] [Builder(Type = typeof(ConfixRestoreSettings), Property = nameof(ConfixRestoreSettings.GitUsername))] + public static T ResetGitUsername(this T o) where T : ConfixRestoreSettings => o.Modify(b => b.Remove(() => o.GitUsername)); + #endregion + #region GitToken + /// + [Pure] [Builder(Type = typeof(ConfixRestoreSettings), Property = nameof(ConfixRestoreSettings.GitToken))] + public static T SetGitToken(this T o, string v) where T : ConfixRestoreSettings => o.Modify(b => b.Set(() => o.GitToken, v)); + /// + [Pure] [Builder(Type = typeof(ConfixRestoreSettings), Property = nameof(ConfixRestoreSettings.GitToken))] + public static T ResetGitToken(this T o) where T : ConfixRestoreSettings => o.Modify(b => b.Remove(() => o.GitToken)); + #endregion #region Environment /// [Pure] [Builder(Type = typeof(ConfixRestoreSettings), Property = nameof(ConfixRestoreSettings.Environment))] diff --git a/src/Confix.Tool/src/Confix.Nuke/Confix.Tool.json b/src/Confix.Tool/src/Confix.Nuke/Confix.Tool.json index 43a2ea97..904019c9 100644 --- a/src/Confix.Tool/src/Confix.Nuke/Confix.Tool.json +++ b/src/Confix.Tool/src/Confix.Nuke/Confix.Tool.json @@ -159,6 +159,18 @@ "format": "--no-restore {value}", "help": "Disables restoring of schemas" }, + { + "name": "GitUsername", + "type": "string", + "format": "--git-username {value}", + "help": "The username used for git authentication." + }, + { + "name": "GitToken", + "type": "string", + "format": "--git-token {value}", + "help": "The token used for git authentication." + }, { "name": "OutputFile", "type": "string", @@ -500,6 +512,18 @@ "format": "--encrypt {value}", "help": "Encrypt the output file" }, + { + "name": "GitUsername", + "type": "string", + "format": "--git-username {value}", + "help": "The username used for git authentication." + }, + { + "name": "GitToken", + "type": "string", + "format": "--git-token {value}", + "help": "The token used for git authentication." + }, { "name": "Verbosity", "type": "string", @@ -520,6 +544,18 @@ "format": "--dotnet-configuration {value}", "help": "The configuration passed to dotnet commands. Defaults to 'Debug'." }, + { + "name": "GitUsername", + "type": "string", + "format": "--git-username {value}", + "help": "The username used for git authentication." + }, + { + "name": "GitToken", + "type": "string", + "format": "--git-token {value}", + "help": "The token used for git authentication." + }, { "name": "Environment", "type": "string", diff --git a/src/Confix.Tool/test/Confix.Tool.Tests/Commands/Variables/VariableCopyCommandTests.cs b/src/Confix.Tool/test/Confix.Tool.Tests/Commands/Variables/VariableCopyCommandTests.cs index fcb08c7e..51997503 100644 --- a/src/Confix.Tool/test/Confix.Tool.Tests/Commands/Variables/VariableCopyCommandTests.cs +++ b/src/Confix.Tool/test/Confix.Tool.Tests/Commands/Variables/VariableCopyCommandTests.cs @@ -105,7 +105,7 @@ public async Task Should_Copy_VariableFromOneProviderToTheOther() using var cli = _cli; const string beforeValue = "test"; var node = (JsonNode?) beforeValue; - await _first.SetAsync("a.b", node!, CancellationToken.None); + await _first.SetAsync("a.b", node!, new VariableProviderContext(null, CancellationToken.None)); cli.Directories.Home.CreateConfixRc(_confixRc); @@ -113,7 +113,7 @@ public async Task Should_Copy_VariableFromOneProviderToTheOther() await cli.RunAsync("variable copy --from $first:a.b --to $second:a.b"); // Assert - var afterValue = await _second.ResolveAsync("a.b", CancellationToken.None); + var afterValue = await _second.ResolveAsync("a.b", new VariableProviderContext(null, CancellationToken.None)); Assert.Equal(beforeValue, afterValue.ToString()); SnapshotBuilder.New().AddOutput(cli).MatchSnapshot(); } @@ -125,7 +125,7 @@ public async Task Should_Copy_VariableFromOneProviderToTheOther_When_DifferentEn using var cli = _cli; const string beforeValue = "test"; var node = (JsonNode?) beforeValue; - await _first.SetAsync("a.b", node!, CancellationToken.None); + await _first.SetAsync("a.b", node!, new VariableProviderContext(null, CancellationToken.None)); cli.Directories.Home.CreateConfixRc(_confixRc); @@ -134,7 +134,7 @@ await cli.RunAsync( "variable copy --from $first:a.b --to $second:a.b --to-environment prod --environment dev"); // Assert - var afterValue = await _second.ResolveAsync("a.b", CancellationToken.None); + var afterValue = await _second.ResolveAsync("a.b", new VariableProviderContext(null, CancellationToken.None)); Assert.Equal(beforeValue, afterValue.ToString()); SnapshotBuilder.New().AddOutput(cli).MatchSnapshot(); } @@ -146,7 +146,7 @@ public async Task Should_Fail_When_Environment_DoesNotExists() using var cli = _cli; const string beforeValue = "test"; var node = (JsonNode?) beforeValue; - await _first.SetAsync("a.b", node!, CancellationToken.None); + await _first.SetAsync("a.b", node!, new VariableProviderContext(null, CancellationToken.None)); cli.Directories.Home.CreateConfixRc(_confixRc); @@ -196,13 +196,13 @@ public ValueTask DisposeAsync() } /// - public Task> ListAsync(CancellationToken cancellationToken) + public Task> ListAsync(IVariableProviderContext context) { return Task.FromResult>(_variables.Keys.ToList()); } /// - public Task ResolveAsync(string path, CancellationToken cancellationToken) + public Task ResolveAsync(string path, IVariableProviderContext context) { if (_variables.TryGetValue(path, out var value)) { @@ -215,7 +215,7 @@ public Task ResolveAsync(string path, CancellationToken cancellationTo /// public Task> ResolveManyAsync( IReadOnlyList paths, - CancellationToken cancellationToken) + IVariableProviderContext context) { return Task.FromResult>(_variables .Where(x => paths.Contains(x.Key)) @@ -223,7 +223,7 @@ public Task> ResolveManyAsync( } /// - public Task SetAsync(string path, JsonNode value, CancellationToken ct) + public Task SetAsync(string path, JsonNode value, IVariableProviderContext context) { _variables[path] = value; return Task.FromResult(path); diff --git a/src/Confix.Tool/test/Confix.Tool.Tests/Entities/Component/GitUrlTests.cs b/src/Confix.Tool/test/Confix.Tool.Tests/Entities/Component/GitUrlTests.cs new file mode 100644 index 00000000..47594a23 --- /dev/null +++ b/src/Confix.Tool/test/Confix.Tool.Tests/Entities/Component/GitUrlTests.cs @@ -0,0 +1,28 @@ +using Confix.Tool; +using Confix.Tool.Common.Pipelines; +using Confix.Tool.Entities.Components.Git; +using Moq; + +public class GitUrlTests +{ + [Theory] + [InlineData("https://github.com/org/repo.git", "user", "token", "https://user:token@github.com/org/repo.git")] + [InlineData("https://github.com/org/repo.git", null, null, "https://github.com/org/repo.git")] + [InlineData("https://github.com/org/repo.git", "", "", "https://github.com/org/repo.git")] + [InlineData("http://github.com/org/repo.git", "user", "token", "http://github.com/org/repo.git")] + [InlineData("https://github.com/org/repo.git", "user", null, "https://github.com/org/repo.git")] + [InlineData("https://github.com/org/repo.git", null, "token", "https://github.com/org/repo.git")] + public void GitUrl_Create_WorksAsExpected(string url, object username, object token, string expected) + { + // Arrange + var parameters = new Mock(); + parameters.Setup(p => p.TryGet(It.IsAny(), out username)).Returns(true); + parameters.Setup(p => p.TryGet(It.IsAny(), out token)).Returns(true); + + // Act + var result = GitUrl.Create(url, parameters.Object); + + // Assert + Assert.Equal(expected, result); + } +} diff --git a/src/Confix.Tool/test/Confix.Tool.Tests/Variables/AzureKeyVaultProviderTests.cs b/src/Confix.Tool/test/Confix.Tool.Tests/Variables/AzureKeyVaultProviderTests.cs index 4cb167d2..1cec1511 100644 --- a/src/Confix.Tool/test/Confix.Tool.Tests/Variables/AzureKeyVaultProviderTests.cs +++ b/src/Confix.Tool/test/Confix.Tool.Tests/Variables/AzureKeyVaultProviderTests.cs @@ -36,8 +36,10 @@ public async Task ListAsync_Should_ReturnKeysAsync() .Returns(pageableMock.Object); AzureKeyVaultProvider provider = new(secretClientMock.Object); + var context = new VariableProviderContext(null, CancellationToken.None); + // act - var result = await provider.ListAsync(default); + var result = await provider.ListAsync(context); // assert result.Should().HaveCount(2); @@ -60,9 +62,10 @@ public async Task ResolveAsync_Should_ResolveVariableAsync() .ReturnsAsync(responseMock.Object); AzureKeyVaultProvider provider = new(secretClientMock.Object); + var context = new VariableProviderContext(null, CancellationToken.None); // act - var result = await provider.ResolveAsync("foo", default); + var result = await provider.ResolveAsync("foo", context); // assert ((string?)result)?.Should().Be("bar"); @@ -82,9 +85,10 @@ public async Task SetAsync_Should_SetAndReturn() .Setup(x => x.SetSecretAsync("foo", "bar", default)) .ReturnsAsync(responseMock.Object); AzureKeyVaultProvider provider = new(secretClientMock.Object); + var context = new VariableProviderContext(null, CancellationToken.None); // act - var result = await provider.SetAsync("foo", JsonValue.Create("bar")!, default); + var result = await provider.SetAsync("foo", JsonValue.Create("bar")!, context); // assert result.Should().Be("vault.key"); diff --git a/src/Confix.Tool/test/Confix.Tool.Tests/Variables/LocalVariableProviderTests.cs b/src/Confix.Tool/test/Confix.Tool.Tests/Variables/LocalVariableProviderTests.cs index 6efd31d5..548d4bf1 100644 --- a/src/Confix.Tool/test/Confix.Tool.Tests/Variables/LocalVariableProviderTests.cs +++ b/src/Confix.Tool/test/Confix.Tool.Tests/Variables/LocalVariableProviderTests.cs @@ -102,9 +102,10 @@ await PrepareFile( """); LocalVariableProvider provider = new(new LocalVariableProviderDefinition(tmpFilePath)); var paths = new List { "foo", "bar" }; + var context = new VariableProviderContext(null, CancellationToken.None); // act - var result = await provider.ResolveManyAsync(paths, default); + var result = await provider.ResolveManyAsync(paths, context); // assert result.Should().HaveCount(2); @@ -125,11 +126,12 @@ await PrepareFile( """); LocalVariableProvider provider = new(new LocalVariableProviderDefinition(tmpFilePath)); var paths = new List { "foo", "nonexistent" }; + var context = new VariableProviderContext(null, CancellationToken.None); // act & assert var exception = await Assert.ThrowsAsync(() - => provider.ResolveManyAsync(paths, default)); + => provider.ResolveManyAsync(paths, context)); exception.InnerExceptions.Should().HaveCount(1); exception.InnerExceptions[0].Should().BeOfType(); } diff --git a/src/Confix.Tool/test/Confix.Tool.Tests/Variables/VariableReplacerServiceTests.cs b/src/Confix.Tool/test/Confix.Tool.Tests/Variables/VariableReplacerServiceTests.cs index e0ba8fec..14d78192 100644 --- a/src/Confix.Tool/test/Confix.Tool.Tests/Variables/VariableReplacerServiceTests.cs +++ b/src/Confix.Tool/test/Confix.Tool.Tests/Variables/VariableReplacerServiceTests.cs @@ -25,8 +25,8 @@ public async Task RewriteAsync_ValidVariables_ReplaceAllVariablesAsync() Mock variableResolverMock = new(MockBehavior.Strict); variableResolverMock.Setup(x => x.ResolveVariables( It.IsAny>(), - It.IsAny())) - .ReturnsAsync((IReadOnlyList keys, CancellationToken _) => + It.IsAny())) + .ReturnsAsync((IReadOnlyList keys, IVariableProviderContext _) => { var result = new Dictionary(); foreach (var key in keys) @@ -53,8 +53,8 @@ public async Task RewriteAsync_JsonValue_ResolvesCorrectly() Mock variableResolverMock = new(MockBehavior.Strict); variableResolverMock.Setup(x => x.ResolveVariables( It.IsAny>(), - It.IsAny())) - .ReturnsAsync((IReadOnlyList keys, CancellationToken _) => + It.IsAny())) + .ReturnsAsync((IReadOnlyList keys, IVariableProviderContext _) => { var result = new Dictionary(); foreach (var key in keys) @@ -85,8 +85,8 @@ public async Task RewriteAsync_VariablesInNestedArray_ResolvesCorrectly() Mock variableResolverMock = new(MockBehavior.Strict); variableResolverMock.Setup(x => x.ResolveVariables( It.IsAny>(), - It.IsAny())) - .ReturnsAsync((IReadOnlyList keys, CancellationToken _) => + It.IsAny())) + .ReturnsAsync((IReadOnlyList keys, IVariableProviderContext _) => { var result = new Dictionary(); foreach (var key in keys) @@ -133,8 +133,8 @@ public async Task RewriteAsync_VariablesInNestedObject_ResolvesCorrectly() Mock variableResolverMock = new(MockBehavior.Strict); variableResolverMock.Setup(x => x.ResolveVariables( It.IsAny>(), - It.IsAny())) - .ReturnsAsync((IReadOnlyList keys, CancellationToken _) => + It.IsAny())) + .ReturnsAsync((IReadOnlyList keys, IVariableProviderContext _) => { var result = new Dictionary(); foreach (var key in keys) @@ -182,8 +182,8 @@ public async Task RewriteAsync_RecursiveVariables_CorrectlyResolve() Mock variableResolverMock = new(MockBehavior.Strict); variableResolverMock.Setup(x => x.ResolveVariables( It.IsAny>(), - It.IsAny())) - .ReturnsAsync((IReadOnlyList keys, CancellationToken _) => + It.IsAny())) + .ReturnsAsync((IReadOnlyList keys, IVariableProviderContext _) => { var result = new Dictionary(); foreach (var key in keys) @@ -222,8 +222,8 @@ public async Task RewriteAsync_RecursiveVariablesWithDirectLoop_ThrowCircularVar Mock variableResolverMock = new(MockBehavior.Strict); variableResolverMock.Setup(x => x.ResolveVariables( It.IsAny>(), - It.IsAny())) - .ReturnsAsync((IReadOnlyList keys, CancellationToken _) => + It.IsAny())) + .ReturnsAsync((IReadOnlyList keys, IVariableProviderContext _) => { var result = new Dictionary(); foreach (var key in keys) @@ -259,8 +259,8 @@ public async Task RewriteAsync_RecursiveVariablesWithindirectLoop_ThrowsCircular Mock variableResolverMock = new(MockBehavior.Strict); variableResolverMock.Setup(x => x.ResolveVariables( It.IsAny>(), - It.IsAny())) - .ReturnsAsync((IReadOnlyList keys, CancellationToken _) => + It.IsAny())) + .ReturnsAsync((IReadOnlyList keys, IVariableProviderContext _) => { var result = new Dictionary(); foreach (var key in keys) diff --git a/src/Confix.Tool/test/Confix.Tool.Tests/Variables/VariableResolverTests.cs b/src/Confix.Tool/test/Confix.Tool.Tests/Variables/VariableResolverTests.cs index ccf864e3..03d68ad5 100644 --- a/src/Confix.Tool/test/Confix.Tool.Tests/Variables/VariableResolverTests.cs +++ b/src/Confix.Tool/test/Confix.Tool.Tests/Variables/VariableResolverTests.cs @@ -47,12 +47,12 @@ public async Task ResolveVariables_MultipleProviders_CorrectResult() } }; var resolver = new VariableResolver(factoryMock.Object, new VariableListCache(), configurations); - var cancellationToken = CancellationToken.None; + var context = new VariableProviderContext(null!, CancellationToken.None); var provider1Mock = new Mock(); provider1Mock.Setup(p => p.ResolveManyAsync( It.Is>(paths => paths.SequenceEqual(new[] { "Key1", "Key3" })), - cancellationToken)) + context)) .ReturnsAsync(new Dictionary { { "Key1", JsonValue.Create("Value1")! }, @@ -62,7 +62,7 @@ public async Task ResolveVariables_MultipleProviders_CorrectResult() var provider2Mock = new Mock(); provider2Mock.Setup(p => p.ResolveManyAsync( It.Is>(paths => paths.SequenceEqual(new[] { "Key2", "Key4" })), - cancellationToken)) + context)) .ReturnsAsync(new Dictionary { { "Key2", JsonValue.Create("Value2")! }, @@ -76,7 +76,7 @@ public async Task ResolveVariables_MultipleProviders_CorrectResult() .Returns(provider2Mock.Object); // Act - var result = await resolver.ResolveVariables(keys, cancellationToken); + var result = await resolver.ResolveVariables(keys, context); // Assert result.Should().HaveCount(4); @@ -112,12 +112,12 @@ public async Task ResolveVariables_DuplicatePaths_OnlyFetchOnce() } }; var resolver = new VariableResolver(factoryMock.Object, new VariableListCache(), configurations); - var cancellationToken = CancellationToken.None; + var context = new VariableProviderContext(null!, CancellationToken.None); var provider1Mock = new Mock(); provider1Mock.Setup(p => p.ResolveManyAsync( It.Is>(paths => paths.SequenceEqual(new[] { "Key1" })), - cancellationToken)) + context)) .ReturnsAsync(new Dictionary { { "Key1", JsonValue.Create("Value1")! }, @@ -127,7 +127,7 @@ public async Task ResolveVariables_DuplicatePaths_OnlyFetchOnce() .Returns(provider1Mock.Object); // Act - var result = await resolver.ResolveVariables(keys, cancellationToken); + var result = await resolver.ResolveVariables(keys, context); // Assert result.Should().HaveCount(1); @@ -135,7 +135,7 @@ public async Task ResolveVariables_DuplicatePaths_OnlyFetchOnce() provider1Mock.Verify(p => p.ResolveManyAsync( It.Is>(paths => paths.SequenceEqual(new[] { "Key1" })), - cancellationToken), Times.Once); + context), Times.Once); } [Fact] @@ -145,11 +145,11 @@ public async Task ResolveVariable_ProviderNotFound_ThrowsExitException() var factoryMock = new Mock(); var configurations = new List(); var resolver = new VariableResolver(factoryMock.Object,new VariableListCache(), configurations); - var cancellationToken = CancellationToken.None; + var context = new VariableProviderContext(null!, CancellationToken.None); // Act & Assert await Assert.ThrowsAsync(() => - resolver.ResolveVariable(new VariablePath("Provider1", "Key1"), cancellationToken)); + resolver.ResolveVariable(new VariablePath("Provider1", "Key1"), context)); } [Fact] @@ -165,10 +165,10 @@ public async Task ResolveVariables_ProviderNotFound_ThrowsExitException() var configurations = new List(); var resolver = new VariableResolver(factoryMock.Object, new VariableListCache(), configurations); - var cancellationToken = CancellationToken.None; + var context = new VariableProviderContext(null!, CancellationToken.None); // Act & Assert await Assert.ThrowsAsync(() => - resolver.ResolveVariables(keys, cancellationToken)); + resolver.ResolveVariables(keys, context)); } }