Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ ldcli aws-devops-agent setup

The AWS DevOps Agent is available in `us-east-1`, `us-east-2`, `us-west-2`, `ca-central-1`, `sa-east-1`, `ap-south-1`, `ap-southeast-1`, `ap-southeast-2`, `ap-northeast-1`, `ap-northeast-2`, `eu-central-1`, `eu-west-1`, `eu-west-2`, `eu-west-3` and `eu-north-1`, and requires AWS CLI 2.36 or later if you also use the AWS CLI directly. `setup` warns when the `aws` binary on your PATH is missing or older than that; the command itself uses the AWS SDK, so it still runs.

If the account already runs the AWS DevOps Agent, `setup` lists its agent spaces and asks which one to connect LaunchDarkly to. It then only registers and associates the LaunchDarkly MCP server on the space you pick, leaving its IAM roles, account association and operator app sign-in configuration alone. Pass `--agent-space-id <id>` to pick one without being asked, or `--new-agent-space` to provision another space.
If the account already runs the AWS DevOps Agent, `setup` lists its agent spaces and asks which one to connect LaunchDarkly to. It then only registers and associates the LaunchDarkly MCP server on the space you pick, leaving its IAM roles, account association and operator app sign-in configuration alone. Pass `--agent-space-id <id>` to pick one without being asked, or `--new-agent-space` to provision another space. You cannot pass both. If you pass `--agent-space-id` with `--auth-flow`, `setup` runs the full setup on that space. The full setup also changes the IAM roles, the account association, and the operator app sign-in configuration.

If the SSO session of your profile expired, `setup` and `status` offer to run `aws sso login --profile <name>` for you. They ask only in a terminal.
Before `setup` changes AWS, it shows a plan. The plan names the AWS account, region, profile, IAM roles, agent space, operator app, and MCP server, and what `setup` will do to each. In a terminal, `setup` then asks `Continue? [y/N]` and stops with an error unless you type `y` or `yes`. To skip the question, pass `--yes`. If stdin is a terminal and the output is plaintext, `setup` can ask. In other runs, it does not ask. If stdout is not a terminal, the default output is json, so `setup` does not ask. `setup` writes the plan, the questions, and the progress to stderr. It writes only the result to stdout. Thus every run shows the plan, and with `--output json`, stdout contains only the JSON result.

If the SSO session of your profile expired, `setup` and `status` offer to run `aws sso login --profile <name>` for you. They ask only in a terminal, and not with `--output json`.

Without a terminal — in CI, or with `--output json` — `setup` reuses the space matching `--agent-space-name` so an unattended re-run stays idempotent, and fails asking for `--agent-space-id` or `--new-agent-space` when the only spaces are ones it did not create.

Expand Down
15 changes: 10 additions & 5 deletions cmd/aws_devops_agent/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/spf13/cobra"

"github.com/launchdarkly/ldcli/cmd/cliflags"
"github.com/launchdarkly/ldcli/internal/awsdevops"
)

Expand All @@ -27,17 +28,21 @@ type ssoLogin struct {

// loadClients builds AWS clients from the command flags.
func loadClients(cmd *cobra.Command) (awsdevops.Clients, error) {
l := ssoLogin{
l := newSSOLogin(cmd, canPrompt)

return l.clients(cmd.Context(), mustString(cmd, regionFlag), mustString(cmd, profileFlag))
}

func newSSOLogin(cmd *cobra.Command, tty func() bool) ssoLogin {
return ssoLogin{
newClients: awsdevops.NewClients,
configPath: awsdevops.ConfigFilePath(),
in: cmd.InOrStdin(),
in: sharedStdin(cmd),
out: cmd.ErrOrStderr(),
interactive: canPrompt,
interactive: func() bool { return cliflags.GetOutputKind(cmd) != "json" && tty() },
lookPath: exec.LookPath,
run: runAttached,
}

return l.clients(cmd.Context(), mustString(cmd, regionFlag), mustString(cmd, profileFlag))
}

func (l ssoLogin) clients(ctx context.Context, region, profile string) (awsdevops.Clients, error) {
Expand Down
35 changes: 35 additions & 0 deletions cmd/aws_devops_agent/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
"strings"
"testing"

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/launchdarkly/ldcli/cmd/cliflags"
"github.com/launchdarkly/ldcli/internal/awsdevops"
)

Expand Down Expand Up @@ -228,3 +230,36 @@ func TestLoginSkipsWhenFirstCallWorks(t *testing.T) {
assert.Zero(t, f.reads)
assert.Equal(t, 1, f.calls)
}

// JSON runs never ask, like the setup plan.
func TestLoginNeverAsksInJSONMode(t *testing.T) {
viper.Set(cliflags.OutputFlag, "json")
t.Cleanup(func() { viper.Set(cliflags.OutputFlag, "") })
cmd := NewStatusCmd(nil)

l := newSSOLogin(cmd, func() bool { return true })

assert.False(t, l.interactive())
}

func TestLoginAsksInPlaintextTerminal(t *testing.T) {
viper.Set(cliflags.OutputFlag, "plaintext")
t.Cleanup(func() { viper.Set(cliflags.OutputFlag, "") })
cmd := NewStatusCmd(nil)

l := newSSOLogin(cmd, func() bool { return true })

assert.True(t, l.interactive())
}

// The SSO prompt shares stdin with later prompts.
func TestLoginPromptLeavesLaterLines(t *testing.T) {
cmd := NewSetupCmd(nil)
cmd.SetIn(strings.NewReader("y\n1\nyes\n"))

l := newSSOLogin(cmd, func() bool { return true })

assert.Equal(t, "y", readLine(l.in))
assert.Equal(t, "1", readLine(cmd.InOrStdin()))
assert.Equal(t, "yes", readLine(cmd.InOrStdin()))
}
Loading
Loading