Skip to content
Merged
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
30 changes: 19 additions & 11 deletions cmd/command/stacks/stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/AlecAivazis/survey/v2"
"github.com/pluralsh/plural-cli/pkg/api"
"github.com/pluralsh/plural-cli/pkg/client"
"github.com/pluralsh/plural-cli/pkg/common"
"github.com/pluralsh/plural-cli/pkg/config"
Expand Down Expand Up @@ -81,13 +82,28 @@ func (p *Plural) handleGenerateBackend(_ *cli.Context) error {
return err
}

id := ""
err := p.askStackID(&id)
stackNames := make(map[string]string)
infrastructureStacks, err := p.ConsoleClient.ListaStacks()
if err != nil {
return api.GetErrorResponse(err, "ListaStacks")
}
if infrastructureStacks == nil || infrastructureStacks.InfrastructureStacks == nil || len(infrastructureStacks.InfrastructureStacks.Edges) == 0 {
return fmt.Errorf("returned objects list [ListStacks] is nil")
}
for _, node := range infrastructureStacks.InfrastructureStacks.Edges {
stackNames[node.Node.Name] = lo.FromPtr(node.Node.ID)
}
var name string
prompt := &survey.Select{
Message: "Select a stack to generate a backend for:",
Options: lo.Keys(stackNames),
}
opts := []survey.AskOpt{survey.WithValidator(survey.Required)}
if err := survey.AskOne(prompt, &name, opts...); err != nil {
return err
}

stateUrls, err := stacks.GetTerraformStateUrls(p.ConsoleClient, id)
stateUrls, err := stacks.GetTerraformStateUrls(p.ConsoleClient, stackNames[name])
if err != nil {
return err
}
Expand All @@ -113,11 +129,3 @@ func (p *Plural) handleGenerateBackend(_ *cli.Context) error {

return git.AppendGitIgnore(dir, []string{fileName})
}

func (p *Plural) askStackID(id *string) (err error) {
return survey.AskOne(
&survey.Input{Message: "Enter the stack id:"},
id,
survey.WithValidator(survey.Required),
)
}
2 changes: 1 addition & 1 deletion hack/gen-client-mocks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cd $(dirname $0)/..

source hack/lib.sh

CONTAINERIZE_IMAGE=golang:1.23.5 containerize ./hack/gen-client-mocks.sh
CONTAINERIZE_IMAGE=golang:1.25.1 containerize ./hack/gen-client-mocks.sh

go run github.com/vektra/mockery/v2@latest --dir=pkg/api/ --name=Client --output=pkg/test/mocks
go run github.com/vektra/mockery/v2@latest --dir=pkg/kubernetes --name=Kube --output=pkg/test/mocks
Expand Down
8 changes: 6 additions & 2 deletions pkg/client/plural.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ func (p *Plural) HandleInit(c *cli.Context) error {
}

prov, err := common.RunPreflights(c)
if err != nil && !c.Bool("ignore-preflights") {
return err
if err != nil {
if !c.Bool("ignore-preflights") {
fmt.Println("Preflight checks failed. You can rerun with --ignore-preflights to skip these checks.")
return fmt.Errorf("preflight checks failed: %w", err)
}
fmt.Println("Preflight checks failed, but continuing because --ignore-preflights was specified.")
}

if !git && common.Affirm("You're attempting to setup plural outside a git repository. Would you like us to set one up for you here?", "PLURAL_INIT_AFFIRM_SETUP_REPO") {
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const (

const Gitattributes = `context.yaml filter=plural-crypt diff=plural-crypt
workspace.yaml filter=plural-crypt diff=plural-crypt
context.yaml* filter=plural-crypt diff=plural-crypt
workspace.yaml* filter=plural-crypt diff=plural-crypt
helm-values/*.yaml filter=plural-crypt diff=plural-crypt
.env filter=plural-crypt diff=plural-crypt
Expand All @@ -34,6 +33,7 @@ const Gitignore = `/**/.terraform
*.swo
.DS_STORE
.vscode
context.yaml*
`

func CryptoInit(c *cli.Context) error {
Expand Down
1 change: 1 addition & 0 deletions pkg/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type ConsoleClient interface {
CreateClusterRegistration(attributes consoleclient.ClusterRegistrationCreateAttributes) (*consoleclient.ClusterRegistrationFragment, error)
IsClusterRegistrationComplete(machineID string) (bool, *consoleclient.ClusterRegistrationFragment)
GetUser(email string) (*consoleclient.UserFragment, error)
ListaStacks() (*consoleclient.ListInfrastructureStacks, error)
}

type authedTransport struct {
Expand Down
4 changes: 4 additions & 0 deletions pkg/console/stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ import (
func (c *consoleClient) ListStackRuns(stackID string) (*gqlclient.ListStackRuns, error) {
return c.client.ListStackRuns(c.ctx, stackID, nil, nil, lo.ToPtr(int64(100)), nil)
}

func (c *consoleClient) ListaStacks() (*gqlclient.ListInfrastructureStacks, error) {
return c.client.ListInfrastructureStacks(c.ctx, nil, lo.ToPtr(int64(100)), nil, nil)
}
2 changes: 1 addition & 1 deletion pkg/test/mocks/Client.go

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

32 changes: 31 additions & 1 deletion pkg/test/mocks/ConsoleClient.go

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

2 changes: 1 addition & 1 deletion pkg/test/mocks/Kube.go

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

1 change: 1 addition & 0 deletions pkg/up/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (ctx *Context) Prune() error {

_ = os.Remove("./terraform/mgmt/console.tf")
_ = os.RemoveAll("./terraform/apps")
_ = os.Remove("./context.yaml")

return git.Sync(repoRoot, "Post-setup resource cleanup", true)
}
Expand Down
Loading