Skip to content

Commit

Permalink
Add support for external run dependencies. (#146)
Browse files Browse the repository at this point in the history
* Add support for run external dependencies.

Signed-off-by: Jakub Martin <[email protected]>

* Refactor graphql schema.

Signed-off-by: Jakub Martin <[email protected]>

* Rename command.

Signed-off-by: Jakub Martin <[email protected]>

* Fixes.

Signed-off-by: Jakub Martin <[email protected]>

* Fix lint.

Signed-off-by: Jakub Martin <[email protected]>

* Fix lint

Signed-off-by: Jakub Martin <[email protected]>

* Fix lint?

Signed-off-by: Jakub Martin <[email protected]>

---------

Signed-off-by: Jakub Martin <[email protected]>
  • Loading branch information
cube2222 authored Jun 19, 2023
1 parent 37dec06 commit 2f65b41
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29
github.com/urfave/cli/v2 v2.25.1
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561
golang.org/x/net v0.8.0
golang.org/x/oauth2 v0.6.0
golang.org/x/sync v0.1.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
Expand Down
15 changes: 15 additions & 0 deletions internal/cmd/run_external_dependency/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package runexternaldependency

import "github.com/urfave/cli/v2"

var flagRunExternalDependencyID = &cli.StringFlag{
Name: "id",
Usage: "[Required] ID of the external dependency",
Required: true,
}

var flagStatus = &cli.StringFlag{
Name: "status",
Usage: "[Required] Status of the external dependency (one of: 'finished', 'failed')",
Required: true,
}
40 changes: 40 additions & 0 deletions internal/cmd/run_external_dependency/mark_completed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package runexternaldependency

import (
"fmt"
"strings"

"github.com/urfave/cli/v2"
"golang.org/x/exp/slices"

"github.com/spacelift-io/spacectl/internal/cmd/authenticated"
)

func markRunExternalDependencyAsCompleted(cliCtx *cli.Context) error {
externalDependencyID := cliCtx.String(flagRunExternalDependencyID.Name)
status := cliCtx.String(flagStatus.Name)

var mutation struct {
RunExternalDependencyMarkAsFinished struct {
Phantom bool `graphql:"phantom"`
} `graphql:"runExternalDependencyMarkAsCompleted(dependency: $dependency, status: $status)"`
}

if !slices.Contains([]string{"finished", "failed"}, status) {
return fmt.Errorf("status must be one of: finished, failed")
}

type RunExternalDependencyStatus string
variables := map[string]interface{}{
"dependency": externalDependencyID,
"status": RunExternalDependencyStatus(strings.ToUpper(status)),
}

if err := authenticated.Client.Mutate(cliCtx.Context, &mutation, variables); err != nil {
return err
}

fmt.Printf("Marked external dependency as %s\n", status)

return nil
}
30 changes: 30 additions & 0 deletions internal/cmd/run_external_dependency/run_external_dependency.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package runexternaldependency

import (
"github.com/urfave/cli/v2"

"github.com/spacelift-io/spacectl/internal/cmd"
"github.com/spacelift-io/spacectl/internal/cmd/authenticated"
)

// Command encapsulates the run external dependency command subtree.
func Command() *cli.Command {
return &cli.Command{
Name: "run-external-dependency",
Usage: "Manage Spacelift Run external dependencies",
Subcommands: []*cli.Command{
{
Category: "Run external dependency management",
Name: "mark-completed",
Usage: "Mark Run external dependency as completed",
Flags: []cli.Flag{
flagRunExternalDependencyID,
flagStatus,
},
Action: markRunExternalDependencyAsCompleted,
Before: authenticated.Ensure,
ArgsUsage: cmd.EmptyArgsUsage,
},
},
}
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/spacelift-io/spacectl/internal/cmd/module"
"github.com/spacelift-io/spacectl/internal/cmd/profile"
"github.com/spacelift-io/spacectl/internal/cmd/provider"
"github.com/spacelift-io/spacectl/internal/cmd/run_external_dependency"
"github.com/spacelift-io/spacectl/internal/cmd/stack"
versioncmd "github.com/spacelift-io/spacectl/internal/cmd/version"
"github.com/spacelift-io/spacectl/internal/cmd/whoami"
Expand All @@ -33,6 +34,7 @@ func main() {
module.Command(),
profile.Command(),
provider.Command(),
runexternaldependency.Command(),
stack.Command(),
whoami.Command(),
versioncmd.Command(version),
Expand Down

0 comments on commit 2f65b41

Please sign in to comment.