Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
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
6 changes: 3 additions & 3 deletions sdk/Pulumi.Automation.Tests/LocalWorkspaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ public async Task StackReferenceDestroyDiscardsWithTwoInlinePrograms()
var upResult = await stackA.UpAsync();
Assert.Equal(UpdateKind.Update, upResult.Summary.Kind);
Assert.Equal(UpdateState.Succeeded, upResult.Summary.Result);
Assert.Equal(1, upResult.Outputs.Count);
Assert.Single(upResult.Outputs);

// exp_static
Assert.True(upResult.Outputs.TryGetValue("exp_static", out var expStaticValue));
Expand All @@ -934,7 +934,7 @@ public async Task StackReferenceDestroyDiscardsWithTwoInlinePrograms()
var upResult = await stackB.UpAsync();
Assert.Equal(UpdateKind.Update, upResult.Summary.Kind);
Assert.Equal(UpdateState.Succeeded, upResult.Summary.Result);
Assert.Equal(1, upResult.Outputs.Count);
Assert.Single(upResult.Outputs);

// exp_static
Assert.True(upResult.Outputs.TryGetValue("exp_static", out var expStaticValue));
Expand Down Expand Up @@ -1765,7 +1765,7 @@ public async Task WorkspaceStackSupportsCancel()

try
{
Task.WaitAll(destroyTask, cancelTask);
await Task.WhenAll(destroyTask, cancelTask);
}
catch (AggregateException)
{
Expand Down
12 changes: 6 additions & 6 deletions sdk/Pulumi.Automation.Tests/Pulumi.Automation.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="Serilog.Sinks.XUnit" Version="2.0.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="Serilog.Sinks.XUnit" Version="3.0.19" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void CanDeserializeUpdateSummary()
Assert.Equal(UpdateKind.Update, update.Kind);
Assert.Equal(UpdateState.Succeeded, update.Result);
Assert.NotNull(update.ResourceChanges);
Assert.Equal(1, update.ResourceChanges!.Count);
Assert.Single(update.ResourceChanges!);
Assert.True(update.ResourceChanges.TryGetValue(OperationType.Create, out var createdCount));
Assert.Equal(3, createdCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ bool IEqualityComparer<IDictionary<TKey, TValue>>.Equals(IDictionary<TKey, TValu
var y2 = new Dictionary<TKey, TValue>(y, this._keyComparer);
foreach (var pair in x)
{
if (!y2.ContainsKey(pair.Key))
if (!y2.TryGetValue(pair.Key, out TValue? value))
{
return false;
}

if (!this._valueComparer.Equals(pair.Value, y2[pair.Key]))
if (!this._valueComparer.Equals(pair.Value, value))
{
return false;
}
Expand Down
12 changes: 6 additions & 6 deletions sdk/Pulumi.Automation/Commands/LocalPulumiCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static async Task<LocalPulumiCommand> CreateAsync(
}

var minimumVersion = _minimumVersion;
if (options?.Version != null && options.Version > minimumVersion)
if (options?.Version != null && options.Version.CompareSortOrderTo(minimumVersion) > 0)
{
minimumVersion = options.Version;
}
Expand Down Expand Up @@ -151,7 +151,7 @@ private static async Task InstallWindowsAsync(SemVersion version, string root, C
string command = systemRoot != null
? Path.Combine(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe")
: "powershell.exe";
string[] args = {
string[] args = [
"-NoProfile",
"-InputFormat",
"None",
Expand All @@ -164,7 +164,7 @@ private static async Task InstallWindowsAsync(SemVersion version, string root, C
root,
"-Version",
version.ToString()
};
];

var result = await Cli.Wrap(command).WithArguments(args, escape: true)
.WithValidation(CommandResultValidation.None)
Expand Down Expand Up @@ -257,7 +257,7 @@ private static async Task<string> DownloadToTmpFileAsync(string url, string exte
{
throw new InvalidOperationException($"Major version mismatch. You are using Pulumi CLI version {version} with Automation SDK v{minVersion.Major}. Please update the SDK.");
}
if (minVersion > version)
if (minVersion.CompareSortOrderTo(version) > 0)
{
throw new InvalidOperationException($"Minimum version requirement failed. The minimum CLI version requirement is {minVersion}, your current CLI version is {version}. Please update the Pulumi CLI.");
}
Expand Down Expand Up @@ -384,12 +384,12 @@ private static IList<string> PulumiArgs(IList<string> args, EventLogFile? eventL
// this causes commands to fail rather than prompting for input (and thus hanging indefinitely)
if (!args.Contains("--non-interactive"))
{
args = args.Concat(new[] { "--non-interactive" }).ToList();
args = args.Concat(["--non-interactive"]).ToList();
}

if (eventLogFile != null)
{
args = args.Concat(new[] { "--event-log", eventLogFile.FilePath }).ToList();
args = args.Concat(["--event-log", eventLogFile.FilePath]).ToList();
}

return args;
Expand Down
3 changes: 2 additions & 1 deletion sdk/Pulumi.Automation/ConfigValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class ConfigValue

public ConfigValue(
string value,
bool isSecret = false)
bool isSecret = false
)
{
this.Value = value;
this.IsSecret = isSecret;
Expand Down
42 changes: 21 additions & 21 deletions sdk/Pulumi.Automation/LocalWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ private async Task InitializeProjectSettingsAsync(ProjectSettings projectSetting
}
}

private static readonly string[] _settingsExtensions = { ".yaml", ".yml", ".json" };
private static readonly string[] _settingsExtensions = [".yaml", ".yml", ".json"];

private static bool OptOutOfVersionCheck(IDictionary<string, string?>? EnvironmentVariables = null)
{
Expand Down Expand Up @@ -535,32 +535,32 @@ public override async Task AddEnvironmentsAsync(string stackName, IEnumerable<st
public override async Task RemoveEnvironmentAsync(string stackName, string environment, CancellationToken cancellationToken = default)
{
CheckSupportsEnvironmentsCommands();
await this.RunCommandAsync(new[] { "config", "env", "rm", environment, "--stack", stackName, "--yes" }, cancellationToken).ConfigureAwait(false);
await this.RunCommandAsync(["config", "env", "rm", environment, "--stack", stackName, "--yes"], cancellationToken).ConfigureAwait(false);
}

/// <inheritdoc/>
public override async Task<string> GetTagAsync(string stackName, string key, CancellationToken cancellationToken = default)
{
var result = await this.RunCommandAsync(new[] { "stack", "tag", "get", key, "--stack", stackName }, cancellationToken).ConfigureAwait(false);
var result = await this.RunCommandAsync(["stack", "tag", "get", key, "--stack", stackName], cancellationToken).ConfigureAwait(false);
return result.StandardOutput.Trim();
}

/// <inheritdoc/>
public override async Task SetTagAsync(string stackName, string key, string value, CancellationToken cancellationToken = default)
{
await this.RunCommandAsync(new[] { "stack", "tag", "set", key, value, "--stack", stackName }, cancellationToken).ConfigureAwait(false);
await this.RunCommandAsync(["stack", "tag", "set", key, value, "--stack", stackName], cancellationToken).ConfigureAwait(false);
}

/// <inheritdoc/>
public override async Task RemoveTagAsync(string stackName, string key, CancellationToken cancellationToken = default)
{
await this.RunCommandAsync(new[] { "stack", "tag", "rm", key, "--stack", stackName }, cancellationToken).ConfigureAwait(false);
await this.RunCommandAsync(["stack", "tag", "rm", key, "--stack", stackName], cancellationToken).ConfigureAwait(false);
}

/// <inheritdoc/>
public override async Task<Dictionary<string, string>> ListTagsAsync(string stackName, CancellationToken cancellationToken = default)
{
var result = await this.RunCommandAsync(new[] { "stack", "tag", "ls", "--json", "--stack", stackName }, cancellationToken).ConfigureAwait(false);
var result = await this.RunCommandAsync(["stack", "tag", "ls", "--json", "--stack", stackName], cancellationToken).ConfigureAwait(false);
return this._serializer.DeserializeJson<Dictionary<string, string>>(result.StandardOutput);
}

Expand All @@ -576,15 +576,15 @@ public override async Task<ConfigValue> GetConfigAsync(string stackName, string
{
args.Add("--path");
}
args.AddRange(new[] { key, "--json", "--stack", stackName });
args.AddRange([key, "--json", "--stack", stackName]);
var result = await this.RunCommandAsync(args, cancellationToken).ConfigureAwait(false);
return this._serializer.DeserializeJson<ConfigValue>(result.StandardOutput);
}

/// <inheritdoc/>
public override async Task<ImmutableDictionary<string, ConfigValue>> GetAllConfigAsync(string stackName, CancellationToken cancellationToken = default)
{
var result = await this.RunCommandAsync(new[] { "config", "--show-secrets", "--json", "--stack", stackName }, cancellationToken).ConfigureAwait(false);
var result = await this.RunCommandAsync(["config", "--show-secrets", "--json", "--stack", stackName], cancellationToken).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(result.StandardOutput))
return ImmutableDictionary<string, ConfigValue>.Empty;

Expand All @@ -605,7 +605,7 @@ public override async Task SetConfigAsync(string stackName, string key, ConfigVa
args.Add("--path");
}
var secretArg = value.IsSecret ? "--secret" : "--plaintext";
args.AddRange(new[] { key, secretArg, "--stack", stackName, "--non-interactive", "--", value.Value });
args.AddRange([key, secretArg, "--stack", stackName, "--non-interactive", "--", value.Value]);
await this.RunCommandAsync(args, cancellationToken).ConfigureAwait(false);
}

Expand Down Expand Up @@ -664,7 +664,7 @@ public override async Task RemoveAllConfigAsync(string stackName, IEnumerable<st
/// <inheritdoc/>
public override async Task<ImmutableDictionary<string, ConfigValue>> RefreshConfigAsync(string stackName, CancellationToken cancellationToken = default)
{
await this.RunCommandAsync(new[] { "config", "refresh", "--force", "--stack", stackName }, cancellationToken).ConfigureAwait(false);
await this.RunCommandAsync(["config", "refresh", "--force", "--stack", stackName], cancellationToken).ConfigureAwait(false);
return await this.GetAllConfigAsync(stackName, cancellationToken).ConfigureAwait(false);
}

Expand All @@ -675,13 +675,13 @@ public override async Task<WhoAmIResult> WhoAmIAsync(CancellationToken cancellat
if (SupportsCommand(new SemVersion(3, 58)))
{
// Use the new --json style
var result = await this.RunCommandAsync(new[] { "whoami", "--json" }, cancellationToken).ConfigureAwait(false);
var result = await this.RunCommandAsync(["whoami", "--json"], cancellationToken).ConfigureAwait(false);
return this._serializer.DeserializeJson<WhoAmIResult>(result.StandardOutput);
}
else
{
// Fallback to the old just a name style
var result = await this.RunCommandAsync(new[] { "whoami", }, cancellationToken).ConfigureAwait(false);
var result = await this.RunCommandAsync(["whoami",], cancellationToken).ConfigureAwait(false);
return new WhoAmIResult(result.StandardOutput.Trim(), null, ImmutableArray<string>.Empty);
}
}
Expand All @@ -697,7 +697,7 @@ public override Task CreateStackAsync(string stackName, CancellationToken cancel
};

if (!string.IsNullOrWhiteSpace(this.SecretsProvider))
args.AddRange(new[] { "--secrets-provider", this.SecretsProvider });
args.AddRange(["--secrets-provider", this.SecretsProvider]);

if (Remote)
args.Add("--no-select");
Expand Down Expand Up @@ -726,12 +726,12 @@ public override Task SelectStackAsync(string stackName, CancellationToken cancel

/// <inheritdoc/>
public override Task RemoveStackAsync(string stackName, CancellationToken cancellationToken = default)
=> this.RunCommandAsync(new[] { "stack", "rm", "--yes", stackName }, cancellationToken);
=> this.RunCommandAsync(["stack", "rm", "--yes", stackName], cancellationToken);

/// <inheritdoc/>
public override async Task<ImmutableList<StackSummary>> ListStacksAsync(CancellationToken cancellationToken = default)
{
var result = await this.RunCommandAsync(new[] { "stack", "ls", "--json" }, cancellationToken).ConfigureAwait(false);
var result = await this.RunCommandAsync(["stack", "ls", "--json"], cancellationToken).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(result.StandardOutput))
return ImmutableList<StackSummary>.Empty;

Expand All @@ -743,7 +743,7 @@ public override async Task<ImmutableList<StackSummary>> ListStacksAsync(Cancella
public override async Task<StackDeployment> ExportStackAsync(string stackName, CancellationToken cancellationToken = default)
{
var commandResult = await this.RunCommandAsync(
new[] { "stack", "export", "--stack", stackName, "--show-secrets" },
["stack", "export", "--stack", stackName, "--show-secrets"],
cancellationToken).ConfigureAwait(false);
return StackDeployment.FromJsonString(commandResult.StandardOutput);
}
Expand All @@ -755,7 +755,7 @@ public override async Task ImportStackAsync(string stackName, StackDeployment st
try
{
await File.WriteAllTextAsync(tempFileName, state.Json.GetRawText(), cancellationToken).ConfigureAwait(false);
await this.RunCommandAsync(new[] { "stack", "import", "--file", tempFileName, "--stack", stackName },
await this.RunCommandAsync(["stack", "import", "--file", tempFileName, "--stack", stackName],
cancellationToken).ConfigureAwait(false);
}
finally
Expand Down Expand Up @@ -814,7 +814,7 @@ public override Task RemovePluginAsync(string? name = null, string? versionRange
/// <inheritdoc/>
public override async Task<ImmutableList<PluginInfo>> ListPluginsAsync(CancellationToken cancellationToken = default)
{
var result = await this.RunCommandAsync(new[] { "plugin", "ls", "--json" }, cancellationToken).ConfigureAwait(false);
var result = await this.RunCommandAsync(["plugin", "ls", "--json"], cancellationToken).ConfigureAwait(false);
var plugins = this._serializer.DeserializeJson<List<PluginInfo>>(result.StandardOutput);
return plugins.ToImmutableList();
}
Expand All @@ -823,8 +823,8 @@ public override async Task<ImmutableList<PluginInfo>> ListPluginsAsync(Cancellat
public override async Task<ImmutableDictionary<string, OutputValue>> GetStackOutputsAsync(string stackName, CancellationToken cancellationToken = default)
{
// TODO: do this in parallel after this is fixed https://github.com/pulumi/pulumi/issues/6050
var maskedResult = await this.RunCommandAsync(new[] { "stack", "output", "--json", "--stack", stackName }, cancellationToken).ConfigureAwait(false);
var plaintextResult = await this.RunCommandAsync(new[] { "stack", "output", "--json", "--show-secrets", "--stack", stackName }, cancellationToken).ConfigureAwait(false);
var maskedResult = await this.RunCommandAsync(["stack", "output", "--json", "--stack", stackName], cancellationToken).ConfigureAwait(false);
var plaintextResult = await this.RunCommandAsync(["stack", "output", "--json", "--show-secrets", "--stack", stackName], cancellationToken).ConfigureAwait(false);

var maskedOutput = string.IsNullOrWhiteSpace(maskedResult.StandardOutput)
? new Dictionary<string, object>()
Expand Down Expand Up @@ -1028,7 +1028,7 @@ private bool SupportsCommand(SemVersion minSupportedVersion)
{
var version = _cmd.Version ?? new SemVersion(3, 0);

return version >= minSupportedVersion;
return version.CompareSortOrderTo(minSupportedVersion) >= 0;
}

private void CheckSupportsEnvironmentsCommands()
Expand Down
Loading
Loading