Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add support for pulumi config env ls #225

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions sdk/Pulumi.Automation.Tests/LocalWorkspaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

using static Pulumi.Automation.Tests.Utility;
using Xunit.Sdk;
using Castle.DynamicProxy.Generators;
cleverguy25 marked this conversation as resolved.
Show resolved Hide resolved

namespace Pulumi.Automation.Tests
{
Expand Down Expand Up @@ -159,16 +160,23 @@ public async Task AddAndRemoveEnvironment()
var program = PulumiFn.Create<ValidStack>();
var stackName = FullyQualifiedStackName(_pulumiOrg, projectName, $"int_test{GetTestSuffix()}");
await workspace.CreateStackAsync(stackName);
var stack = await WorkspaceStack.SelectAsync(stackName, workspace);

await Assert.ThrowsAsync<CommandException>(() => workspace.AddEnvironmentsAsync(stackName, new[] { "non-existent-env" }));
await Assert.ThrowsAsync<CommandException>(() => stack.AddEnvironmentsAsync(new[] { "non-existent-env" }));

await workspace.AddEnvironmentsAsync(stackName, new[] { "automation-api-test-env", "automation-api-test-env-2" });
await stack.AddEnvironmentsAsync(new[] { "automation-api-test-env", "automation-api-test-env-2" });

var environments = await stack.ListEnvironmentsAsync();
Assert.Equal(new string[]{"automation-api-test-env", "automation-api-test-env-2"}, environments);
cleverguy25 marked this conversation as resolved.
Show resolved Hide resolved
var config = await workspace.GetAllConfigAsync(stackName);

Assert.Equal("test_value", config["node_env_test:new_key"].Value);
Assert.Equal("business", config["node_env_test:also"].Value);

await workspace.RemoveEnvironmentAsync(stackName, "automation-api-test-env");
await stack.RemoveEnvironmentAsync("automation-api-test-env");
environments = await stack.ListEnvironmentsAsync();
Assert.Equal(new string[]{"automation-api-test-env-2"}, environments);
cleverguy25 marked this conversation as resolved.
Show resolved Hide resolved

config = await workspace.GetAllConfigAsync(stackName);
Assert.Equal("business", config["node_env_test:also"].Value);
Assert.False(config.ContainsKey("node_env_test:new_key"));
Expand Down
19 changes: 19 additions & 0 deletions sdk/Pulumi.Automation/LocalWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,14 @@ public override async Task AddEnvironmentsAsync(string stackName, IEnumerable<st
await this.RunCommandAsync(args, cancellationToken).ConfigureAwait(false);
}

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

/// <inheritdoc/>
public override async Task RemoveEnvironmentAsync(string stackName, string environment, CancellationToken cancellationToken = default)
{
Expand Down Expand Up @@ -991,5 +999,16 @@ private void CheckSupportsEnvironmentsCommands()
throw new InvalidOperationException("The Pulumi CLI version does not support env operations on a stack. Please update the Pulumi CLI.");
}
}

private void CheckSupportsEnvironmentsListCommand()
{
var version = this._pulumiVersion ?? new SemVersion(3, 0);

// 3.99 added this command (https://github.com/pulumi/pulumi/releases/tag/v3.99.0)
if (version < new SemVersion(3, 99))
{
throw new InvalidOperationException("The Pulumi CLI version does not support env ls operations on a stack. Please update the Pulumi CLI.");
}
}
}
}
10 changes: 10 additions & 0 deletions sdk/Pulumi.Automation/Pulumi.Automation.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions sdk/Pulumi.Automation/Workspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ internal Workspace(IPulumiCmd cmd)
/// <param name="cancellationToken">A cancellation token.</param>
public abstract Task AddEnvironmentsAsync(string stackName, IEnumerable<string> environments, CancellationToken cancellationToken = default);

/// <summary>
/// Returns the list of environments associated with the specified stack name
/// </summary>
/// <param name="stackName">The name of the stack.</param>
/// <param name="cancellationToken">A cancellation token.</param>
public abstract Task<string[]> ListEnvironmentsAsync(string stackName, CancellationToken cancellationToken = default);
cleverguy25 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Removes environments from a stack's import list.
Expand Down
3 changes: 3 additions & 0 deletions sdk/Pulumi.Automation/WorkspaceStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ public Task<ImmutableDictionary<string, ConfigValue>> RefreshConfigAsync(Cancell
public Task AddEnvironmentsAsync(IEnumerable<string> environments, CancellationToken cancellationToken = default)
=> this.Workspace.AddEnvironmentsAsync(this.Name, environments, cancellationToken);

public Task<string[]> ListEnvironmentsAsync(CancellationToken cancellationToken = default)
=> this.Workspace.ListEnvironmentsAsync(this.Name, cancellationToken);

/// <summary>
/// Removes environments from a stack's import list.
/// </summary>
Expand Down
Loading